From b710379a09b15da342a07f088f01db02a87aff15 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sat, 27 May 2017 17:34:37 +0200 Subject: [PATCH] Make pyfakefs API PEP-8 conform - changed methods names - added old method names as depracated version - added possibility to switch on deprecation warning - see #186 --- README.md | 4 +- docs/usage.rst | 4 +- dynamic_patch_test.py | 12 +- example_test.py | 22 +- fake_filesystem_glob_test.py | 10 +- fake_filesystem_shutil_test.py | 256 +-- fake_filesystem_test.py | 2150 +++++++++++++------------- fake_filesystem_unittest_test.py | 42 +- fake_filesystem_vs_real_test.py | 2 +- fake_pathlib_test.py | 212 +-- fake_tempfile_test.py | 26 +- pyfakefs/deprecator.py | 69 + pyfakefs/fake_filesystem.py | 998 ++++++------ pyfakefs/fake_filesystem_shutil.py | 2 +- pyfakefs/fake_filesystem_unittest.py | 2 +- pyfakefs/fake_pathlib.py | 44 +- pyfakefs/pytest_plugin.py | 2 +- pytest_plugin_test.py | 2 +- 18 files changed, 2035 insertions(+), 1824 deletions(-) create mode 100644 pyfakefs/deprecator.py diff --git a/README.md b/README.md index 76df2479..34605ffb 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ The PyTest plugin provides the `fs` fixture for use in your test. For example: ```python def my_fakefs_test(fs): # "fs" is the reference to the fake file system - fs.CreateFile('/var/data/xx1.txt') + fs.create_file('/var/data/xx1.txt') assert os.path.exists('/var/data/xx1.txt') ``` @@ -57,7 +57,7 @@ from fake_filesystem_unittest import Patcher with Patcher() as patcher: # access the fake_filesystem object via patcher.fs - patcher.fs.CreateFile('/foo/bar', contents='test') + patcher.fs.create_file('/foo/bar', contents='test') # the following code works on the fake filesystem with open('/foo/bar') as f: diff --git a/docs/usage.rst b/docs/usage.rst index 08c38768..2382c92b 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -24,7 +24,7 @@ The PyTest plugin provides the ``fs`` fixture for use in your test. For example: def my_fakefs_test(fs): # "fs" is the reference to the fake file system - fs.CreateFile('/var/data/xx1.txt') + fs.create_file('/var/data/xx1.txt') assert os.path.exists('/var/data/xx1.txt') Patch using fake_filesystem_unittest.Patcher @@ -83,7 +83,7 @@ The following modules and functions can be patched: fs = fake_fs.FakeFilesystem() # Do some setup on the faked file system - fs.CreateFile('/foo/bar', contents='test') + fs.create_file('/foo/bar', contents='test') # Replace some built-in file system related modules you use with faked ones diff --git a/dynamic_patch_test.py b/dynamic_patch_test.py index b3d96530..7692de28 100644 --- a/dynamic_patch_test.py +++ b/dynamic_patch_test.py @@ -39,28 +39,28 @@ def testOsPatch(self): import os os.mkdir('test') - self.assertTrue(self.fs.Exists('test')) + self.assertTrue(self.fs.exists('test')) self.assertTrue(os.path.exists('test')) def testOsImportAsPatch(self): import os as _os _os.mkdir('test') - self.assertTrue(self.fs.Exists('test')) + self.assertTrue(self.fs.exists('test')) self.assertTrue(_os.path.exists('test')) def testOsPathPatch(self): import os.path os.mkdir('test') - self.assertTrue(self.fs.Exists('test')) + self.assertTrue(self.fs.exists('test')) self.assertTrue(os.path.exists('test')) @unittest.skipIf(sys.version_info < (3, 3), 'disk_usage new in Python 3.3') def testShutilPatch(self): import shutil - self.fs.SetDiskUsage(100) + self.fs.set_disk_usage(100) self.assertEqual(100, shutil.disk_usage('/').total) @unittest.skipIf(sys.version_info < (3, 4), 'pathlib new in Python 3.4') @@ -72,8 +72,8 @@ def testPathlibPatch(self): with path.open('w') as f: f.write('test') - self.assertTrue(self.fs.Exists(file_path)) - file_object = self.fs.GetObject(file_path) + self.assertTrue(self.fs.exists(file_path)) + file_object = self.fs.get_object(file_path) self.assertEqual('test', file_object.contents) diff --git a/example_test.py b/example_test.py index e28b54d1..ccf2c5d4 100644 --- a/example_test.py +++ b/example_test.py @@ -19,11 +19,11 @@ Test the :py:class`pyfakefs.example` module to demonstrate the usage of the :py:class`pyfakefs.fake_filesystem_unittest.TestCase` base class. -Fake filesystem functions like `CreateFile()`, `CreateDirectory()` or `CreateLink()` +Fake filesystem functions like `create_file()`, `create_dir()` or `symlink()` are often used to set up file structures at the beginning of a test. While you could also use the familiar `open()`, `os.mkdirs()` and similar functions, these functions can make the test code shorter and more readable. -`CreateFile()` is particularly convenient because it creates all parent directories +`create_file()` is particularly convenient because it creates all parent directories and allows you to specify the contents or the size of the file. """ @@ -87,8 +87,8 @@ def test_create_file(self): def test_delete_file(self): """Test example.delete_file() which uses `os.remove()`.""" - self.fs.CreateFile('/test/full.txt', - contents='First line\n' + self.fs.create_file('/test/full.txt', + contents='First line\n' 'Second Line\n') self.assertTrue(os.path.exists('/test/full.txt')) example.delete_file('/test/full.txt') @@ -97,13 +97,13 @@ def test_delete_file(self): def test_file_exists(self): """Test example.path_exists() which uses `os.path.exists()`.""" self.assertFalse(example.path_exists('/test/empty.txt')) - self.fs.CreateFile('/test/empty.txt') + self.fs.create_file('/test/empty.txt') self.assertTrue(example.path_exists('/test/empty.txt')) def test_get_globs(self): """Test example.get_glob().""" self.assertFalse(os.path.isdir('/test')) - self.fs.CreateDirectory('/test/dir1/dir2a') + self.fs.create_dir('/test/dir1/dir2a') self.assertTrue(os.path.isdir('/test/dir1/dir2a')) # os.mkdirs() works, too. os.makedirs('/test/dir1/dir2b') @@ -120,7 +120,7 @@ def test_get_globs(self): def test_rm_tree(self): """Test example.rm_tree() using `shutil.rmtree()`.""" - self.fs.CreateDirectory('/test/dir1/dir2a') + self.fs.create_dir('/test/dir1/dir2a') # os.mkdirs() works, too. os.makedirs('/test/dir1/dir2b') self.assertTrue(os.path.isdir('/test/dir1/dir2b')) @@ -136,10 +136,10 @@ def test_scandir(self): The os module has been replaced with the fake os module so the fake filesystem path entries are returned instead of `os.DirEntry` objects. """ - self.fs.CreateFile('/test/text.txt') - self.fs.CreateDirectory('/test/dir') - self.fs.CreateFile('/linktest/linked') - self.fs.CreateLink('/test/linked_file', '/linktest/linked') + self.fs.create_file('/test/text.txt') + self.fs.create_dir('/test/dir') + self.fs.create_file('/linktest/linked') + self.fs.symlink('/test/linked_file', '/linktest/linked') entries = sorted(example.scandir('/test'), key=lambda e: e.name) self.assertEqual(3, len(entries)) diff --git a/fake_filesystem_glob_test.py b/fake_filesystem_glob_test.py index adfa79cf..172e2b70 100755 --- a/fake_filesystem_glob_test.py +++ b/fake_filesystem_glob_test.py @@ -33,11 +33,11 @@ class FakeGlobUnitTest(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() directory = './xyzzy' - self.fs.CreateDirectory(directory) - self.fs.CreateDirectory('%s/subdir' % directory) - self.fs.CreateDirectory('%s/subdir2' % directory) - self.fs.CreateFile('%s/subfile' % directory) - self.fs.CreateFile('[Temp]') + self.fs.create_dir(directory) + self.fs.create_dir('%s/subdir' % directory) + self.fs.create_dir('%s/subdir2' % directory) + self.fs.create_file('%s/subfile' % directory) + self.fs.create_file('[Temp]') def testGlobEmpty(self): self.assertEqual(glob.glob(''), []) diff --git a/fake_filesystem_shutil_test.py b/fake_filesystem_shutil_test.py index 896eea7a..9a0988a7 100755 --- a/fake_filesystem_shutil_test.py +++ b/fake_filesystem_shutil_test.py @@ -36,52 +36,52 @@ class FakeShutilModuleTest(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() - self.fs.SetDiskUsage(1000) + self.fs.set_disk_usage(1000) def testRmtree(self): directory = 'xyzzy' - self.fs.CreateDirectory(directory) - self.fs.CreateDirectory('%s/subdir' % directory) - self.fs.CreateFile('%s/subfile' % directory) - self.assertTrue(self.fs.Exists(directory)) + self.fs.create_dir(directory) + self.fs.create_dir('%s/subdir' % directory) + self.fs.create_file('%s/subfile' % directory) + self.assertTrue(self.fs.exists(directory)) shutil.rmtree(directory) - self.assertFalse(self.fs.Exists(directory)) - self.assertFalse(self.fs.Exists('%s/subdir' % directory)) - self.assertFalse(self.fs.Exists('%s/subfile' % directory)) + self.assertFalse(self.fs.exists(directory)) + self.assertFalse(self.fs.exists('%s/subdir' % directory)) + self.assertFalse(self.fs.exists('%s/subfile' % directory)) def testRmtreeWithTrailingSlash(self): directory = 'xyzzy' - self.fs.CreateDirectory(directory) - self.fs.CreateDirectory('%s/subdir' % directory) - self.fs.CreateFile('%s/subfile' % directory) + self.fs.create_dir(directory) + self.fs.create_dir('%s/subdir' % directory) + self.fs.create_file('%s/subfile' % directory) shutil.rmtree(directory + '/') - self.assertFalse(self.fs.Exists(directory)) - self.assertFalse(self.fs.Exists('%s/subdir' % directory)) - self.assertFalse(self.fs.Exists('%s/subfile' % directory)) + self.assertFalse(self.fs.exists(directory)) + self.assertFalse(self.fs.exists('%s/subdir' % directory)) + self.assertFalse(self.fs.exists('%s/subfile' % directory)) def testRmtreeWithoutPermissionForAFile(self): - self.fs.CreateFile('/foo/bar') - self.fs.CreateFile('/foo/baz', st_mode=stat.S_IFREG | 0o444) + self.fs.create_file('/foo/bar') + self.fs.create_file('/foo/baz', st_mode=stat.S_IFREG | 0o444) self.assertRaises(OSError, shutil.rmtree, '/foo') - self.assertTrue(self.fs.Exists('/foo/baz')) + self.assertTrue(self.fs.exists('/foo/baz')) def testRmtreeWithOpenFilePosix(self): self.fs.is_windows_fs = False fake_open = fake_filesystem.FakeFileOpen(self.fs) - self.fs.CreateFile('/foo/bar') - self.fs.CreateFile('/foo/baz') + self.fs.create_file('/foo/bar') + self.fs.create_file('/foo/baz') fake_open('/foo/baz', 'r') shutil.rmtree('/foo') - self.assertFalse(self.fs.Exists('/foo/baz')) + self.assertFalse(self.fs.exists('/foo/baz')) def testRmtreeWithOpenFileFailsUnderWindows(self): self.fs.is_windows_fs = True fake_open = fake_filesystem.FakeFileOpen(self.fs) - self.fs.CreateFile('/foo/bar') - self.fs.CreateFile('/foo/baz') + self.fs.create_file('/foo/bar') + self.fs.create_file('/foo/baz') fake_open('/foo/baz', 'r') self.assertRaises(OSError, shutil.rmtree, '/foo') - self.assertTrue(self.fs.Exists('/foo/baz')) + self.assertTrue(self.fs.exists('/foo/baz')) def testRmtreeNonExistingDir(self): directory = 'nonexisting' @@ -122,40 +122,40 @@ def error_handler(_, path, error_info): def testCopy(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' - src_obj = self.fs.CreateFile(src_file) + src_obj = self.fs.create_file(src_file) src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750) - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_file)) shutil.copy(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) - dst_obj = self.fs.GetObject(dst_file) + self.assertTrue(self.fs.exists(dst_file)) + dst_obj = self.fs.get_object(dst_file) self.assertEqual(src_obj.st_mode, dst_obj.st_mode) def testCopyDirectory(self): src_file = 'xyzzy' parent_directory = 'parent' dst_file = '%s/%s' % (parent_directory, src_file) - src_obj = self.fs.CreateFile(src_file) - self.fs.CreateDirectory(parent_directory) + src_obj = self.fs.create_file(src_file) + self.fs.create_dir(parent_directory) src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750) - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(parent_directory)) - self.assertFalse(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(parent_directory)) + self.assertFalse(self.fs.exists(dst_file)) shutil.copy(src_file, parent_directory) - self.assertTrue(self.fs.Exists(dst_file)) - dst_obj = self.fs.GetObject(dst_file) + self.assertTrue(self.fs.exists(dst_file)) + dst_obj = self.fs.get_object(dst_file) self.assertEqual(src_obj.st_mode, dst_obj.st_mode) def testCopystat(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' - src_obj = self.fs.CreateFile(src_file) - dst_obj = self.fs.CreateFile(dst_file) + src_obj = self.fs.create_file(src_file) + dst_obj = self.fs.create_file(dst_file) src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750) src_obj.st_atime = time.time() src_obj.st_mtime = time.time() - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) shutil.copystat(src_file, dst_file) self.assertEqual(src_obj.st_mode, dst_obj.st_mode) self.assertEqual(src_obj.st_atime, dst_obj.st_atime) @@ -164,15 +164,15 @@ def testCopystat(self): def testCopy2(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' - src_obj = self.fs.CreateFile(src_file) + src_obj = self.fs.create_file(src_file) src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750) src_obj.st_atime = time.time() src_obj.st_mtime = time.time() - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_file)) shutil.copy2(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) - dst_obj = self.fs.GetObject(dst_file) + self.assertTrue(self.fs.exists(dst_file)) + dst_obj = self.fs.get_object(dst_file) self.assertEqual(src_obj.st_mode, dst_obj.st_mode) self.assertEqual(src_obj.st_atime, dst_obj.st_atime) self.assertEqual(src_obj.st_mtime, dst_obj.st_mtime) @@ -181,17 +181,17 @@ def testCopy2Directory(self): src_file = 'xyzzy' parent_directory = 'parent' dst_file = '%s/%s' % (parent_directory, src_file) - src_obj = self.fs.CreateFile(src_file) - self.fs.CreateDirectory(parent_directory) + src_obj = self.fs.create_file(src_file) + self.fs.create_dir(parent_directory) src_obj.st_mode = ((src_obj.st_mode & ~0o7777) | 0o750) src_obj.st_atime = time.time() src_obj.st_mtime = time.time() - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(parent_directory)) - self.assertFalse(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(parent_directory)) + self.assertFalse(self.fs.exists(dst_file)) shutil.copy2(src_file, parent_directory) - self.assertTrue(self.fs.Exists(dst_file)) - dst_obj = self.fs.GetObject(dst_file) + self.assertTrue(self.fs.exists(dst_file)) + dst_obj = self.fs.get_object(dst_file) self.assertEqual(src_obj.st_mode, dst_obj.st_mode) self.assertEqual(src_obj.st_atime, dst_obj.st_atime) self.assertEqual(src_obj.st_mtime, dst_obj.st_mtime) @@ -199,22 +199,22 @@ def testCopy2Directory(self): def testCopytree(self): src_directory = 'xyzzy' dst_directory = 'xyzzy_copy' - self.fs.CreateDirectory(src_directory) - self.fs.CreateDirectory('%s/subdir' % src_directory) - self.fs.CreateFile('%s/subfile' % src_directory) - self.assertTrue(self.fs.Exists(src_directory)) - self.assertFalse(self.fs.Exists(dst_directory)) + self.fs.create_dir(src_directory) + self.fs.create_dir('%s/subdir' % src_directory) + self.fs.create_file('%s/subfile' % src_directory) + self.assertTrue(self.fs.exists(src_directory)) + self.assertFalse(self.fs.exists(dst_directory)) shutil.copytree(src_directory, dst_directory) - self.assertTrue(self.fs.Exists(dst_directory)) - self.assertTrue(self.fs.Exists('%s/subdir' % dst_directory)) - self.assertTrue(self.fs.Exists('%s/subfile' % dst_directory)) + self.assertTrue(self.fs.exists(dst_directory)) + self.assertTrue(self.fs.exists('%s/subdir' % dst_directory)) + self.assertTrue(self.fs.exists('%s/subfile' % dst_directory)) def testCopytreeSrcIsFile(self): src_file = 'xyzzy' dst_directory = 'xyzzy_copy' - self.fs.CreateFile(src_file) - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_directory)) + self.fs.create_file(src_file) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_directory)) self.assertRaises(OSError, shutil.copytree, src_file, @@ -223,33 +223,33 @@ def testCopytreeSrcIsFile(self): def testMoveFileInSameFilesystem(self): src_file = '/original_xyzzy' dst_file = '/moved_xyzzy' - src_object = self.fs.CreateFile(src_file) + src_object = self.fs.create_file(src_file) src_ino = src_object.st_ino src_dev = src_object.st_dev - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_file)) shutil.move(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) - self.assertFalse(self.fs.Exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) + self.assertFalse(self.fs.exists(src_file)) - dst_object = self.fs.GetObject(dst_file) + dst_object = self.fs.get_object(dst_file) self.assertEqual(src_ino, dst_object.st_ino) self.assertEqual(src_dev, dst_object.st_dev) def testMoveFileIntoOtherFilesystem(self): - self.fs.AddMountPoint('/mount') + self.fs.add_mount_point('/mount') src_file = '/original_xyzzy' dst_file = '/mount/moved_xyzzy' - src_object = self.fs.CreateFile(src_file) + src_object = self.fs.create_file(src_file) src_ino = src_object.st_ino src_dev = src_object.st_dev shutil.move(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) - self.assertFalse(self.fs.Exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) + self.assertFalse(self.fs.exists(src_file)) - dst_object = self.fs.GetObject(dst_file) + dst_object = self.fs.get_object(dst_file) self.assertNotEqual(src_ino, dst_object.st_ino) self.assertNotEqual(src_dev, dst_object.st_dev) @@ -257,39 +257,39 @@ def testMoveFileIntoDirectory(self): src_file = 'xyzzy' dst_directory = 'directory' dst_file = '%s/%s' % (dst_directory, src_file) - self.fs.CreateFile(src_file) - self.fs.CreateDirectory(dst_directory) - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_file)) + self.fs.create_file(src_file) + self.fs.create_dir(dst_directory) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_file)) shutil.move(src_file, dst_directory) - self.assertTrue(self.fs.Exists(dst_file)) - self.assertFalse(self.fs.Exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) + self.assertFalse(self.fs.exists(src_file)) def testMoveDirectory(self): src_directory = 'original_xyzzy' dst_directory = 'moved_xyzzy' - self.fs.CreateDirectory(src_directory) - self.fs.CreateFile('%s/subfile' % src_directory) - self.fs.CreateDirectory('%s/subdir' % src_directory) - self.assertTrue(self.fs.Exists(src_directory)) - self.assertFalse(self.fs.Exists(dst_directory)) + self.fs.create_dir(src_directory) + self.fs.create_file('%s/subfile' % src_directory) + self.fs.create_dir('%s/subdir' % src_directory) + self.assertTrue(self.fs.exists(src_directory)) + self.assertFalse(self.fs.exists(dst_directory)) shutil.move(src_directory, dst_directory) - self.assertTrue(self.fs.Exists(dst_directory)) - self.assertTrue(self.fs.Exists('%s/subfile' % dst_directory)) - self.assertTrue(self.fs.Exists('%s/subdir' % dst_directory)) - self.assertFalse(self.fs.Exists(src_directory)) + self.assertTrue(self.fs.exists(dst_directory)) + self.assertTrue(self.fs.exists('%s/subfile' % dst_directory)) + self.assertTrue(self.fs.exists('%s/subdir' % dst_directory)) + self.assertFalse(self.fs.exists(src_directory)) @unittest.skipIf(sys.version_info < (3, 3), 'New in Python 3.3') def testDiskUsage(self): - self.fs.CreateFile('/foo/bar', st_size=400) + self.fs.create_file('/foo/bar', st_size=400) disk_usage = shutil.disk_usage('/') self.assertEqual(1000, disk_usage.total) self.assertEqual(400, disk_usage.used) self.assertEqual(600, disk_usage.free) self.assertEqual((1000, 400, 600), disk_usage) - self.fs.AddMountPoint('/mount', total_size=500) - self.fs.CreateFile('/mount/foo/bar', st_size=400) + self.fs.add_mount_point('/mount', total_size=500) + self.fs.create_file('/mount/foo/bar', st_size=400) disk_usage = shutil.disk_usage('/mount/foo/') self.assertEqual((500, 400, 100), disk_usage) @@ -302,19 +302,19 @@ def testCommonCase(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' contents = 'contents of file' - self.fs.CreateFile(src_file, contents=contents) - self.assertTrue(self.fs.Exists(src_file)) - self.assertFalse(self.fs.Exists(dst_file)) + self.fs.create_file(src_file, contents=contents) + self.assertTrue(self.fs.exists(src_file)) + self.assertFalse(self.fs.exists(dst_file)) shutil.copyfile(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) - self.assertEqual(contents, self.fs.GetObject(dst_file).contents) + self.assertTrue(self.fs.exists(dst_file)) + self.assertEqual(contents, self.fs.get_object(dst_file).contents) def testRaisesIfSourceAndDestAreTheSameFile(self): src_file = 'xyzzy' dst_file = src_file contents = 'contents of file' - self.fs.CreateFile(src_file, contents=contents) - self.assertTrue(self.fs.Exists(src_file)) + self.fs.create_file(src_file, contents=contents) + self.assertTrue(self.fs.exists(src_file)) self.assertRaises(shutil.Error, shutil.copyfile, src_file, dst_file) @@ -324,9 +324,9 @@ def testRaisesIfDestIsASymlinkToSrc(self): src_file = '/tmp/foo' dst_file = '/tmp/bar' contents = 'contents of file' - self.fs.CreateFile(src_file, contents=contents) - self.fs.CreateLink(dst_file, src_file) - self.assertTrue(self.fs.Exists(src_file)) + self.fs.create_file(src_file, contents=contents) + self.fs.symlink(dst_file, src_file) + self.assertTrue(self.fs.exists(src_file)) self.assertRaises(shutil.Error, shutil.copyfile, src_file, dst_file) @@ -335,26 +335,26 @@ def testSucceedsIfDestExistsAndIsWritable(self): dst_file = 'xyzzy_copy' src_contents = 'contents of source file' dst_contents = 'contents of dest file' - self.fs.CreateFile(src_file, contents=src_contents) - self.fs.CreateFile(dst_file, contents=dst_contents) - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(dst_file)) + self.fs.create_file(src_file, contents=src_contents) + self.fs.create_file(dst_file, contents=dst_contents) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) shutil.copyfile(src_file, dst_file) - self.assertTrue(self.fs.Exists(dst_file)) + self.assertTrue(self.fs.exists(dst_file)) self.assertEqual(src_contents, - self.fs.GetObject(dst_file).contents) + self.fs.get_object(dst_file).contents) def testRaisesIfDestExistsAndIsNotWritable(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' src_contents = 'contents of source file' dst_contents = 'contents of dest file' - self.fs.CreateFile(src_file, contents=src_contents) - self.fs.CreateFile(dst_file, - st_mode=stat.S_IFREG | 0o400, - contents=dst_contents) - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(dst_file)) + self.fs.create_file(src_file, contents=src_contents) + self.fs.create_file(dst_file, + st_mode=stat.S_IFREG | 0o400, + contents=dst_contents) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(dst_file)) self.assertRaises(IOError, shutil.copyfile, src_file, dst_file) def testRaisesIfDestDirIsNotWritableUnderPosix(self): @@ -363,33 +363,33 @@ def testRaisesIfDestDirIsNotWritableUnderPosix(self): dst_dir = '/tmp/foo' dst_file = '%s/%s' % (dst_dir, src_file) src_contents = 'contents of source file' - self.fs.CreateFile(src_file, contents=src_contents) - self.fs.CreateDirectory(dst_dir, perm_bits=0o555) - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(dst_dir)) + self.fs.create_file(src_file, contents=src_contents) + self.fs.create_dir(dst_dir, perm_bits=0o555) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(dst_dir)) self.assertRaises(OSError, shutil.copyfile, src_file, dst_file) def testRaisesIfSrcDoesntExist(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' - self.assertFalse(self.fs.Exists(src_file)) + self.assertFalse(self.fs.exists(src_file)) self.assertRaises(IOError, shutil.copyfile, src_file, dst_file) def testRaisesIfSrcNotReadable(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' src_contents = 'contents of source file' - self.fs.CreateFile(src_file, - st_mode=stat.S_IFREG | 0o000, - contents=src_contents) - self.assertTrue(self.fs.Exists(src_file)) + self.fs.create_file(src_file, + st_mode=stat.S_IFREG | 0o000, + contents=src_contents) + self.assertTrue(self.fs.exists(src_file)) self.assertRaises(IOError, shutil.copyfile, src_file, dst_file) def testRaisesIfSrcIsADirectory(self): src_file = 'xyzzy' dst_file = 'xyzzy_copy' - self.fs.CreateDirectory(src_file) - self.assertTrue(self.fs.Exists(src_file)) + self.fs.create_dir(src_file) + self.assertTrue(self.fs.exists(src_file)) if self.fs.is_windows_fs: self.assertRaises(OSError, shutil.copyfile, src_file, dst_file) else: @@ -399,10 +399,10 @@ def testRaisesIfDestIsADirectory(self): src_file = 'xyzzy' dst_dir = '/tmp/foo' src_contents = 'contents of source file' - self.fs.CreateFile(src_file, contents=src_contents) - self.fs.CreateDirectory(dst_dir) - self.assertTrue(self.fs.Exists(src_file)) - self.assertTrue(self.fs.Exists(dst_dir)) + self.fs.create_file(src_file, contents=src_contents) + self.fs.create_dir(dst_dir) + self.assertTrue(self.fs.exists(src_file)) + self.assertTrue(self.fs.exists(dst_dir)) if self.fs.is_windows_fs: self.assertRaises(OSError, shutil.copyfile, src_file, dst_dir) else: diff --git a/fake_filesystem_test.py b/fake_filesystem_test.py index a5844bd8..4179e20f 100755 --- a/fake_filesystem_test.py +++ b/fake_filesystem_test.py @@ -96,93 +96,99 @@ def testNewFileAndDirectory(self): self.assertEqual(10, self.fake_file.st_ctime) def testAddEntry(self): - self.fake_dir.AddEntry(self.fake_file) + self.fake_dir.add_entry(self.fake_file) self.assertEqual({'foobar': self.fake_file}, self.fake_dir.contents) def testGetEntry(self): - self.fake_dir.AddEntry(self.fake_file) - self.assertEqual(self.fake_file, self.fake_dir.GetEntry('foobar')) + self.fake_dir.add_entry(self.fake_file) + self.assertEqual(self.fake_file, self.fake_dir.get_entry('foobar')) def testGetPath(self): - self.filesystem.root.AddEntry(self.fake_dir) - self.fake_dir.AddEntry(self.fake_file) + self.filesystem.root.add_entry(self.fake_dir) + self.fake_dir.add_entry(self.fake_file) self.assertEqual('/somedir/foobar', self.fake_file.GetPath()) def testRemoveEntry(self): - self.fake_dir.AddEntry(self.fake_file) - self.assertEqual(self.fake_file, self.fake_dir.GetEntry('foobar')) - self.fake_dir.RemoveEntry('foobar') - self.assertRaises(KeyError, self.fake_dir.GetEntry, 'foobar') + self.fake_dir.add_entry(self.fake_file) + self.assertEqual(self.fake_file, self.fake_dir.get_entry('foobar')) + self.fake_dir.remove_entry('foobar') + self.assertRaises(KeyError, self.fake_dir.get_entry, 'foobar') def testShouldThrowIfSetSizeIsNotInteger(self): - self.assertRaisesIOError(errno.ENOSPC, self.fake_file.SetSize, 0.1) + def set_size(): + self.fake_file.size = 0.1 + + self.assertRaisesIOError(errno.ENOSPC, set_size) def testShouldThrowIfSetSizeIsNegative(self): - self.assertRaisesIOError(errno.ENOSPC, self.fake_file.SetSize, -1) + def set_size(): + self.fake_file.size = -1 + + self.assertRaisesIOError(errno.ENOSPC, set_size) def testProduceEmptyFileIfSetSizeIsZero(self): - self.fake_file.SetSize(0) + self.fake_file.size = 0 self.assertEqual('', self.fake_file.contents) def testSetsContentEmptyIfSetSizeIsZero(self): - self.fake_file.SetSize(0) + self.fake_file.size = 0 self.assertEqual('', self.fake_file.contents) def testTruncateFileIfSizeIsSmallerThanCurrentSize(self): - self.fake_file.SetSize(6) + self.fake_file.size = 6 self.assertEqual('dummy_', self.fake_file.contents) def testLeaveFileUnchangedIfSizeIsEqualToCurrentSize(self): - self.fake_file.SetSize(10) + self.fake_file.size = 10 self.assertEqual('dummy_file', self.fake_file.contents) def testSetContentsToDirRaises(self): self.filesystem.is_windows_fs = True - self.assertRaisesOSError(errno.EISDIR, self.fake_dir.SetContents, 'a') + self.assertRaisesOSError(errno.EISDIR, self.fake_dir.set_contents, 'a') self.filesystem.is_windows_fs = False - self.assertRaisesIOError(errno.EISDIR, self.fake_dir.SetContents, 'a') + self.assertRaisesIOError(errno.EISDIR, self.fake_dir.set_contents, 'a') def testPadsFileContentWithNullBytesIfSizeIsGreaterThanCurrentSize(self): - self.fake_file.SetSize(13) + self.fake_file.size = 13 self.assertEqual('dummy_file\0\0\0', self.fake_file.contents) def testSetMTime(self): self.assertEqual(10, self.fake_file.st_mtime) - self.fake_file.SetMTime(13) + self.fake_file.st_mtime = 13 self.assertEqual(13, self.fake_file.st_mtime) - self.fake_file.SetMTime(131) + self.fake_file.st_mtime = 131 self.assertEqual(131, self.fake_file.st_mtime) def testFileInode(self): filesystem = fake_filesystem.FakeFilesystem(path_separator='/') fake_os = fake_filesystem.FakeOsModule(filesystem) file_path = 'some_file1' - filesystem.CreateFile(file_path, contents='contents here1') + filesystem.create_file(file_path, contents='contents here1') self.assertLess(0, fake_os.stat(file_path)[stat.ST_INO]) - file_obj = filesystem.GetObject(file_path) - file_obj.SetIno(43) + file_obj = filesystem.get_object(file_path) + file_obj.st_ino = 43 self.assertEqual(43, fake_os.stat(file_path)[stat.ST_INO]) def testDirectoryInode(self): filesystem = fake_filesystem.FakeFilesystem(path_separator='/') fake_os = fake_filesystem.FakeOsModule(filesystem) dirpath = 'testdir' - filesystem.CreateDirectory(dirpath) + filesystem.create_dir(dirpath) self.assertLess(0, fake_os.stat(dirpath)[stat.ST_INO]) - dir_obj = filesystem.GetObject(dirpath) - dir_obj.SetIno(43) + dir_obj = filesystem.get_object(dirpath) + dir_obj.st_ino = 43 self.assertEqual(43, fake_os.stat(dirpath)[stat.ST_INO]) def testOrderedDirs(self): filesystem = fake_filesystem.FakeFilesystem(path_separator='/') - filesystem.CreateDirectory('/foo') - filesystem.CreateFile('/foo/2') - filesystem.CreateFile('/foo/4') - filesystem.CreateFile('/foo/1') - filesystem.CreateFile('/foo/3') - fake_dir = filesystem.GetObject('/foo') + filesystem.create_dir('/foo') + filesystem.create_file('/foo/2') + filesystem.create_file('/foo/4') + filesystem.create_file('/foo/1') + filesystem.create_file('/foo/3') + fake_dir = filesystem.get_object('/foo') self.assertEqual(['2', '4', '1', '3'], fake_dir.ordered_dirs) @@ -193,15 +199,15 @@ def setUp(self): filesystem=filesystem) def testShouldThrowIfSizeIsNotInteger(self): - self.assertRaisesIOError(errno.ENOSPC, self.fake_file.SetLargeFileSize, - 0.1) + self.assertRaisesIOError(errno.ENOSPC, + self.fake_file.set_large_file_size, 0.1) def testShouldThrowIfSizeIsNegative(self): - self.assertRaisesIOError(errno.ENOSPC, self.fake_file.SetLargeFileSize, - -1) + self.assertRaisesIOError(errno.ENOSPC, + self.fake_file.set_large_file_size, -1) def testSetsContentNoneIfSizeIsNonNegativeInteger(self): - self.fake_file.SetLargeFileSize(1000000000) + self.fake_file.set_large_file_size(1000000000) self.assertEqual(None, self.fake_file.contents) self.assertEqual(1000000000, self.fake_file.st_size) @@ -212,30 +218,30 @@ def setUp(self): self.root_name = '/' def testEmptyPathShouldGetNormalizedToRootPath(self): - self.assertEqual(self.root_name, self.filesystem.NormalizePath('')) + self.assertEqual(self.root_name, self.filesystem.absnormpath('')) def testRootPathRemainsUnchanged(self): self.assertEqual(self.root_name, - self.filesystem.NormalizePath(self.root_name)) + self.filesystem.absnormpath(self.root_name)) def testRelativePathForcedToCwd(self): path = 'bar' self.filesystem.cwd = '/foo' - self.assertEqual('/foo/bar', self.filesystem.NormalizePath(path)) + self.assertEqual('/foo/bar', self.filesystem.absnormpath(path)) def testAbsolutePathRemainsUnchanged(self): path = '/foo/bar' - self.assertEqual(path, self.filesystem.NormalizePath(path)) + self.assertEqual(path, self.filesystem.absnormpath(path)) def testDottedPathIsNormalized(self): path = '/foo/..' - self.assertEqual('/', self.filesystem.NormalizePath(path)) + self.assertEqual('/', self.filesystem.absnormpath(path)) path = 'foo/../bar' - self.assertEqual('/bar', self.filesystem.NormalizePath(path)) + self.assertEqual('/bar', self.filesystem.absnormpath(path)) def testDotPathIsNormalized(self): path = '.' - self.assertEqual('/', self.filesystem.NormalizePath(path)) + self.assertEqual('/', self.filesystem.absnormpath(path)) class GetPathComponentsTest(TestCase): @@ -244,24 +250,24 @@ def setUp(self): self.root_name = '/' def testRootPathShouldReturnEmptyList(self): - self.assertEqual([], self.filesystem.GetPathComponents(self.root_name)) + self.assertEqual([], self.filesystem._path_components(self.root_name)) def testEmptyPathShouldReturnEmptyList(self): - self.assertEqual([], self.filesystem.GetPathComponents('')) + self.assertEqual([], self.filesystem._path_components('')) def testRelativePathWithOneComponentShouldReturnComponent(self): - self.assertEqual(['foo'], self.filesystem.GetPathComponents('foo')) + self.assertEqual(['foo'], self.filesystem._path_components('foo')) def testAbsolutePathWithOneComponentShouldReturnComponent(self): - self.assertEqual(['foo'], self.filesystem.GetPathComponents('/foo')) + self.assertEqual(['foo'], self.filesystem._path_components('/foo')) def testTwoLevelRelativePathShouldReturnComponents(self): self.assertEqual(['foo', 'bar'], - self.filesystem.GetPathComponents('foo/bar')) + self.filesystem._path_components('foo/bar')) def testTwoLevelAbsolutePathShouldReturnComponents(self): self.assertEqual(['foo', 'bar'], - self.filesystem.GetPathComponents('/foo/bar')) + self.filesystem._path_components('/foo/bar')) class FakeFilesystemUnitTest(TestCase): @@ -282,273 +288,273 @@ def testNewFilesystem(self): self.assertEqual({}, self.filesystem.root.contents) def testNoneRaisesTypeError(self): - self.assertRaises(TypeError, self.filesystem.Exists, None) + self.assertRaises(TypeError, self.filesystem.exists, None) def testEmptyStringDoesNotExist(self): - self.assertFalse(self.filesystem.Exists('')) + self.assertFalse(self.filesystem.exists('')) def testExistsRoot(self): - self.assertTrue(self.filesystem.Exists(self.root_name)) + self.assertTrue(self.filesystem.exists(self.root_name)) def testExistsUnaddedFile(self): - self.assertFalse(self.filesystem.Exists(self.fake_file.name)) + self.assertFalse(self.filesystem.exists(self.fake_file.name)) def testNotExistsSubpathNamedLikeFileContents(self): # regression test for #219 file_path = "/foo/bar" - self.filesystem.CreateFile(file_path, contents='baz') - self.assertFalse(self.filesystem.Exists(file_path + "/baz")) + self.filesystem.create_file(file_path, contents='baz') + self.assertFalse(self.filesystem.exists(file_path + "/baz")) def testGetRootObject(self): self.assertEqual(self.filesystem.root, - self.filesystem.GetObject(self.root_name)) + self.filesystem.get_object(self.root_name)) def testAddObjectToRoot(self): - self.filesystem.AddObject(self.root_name, self.fake_file) + self.filesystem.add_object(self.root_name, self.fake_file) self.assertEqual({'foobar': self.fake_file}, self.filesystem.root.contents) def testExistsAddedFile(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.assertTrue(self.filesystem.Exists(self.fake_file.name)) + self.filesystem.add_object(self.root_name, self.fake_file) + self.assertTrue(self.filesystem.exists(self.fake_file.name)) def testExistsRelativePath(self): - self.filesystem.CreateFile('/a/b/file_one') - self.filesystem.CreateFile('/a/c/file_two') - self.assertTrue(self.filesystem.Exists('a/b/../c/file_two')) - self.assertTrue(self.filesystem.Exists('/a/c/../b/file_one')) - self.assertTrue(self.filesystem.Exists('/a/c/../../a/b/file_one')) - self.assertFalse(self.filesystem.Exists('a/b/../z/d')) - self.assertFalse(self.filesystem.Exists('a/b/../z/../c/file_two')) + self.filesystem.create_file('/a/b/file_one') + self.filesystem.create_file('/a/c/file_two') + self.assertTrue(self.filesystem.exists('a/b/../c/file_two')) + self.assertTrue(self.filesystem.exists('/a/c/../b/file_one')) + self.assertTrue(self.filesystem.exists('/a/c/../../a/b/file_one')) + self.assertFalse(self.filesystem.exists('a/b/../z/d')) + self.assertFalse(self.filesystem.exists('a/b/../z/../c/file_two')) self.filesystem.cwd = '/a/c' - self.assertTrue(self.filesystem.Exists('../b/file_one')) - self.assertTrue(self.filesystem.Exists('../../a/b/file_one')) - self.assertTrue(self.filesystem.Exists('../../a/b/../../a/c/file_two')) - self.assertFalse(self.filesystem.Exists('../z/file_one')) - self.assertFalse(self.filesystem.Exists('../z/../c/file_two')) + self.assertTrue(self.filesystem.exists('../b/file_one')) + self.assertTrue(self.filesystem.exists('../../a/b/file_one')) + self.assertTrue(self.filesystem.exists('../../a/b/../../a/c/file_two')) + self.assertFalse(self.filesystem.exists('../z/file_one')) + self.assertFalse(self.filesystem.exists('../z/../c/file_two')) def testGetObjectFromRoot(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.assertEqual(self.fake_file, self.filesystem.GetObject('foobar')) + self.filesystem.add_object(self.root_name, self.fake_file) + self.assertEqual(self.fake_file, self.filesystem.get_object('foobar')) def testGetNonexistentObjectFromRootError(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.assertEqual(self.fake_file, self.filesystem.GetObject('foobar')) - self.assertRaisesIOError(errno.ENOENT, self.filesystem.GetObject, - 'some_bogus_filename') + self.filesystem.add_object(self.root_name, self.fake_file) + self.assertEqual(self.fake_file, self.filesystem.get_object('foobar')) + self.assertRaisesIOError( + errno.ENOENT, self.filesystem.get_object, 'some_bogus_filename') def testRemoveObjectFromRoot(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.filesystem.RemoveObject(self.fake_file.name) - self.assertRaisesIOError(errno.ENOENT, self.filesystem.GetObject, - self.fake_file.name) + self.filesystem.add_object(self.root_name, self.fake_file) + self.filesystem.remove_object(self.fake_file.name) + self.assertRaisesIOError( + errno.ENOENT, self.filesystem.get_object, self.fake_file.name) def testRemoveNonexistenObjectFromRootError(self): - self.assertRaisesIOError(errno.ENOENT, self.filesystem.RemoveObject, - 'some_bogus_filename') + self.assertRaisesIOError( + errno.ENOENT, self.filesystem.remove_object, 'some_bogus_filename') def testExistsRemovedFile(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.filesystem.RemoveObject(self.fake_file.name) - self.assertFalse(self.filesystem.Exists(self.fake_file.name)) + self.filesystem.add_object(self.root_name, self.fake_file) + self.filesystem.remove_object(self.fake_file.name) + self.assertFalse(self.filesystem.exists(self.fake_file.name)) def testAddObjectToChild(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) self.assertEqual( {self.fake_file.name: self.fake_file}, - self.filesystem.root.GetEntry(self.fake_child.name).contents) + self.filesystem.root.get_entry(self.fake_child.name).contents) def testAddObjectToRegularFileError(self): - self.filesystem.AddObject(self.root_name, self.fake_file) + self.filesystem.add_object(self.root_name, self.fake_file) self.assertRaisesOSError(errno.ENOTDIR, - self.filesystem.AddObject, + self.filesystem.add_object, self.fake_file.name, self.fake_file) def testExistsFileAddedToChild(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) - path = self.filesystem.JoinPaths(self.fake_child.name, + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) + path = self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name) - self.assertTrue(self.filesystem.Exists(path)) + self.assertTrue(self.filesystem.exists(path)) def testGetObjectFromChild(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) self.assertEqual(self.fake_file, - self.filesystem.GetObject( - self.filesystem.JoinPaths(self.fake_child.name, + self.filesystem.get_object( + self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name))) def testGetNonexistentObjectFromChildError(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) - self.assertRaisesIOError(errno.ENOENT, self.filesystem.GetObject, - self.filesystem.JoinPaths( + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) + self.assertRaisesIOError(errno.ENOENT, self.filesystem.get_object, + self.filesystem.joinpaths( self.fake_child.name, 'some_bogus_filename')) def testRemoveObjectFromChild(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) - target_path = self.filesystem.JoinPaths(self.fake_child.name, + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) + target_path = self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name) - self.filesystem.RemoveObject(target_path) - self.assertRaisesIOError(errno.ENOENT, self.filesystem.GetObject, + self.filesystem.remove_object(target_path) + self.assertRaisesIOError(errno.ENOENT, self.filesystem.get_object, target_path) def testRemoveObjectFromChildError(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.assertRaisesIOError(errno.ENOENT, self.filesystem.RemoveObject, - self.filesystem.JoinPaths( + self.filesystem.add_object(self.root_name, self.fake_child) + self.assertRaisesIOError(errno.ENOENT, self.filesystem.remove_object, + self.filesystem.joinpaths( self.fake_child.name, 'some_bogus_filename')) def testRemoveObjectFromNonDirectoryError(self): - self.filesystem.AddObject(self.root_name, self.fake_file) - self.assertRaisesIOError(errno.ENOTDIR, self.filesystem.RemoveObject, - self.filesystem.JoinPaths( + self.filesystem.add_object(self.root_name, self.fake_file) + self.assertRaisesIOError(errno.ENOTDIR, self.filesystem.remove_object, + self.filesystem.joinpaths( '%s' % self.fake_file.name, 'file_does_not_matter_since_parent_not_a_directory')) def testExistsFileRemovedFromChild(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_file) - path = self.filesystem.JoinPaths(self.fake_child.name, + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_file) + path = self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name) - self.filesystem.RemoveObject(path) - self.assertFalse(self.filesystem.Exists(path)) + self.filesystem.remove_object(path) + self.assertFalse(self.filesystem.exists(path)) def testOperateOnGrandchildDirectory(self): - self.filesystem.AddObject(self.root_name, self.fake_child) - self.filesystem.AddObject(self.fake_child.name, self.fake_grandchild) - grandchild_directory = self.filesystem.JoinPaths(self.fake_child.name, + self.filesystem.add_object(self.root_name, self.fake_child) + self.filesystem.add_object(self.fake_child.name, self.fake_grandchild) + grandchild_directory = self.filesystem.joinpaths(self.fake_child.name, self.fake_grandchild.name) - grandchild_file = self.filesystem.JoinPaths(grandchild_directory, + grandchild_file = self.filesystem.joinpaths(grandchild_directory, self.fake_file.name) - self.assertRaises(IOError, self.filesystem.GetObject, grandchild_file) - self.filesystem.AddObject(grandchild_directory, self.fake_file) + self.assertRaises(IOError, self.filesystem.get_object, grandchild_file) + self.filesystem.add_object(grandchild_directory, self.fake_file) self.assertEqual(self.fake_file, - self.filesystem.GetObject(grandchild_file)) - self.assertTrue(self.filesystem.Exists(grandchild_file)) - self.filesystem.RemoveObject(grandchild_file) - self.assertRaises(IOError, self.filesystem.GetObject, grandchild_file) - self.assertFalse(self.filesystem.Exists(grandchild_file)) + self.filesystem.get_object(grandchild_file)) + self.assertTrue(self.filesystem.exists(grandchild_file)) + self.filesystem.remove_object(grandchild_file) + self.assertRaises(IOError, self.filesystem.get_object, grandchild_file) + self.assertFalse(self.filesystem.exists(grandchild_file)) def testCreateDirectoryInRootDirectory(self): path = 'foo' - self.filesystem.CreateDirectory(path) - new_dir = self.filesystem.GetObject(path) + self.filesystem.create_dir(path) + new_dir = self.filesystem.get_object(path) self.assertEqual(os.path.basename(path), new_dir.name) self.assertTrue(stat.S_IFDIR & new_dir.st_mode) def testCreateDirectoryInRootDirectoryAlreadyExistsError(self): path = 'foo' - self.filesystem.CreateDirectory(path) - self.assertRaisesOSError(errno.EEXIST, self.filesystem.CreateDirectory, - path) + self.filesystem.create_dir(path) + self.assertRaisesOSError( + errno.EEXIST, self.filesystem.create_dir, path) def testCreateDirectory(self): path = 'foo/bar/baz' - self.filesystem.CreateDirectory(path) - new_dir = self.filesystem.GetObject(path) + self.filesystem.create_dir(path) + new_dir = self.filesystem.get_object(path) self.assertEqual(os.path.basename(path), new_dir.name) self.assertTrue(stat.S_IFDIR & new_dir.st_mode) # Create second directory to make sure first is OK. path = '%s/quux' % path - self.filesystem.CreateDirectory(path) - new_dir = self.filesystem.GetObject(path) + self.filesystem.create_dir(path) + new_dir = self.filesystem.get_object(path) self.assertEqual(os.path.basename(path), new_dir.name) self.assertTrue(stat.S_IFDIR & new_dir.st_mode) def testCreateDirectoryAlreadyExistsError(self): path = 'foo/bar/baz' - self.filesystem.CreateDirectory(path) - self.assertRaisesOSError(errno.EEXIST, self.filesystem.CreateDirectory, - path) + self.filesystem.create_dir(path) + self.assertRaisesOSError( + errno.EEXIST, self.filesystem.create_dir, path) def testCreateFileInReadOnlyDirectoryRaisesInPosix(self): self.filesystem.is_windows_fs = False dir_path = '/foo/bar' - self.filesystem.CreateDirectory(dir_path, perm_bits=0o555) + self.filesystem.create_dir(dir_path, perm_bits=0o555) file_path = dir_path + '/baz' - self.assertRaisesOSError(errno.EACCES, self.filesystem.CreateFile, - file_path) + self.assertRaisesOSError( + errno.EACCES, self.filesystem.create_file, file_path) def testCreateFileInReadOnlyDirectoryPossibleInWindows(self): self.filesystem.is_windows_fs = True dir_path = 'C:/foo/bar' - self.filesystem.CreateDirectory(dir_path, perm_bits=0o555) + self.filesystem.create_dir(dir_path, perm_bits=0o555) file_path = dir_path + '/baz' - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) def testCreateFileInCurrentDirectory(self): path = 'foo' contents = 'dummy data' - self.filesystem.CreateFile(path, contents=contents) - self.assertTrue(self.filesystem.Exists(path)) - self.assertFalse(self.filesystem.Exists(os.path.dirname(path))) + self.filesystem.create_file(path, contents=contents) + self.assertTrue(self.filesystem.exists(path)) + self.assertFalse(self.filesystem.exists(os.path.dirname(path))) path = './%s' % path - self.assertTrue(self.filesystem.Exists(os.path.dirname(path))) + self.assertTrue(self.filesystem.exists(os.path.dirname(path))) def testCreateFileInRootDirectory(self): path = '/foo' contents = 'dummy data' - self.filesystem.CreateFile(path, contents=contents) - new_file = self.filesystem.GetObject(path) - self.assertTrue(self.filesystem.Exists(path)) - self.assertTrue(self.filesystem.Exists(os.path.dirname(path))) + self.filesystem.create_file(path, contents=contents) + new_file = self.filesystem.get_object(path) + self.assertTrue(self.filesystem.exists(path)) + self.assertTrue(self.filesystem.exists(os.path.dirname(path))) self.assertEqual(os.path.basename(path), new_file.name) self.assertTrue(stat.S_IFREG & new_file.st_mode) self.assertEqual(contents, new_file.contents) def testCreateFileWithSizeButNoContentCreatesLargeFile(self): path = 'large_foo_bar' - self.filesystem.CreateFile(path, st_size=100000000) - new_file = self.filesystem.GetObject(path) + self.filesystem.create_file(path, st_size=100000000) + new_file = self.filesystem.get_object(path) self.assertEqual(None, new_file.contents) self.assertEqual(100000000, new_file.st_size) def testCreateFileInRootDirectoryAlreadyExistsError(self): path = 'foo' - self.filesystem.CreateFile(path) - self.assertRaisesOSError(errno.EEXIST, self.filesystem.CreateFile, - path) + self.filesystem.create_file(path) + self.assertRaisesOSError( + errno.EEXIST, self.filesystem.create_file, path) def testCreateFile(self): path = 'foo/bar/baz' - retval = self.filesystem.CreateFile(path, contents='dummy_data') - self.assertTrue(self.filesystem.Exists(path)) - self.assertTrue(self.filesystem.Exists(os.path.dirname(path))) - new_file = self.filesystem.GetObject(path) + retval = self.filesystem.create_file(path, contents='dummy_data') + self.assertTrue(self.filesystem.exists(path)) + self.assertTrue(self.filesystem.exists(os.path.dirname(path))) + new_file = self.filesystem.get_object(path) self.assertEqual(os.path.basename(path), new_file.name) self.assertTrue(stat.S_IFREG & new_file.st_mode) self.assertEqual(new_file, retval) def testCreateFileAlreadyExistsError(self): path = 'foo/bar/baz' - self.filesystem.CreateFile(path, contents='dummy_data') - self.assertRaisesOSError(errno.EEXIST, self.filesystem.CreateFile, - path) + self.filesystem.create_file(path, contents='dummy_data') + self.assertRaisesOSError( + errno.EEXIST, self.filesystem.create_file, path) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testCreateLink(self): path = 'foo/bar/baz' target_path = 'foo/bar/quux' - new_file = self.filesystem.CreateLink(path, 'quux') + new_file = self.filesystem.symlink(path, 'quux') # Neither the path not the final target exists before we actually write to # one of them, even though the link appears in the file system. - self.assertFalse(self.filesystem.Exists(path)) - self.assertFalse(self.filesystem.Exists(target_path)) + self.assertFalse(self.filesystem.exists(path)) + self.assertFalse(self.filesystem.exists(target_path)) self.assertTrue(stat.S_IFLNK & new_file.st_mode) # but once we write the linked to file, they both will exist. - self.filesystem.CreateFile(target_path) - self.assertTrue(self.filesystem.Exists(path)) - self.assertTrue(self.filesystem.Exists(target_path)) + self.filesystem.create_file(target_path) + self.assertTrue(self.filesystem.exists(path)) + self.assertTrue(self.filesystem.exists(target_path)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') @@ -556,10 +562,10 @@ def testResolveObject(self): target_path = 'dir/target' target_contents = '0123456789ABCDEF' link_name = 'x' - self.filesystem.CreateDirectory('dir') - self.filesystem.CreateFile('dir/target', contents=target_contents) - self.filesystem.CreateLink(link_name, target_path) - obj = self.filesystem.ResolveObject(link_name) + self.filesystem.create_dir('dir') + self.filesystem.create_file('dir/target', contents=target_contents) + self.filesystem.symlink(link_name, target_path) + obj = self.filesystem.resolve(link_name) self.assertEqual('target', obj.name) self.assertEqual(target_contents, obj.contents) @@ -567,10 +573,10 @@ def checkLresolveObject(self): target_path = 'dir/target' target_contents = '0123456789ABCDEF' link_name = 'x' - self.filesystem.CreateDirectory('dir') - self.filesystem.CreateFile('dir/target', contents=target_contents) - self.filesystem.CreateLink(link_name, target_path) - obj = self.filesystem.LResolveObject(link_name) + self.filesystem.create_dir('dir') + self.filesystem.create_file('dir/target', contents=target_contents) + self.filesystem.symlink(link_name, target_path) + obj = self.filesystem.lresolve(link_name) self.assertEqual(link_name, obj.name) self.assertEqual(target_path, obj.contents) @@ -585,16 +591,11 @@ def testLresolveObjectPosix(self): self.checkLresolveObject() def checkDirectoryAccessOnFile(self, error_subtype): - self.filesystem.CreateFile('not_a_dir') - self.assertRaisesIOError(error_subtype, self.filesystem.ResolveObject, - 'not_a_dir/foo') - self.assertRaisesIOError(error_subtype, self.filesystem.ResolveObject, - 'not_a_dir/foo/bar') - self.assertRaisesIOError(error_subtype, self.filesystem.LResolveObject, - 'not_a_dir/foo') - self.assertRaisesIOError(error_subtype, - self.filesystem.LResolveObject, - 'not_a_dir/foo/bar') + self.filesystem.create_file('not_a_dir') + self.assertRaisesIOError( + error_subtype, self.filesystem.resolve, 'not_a_dir/foo') + self.assertRaisesIOError( + error_subtype, self.filesystem.lresolve, 'not_a_dir/foo/bar') def testDirectoryAccessOnFileWindows(self): self.filesystem.is_windows_fs = True @@ -613,49 +614,49 @@ def setUp(self): self.path = self.os.path def testGetObject(self): - self.filesystem.CreateDirectory('/foo/bar') - self.filesystem.CreateFile('/foo/bar/baz') - self.assertTrue(self.filesystem.GetObject('/Foo/Bar/Baz')) + self.filesystem.create_dir('/foo/bar') + self.filesystem.create_file('/foo/bar/baz') + self.assertTrue(self.filesystem.get_object('/Foo/Bar/Baz')) def testRemoveObject(self): - self.filesystem.CreateDirectory('/foo/bar') - self.filesystem.CreateFile('/foo/bar/baz') - self.filesystem.RemoveObject('/Foo/Bar/Baz') - self.assertFalse(self.filesystem.Exists('/foo/bar/baz')) + self.filesystem.create_dir('/foo/bar') + self.filesystem.create_file('/foo/bar/baz') + self.filesystem.remove_object('/Foo/Bar/Baz') + self.assertFalse(self.filesystem.exists('/foo/bar/baz')) def testExists(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.assertTrue(self.filesystem.Exists('/Foo/Bar')) - self.assertTrue(self.filesystem.Exists('/foo/bar')) + self.filesystem.create_dir('/Foo/Bar') + self.assertTrue(self.filesystem.exists('/Foo/Bar')) + self.assertTrue(self.filesystem.exists('/foo/bar')) - self.filesystem.CreateFile('/foo/Bar/baz') - self.assertTrue(self.filesystem.Exists('/Foo/bar/BAZ')) - self.assertTrue(self.filesystem.Exists('/foo/bar/baz')) + self.filesystem.create_file('/foo/Bar/baz') + self.assertTrue(self.filesystem.exists('/Foo/bar/BAZ')) + self.assertTrue(self.filesystem.exists('/foo/bar/baz')) def testCreateDirectoryWithDifferentCaseRoot(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.filesystem.CreateDirectory('/foo/bar/baz') - dir1 = self.filesystem.GetObject('/Foo/Bar') - dir2 = self.filesystem.GetObject('/foo/bar') + self.filesystem.create_dir('/Foo/Bar') + self.filesystem.create_dir('/foo/bar/baz') + dir1 = self.filesystem.get_object('/Foo/Bar') + dir2 = self.filesystem.get_object('/foo/bar') self.assertEqual(dir1, dir2) def testCreateFileWithDifferentCaseDir(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.filesystem.CreateFile('/foo/bar/baz') - dir1 = self.filesystem.GetObject('/Foo/Bar') - dir2 = self.filesystem.GetObject('/foo/bar') + self.filesystem.create_dir('/Foo/Bar') + self.filesystem.create_file('/foo/bar/baz') + dir1 = self.filesystem.get_object('/Foo/Bar') + dir2 = self.filesystem.get_object('/foo/bar') self.assertEqual(dir1, dir2) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testResolvePath(self): - self.filesystem.CreateDirectory('/foo/baz') - self.filesystem.CreateLink('/Foo/Bar', './baz/bip') + self.filesystem.create_dir('/foo/baz') + self.filesystem.symlink('/Foo/Bar', './baz/bip') self.assertEqual('/foo/baz/bip', - self.filesystem.ResolvePath('/foo/bar')) + self.filesystem.resolve_path('/foo/bar')) def testIsdirIsfile(self): - self.filesystem.CreateFile('foo/bar') + self.filesystem.create_file('foo/bar') self.assertTrue(self.path.isdir('Foo')) self.assertFalse(self.path.isfile('Foo')) self.assertTrue(self.path.isfile('Foo/Bar')) @@ -663,26 +664,26 @@ def testIsdirIsfile(self): def testGetsize(self): file_path = 'foo/bar/baz' - self.filesystem.CreateFile(file_path, contents='1234567') + self.filesystem.create_file(file_path, contents='1234567') self.assertEqual(7, self.path.getsize('FOO/BAR/BAZ')) def testGetsizeWithLoopingSymlink(self): self.filesystem.is_windows_fs = False dir_path = '/foo/bar' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) link_path = dir_path + "/link" link_target = link_path + "/link" self.os.symlink(link_target, link_path) self.assertRaisesOSError(errno.ELOOP, self.os.path.getsize, link_path) def testGetMtime(self): - test_file = self.filesystem.CreateFile('foo/bar1.txt') - test_file.SetMTime(24) + test_file = self.filesystem.create_file('foo/bar1.txt') + test_file.st_mtime = 24 self.assertEqual(24, self.path.getmtime('Foo/Bar1.TXT')) def testGetObjectWithFileSize(self): - self.filesystem.CreateFile('/Foo/Bar', st_size=10) - self.assertTrue(self.filesystem.GetObject('/foo/bar')) + self.filesystem.create_file('/Foo/Bar', st_size=10) + self.assertTrue(self.filesystem.get_object('/foo/bar')) class CaseSensitiveFakeFilesystemTest(TestCase): @@ -693,42 +694,42 @@ def setUp(self): self.path = self.os.path def testGetObject(self): - self.filesystem.CreateDirectory('/foo/bar') - self.filesystem.CreateFile('/foo/bar/baz') - self.assertRaises(IOError, self.filesystem.GetObject, '/Foo/Bar/Baz') + self.filesystem.create_dir('/foo/bar') + self.filesystem.create_file('/foo/bar/baz') + self.assertRaises(IOError, self.filesystem.get_object, '/Foo/Bar/Baz') def testRemoveObject(self): - self.filesystem.CreateDirectory('/foo/bar') - self.filesystem.CreateFile('/foo/bar/baz') - self.assertRaises(IOError, self.filesystem.RemoveObject, - '/Foo/Bar/Baz') - self.assertTrue(self.filesystem.Exists('/foo/bar/baz')) + self.filesystem.create_dir('/foo/bar') + self.filesystem.create_file('/foo/bar/baz') + self.assertRaises( + IOError, self.filesystem.remove_object, '/Foo/Bar/Baz') + self.assertTrue(self.filesystem.exists('/foo/bar/baz')) def testExists(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.assertTrue(self.filesystem.Exists('/Foo/Bar')) - self.assertFalse(self.filesystem.Exists('/foo/bar')) + self.filesystem.create_dir('/Foo/Bar') + self.assertTrue(self.filesystem.exists('/Foo/Bar')) + self.assertFalse(self.filesystem.exists('/foo/bar')) - self.filesystem.CreateFile('/foo/Bar/baz') - self.assertFalse(self.filesystem.Exists('/Foo/bar/BAZ')) - self.assertFalse(self.filesystem.Exists('/foo/bar/baz')) + self.filesystem.create_file('/foo/Bar/baz') + self.assertFalse(self.filesystem.exists('/Foo/bar/BAZ')) + self.assertFalse(self.filesystem.exists('/foo/bar/baz')) def testCreateDirectoryWithDifferentCaseRoot(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.filesystem.CreateDirectory('/foo/bar/baz') - dir1 = self.filesystem.GetObject('/Foo/Bar') - dir2 = self.filesystem.GetObject('/foo/bar') + self.filesystem.create_dir('/Foo/Bar') + self.filesystem.create_dir('/foo/bar/baz') + dir1 = self.filesystem.get_object('/Foo/Bar') + dir2 = self.filesystem.get_object('/foo/bar') self.assertNotEqual(dir1, dir2) def testCreateFileWithDifferentCaseDir(self): - self.filesystem.CreateDirectory('/Foo/Bar') - self.filesystem.CreateFile('/foo/bar/baz') - dir1 = self.filesystem.GetObject('/Foo/Bar') - dir2 = self.filesystem.GetObject('/foo/bar') + self.filesystem.create_dir('/Foo/Bar') + self.filesystem.create_file('/foo/bar/baz') + dir1 = self.filesystem.get_object('/Foo/Bar') + dir2 = self.filesystem.get_object('/foo/bar') self.assertNotEqual(dir1, dir2) def testIsdirIsfile(self): - self.filesystem.CreateFile('foo/bar') + self.filesystem.create_file('foo/bar') self.assertFalse(self.path.isdir('Foo')) self.assertFalse(self.path.isfile('Foo')) self.assertFalse(self.path.isfile('Foo/Bar')) @@ -736,14 +737,14 @@ def testIsdirIsfile(self): def testGetsize(self): file_path = 'foo/bar/baz' - self.filesystem.CreateFile(file_path, contents='1234567') + self.filesystem.create_file(file_path, contents='1234567') self.assertRaises(os.error, self.path.getsize, 'FOO/BAR/BAZ') def testGetMtime(self): - test_file = self.filesystem.CreateFile('foo/bar1.txt') - test_file.SetMTime(24) - self.assertRaisesOSError(errno.ENOENT, self.path.getmtime, - 'Foo/Bar1.TXT') + test_file = self.filesystem.create_file('foo/bar1.txt') + test_file.st_mtime = 24 + self.assertRaisesOSError( + errno.ENOENT, self.path.getmtime, 'Foo/Bar1.TXT') class FakeOsModuleTestBase(TestCase): @@ -752,8 +753,8 @@ def setUp(self): self.os = fake_filesystem.FakeOsModule(self.filesystem) def _CreateTestFile(self, path): - test_file = self.filesystem.CreateFile(path) - self.assertTrue(self.filesystem.Exists(path)) + test_file = self.filesystem.create_file(path) + self.assertTrue(self.filesystem.exists(path)) st = self.os.stat(path) self.assertEqual(0o666, stat.S_IMODE(st.st_mode)) self.assertTrue(st.st_mode & stat.S_IFREG) @@ -761,8 +762,8 @@ def _CreateTestFile(self, path): return test_file def _CreateTestDirectory(self, path): - self.filesystem.CreateDirectory(path) - self.assertTrue(self.filesystem.Exists(path)) + self.filesystem.create_dir(path) + self.assertTrue(self.filesystem.exists(path)) st = self.os.stat(path) self.assertEqual(0o777, stat.S_IMODE(st.st_mode)) self.assertFalse(st.st_mode & stat.S_IFREG) @@ -778,7 +779,7 @@ def setUp(self): def testChdir(self): """chdir should work on a directory.""" directory = '/foo' - self.filesystem.CreateDirectory(directory) + self.filesystem.create_dir(directory) self.os.chdir(directory) def testChdirFailsNonExist(self): @@ -789,7 +790,7 @@ def testChdirFailsNonExist(self): def testChdirFailsNonDirectory(self): """chdir should raies OSError if the target is not a directory.""" filename = '/foo/bar' - self.filesystem.CreateFile(filename) + self.filesystem.create_file(filename) self.assertRaisesOSError(errno.ENOTDIR, self.os.chdir, filename) def testConsecutiveChdir(self): @@ -797,7 +798,7 @@ def testConsecutiveChdir(self): dir1 = 'foo' dir2 = 'bar' full_dirname = self.os.path.join(dir1, dir2) - self.filesystem.CreateDirectory(full_dirname) + self.filesystem.create_dir(full_dirname) self.os.chdir(dir1) self.os.chdir(dir2) self.assertEqual(self.os.getcwd(), self.os.path.sep + full_dirname) @@ -807,7 +808,7 @@ def testBackwardsChdir(self): rootdir = self.os.getcwd() dirname = 'foo' abs_dirname = self.os.path.abspath(dirname) - self.filesystem.CreateDirectory(dirname) + self.filesystem.create_dir(dirname) self.os.chdir(dirname) self.assertEqual(abs_dirname, self.os.getcwd()) self.os.chdir('..') @@ -817,7 +818,7 @@ def testBackwardsChdir(self): def testGetCwd(self): dirname = '/foo/bar' - self.filesystem.CreateDirectory(dirname) + self.filesystem.create_dir(dirname) self.assertEqual(self.os.getcwd(), self.os.path.sep) self.os.chdir(dirname) self.assertEqual(self.os.getcwd(), dirname) @@ -826,7 +827,7 @@ def testListdir(self): directory = 'xyzzy/plugh' files = ['foo', 'bar', 'baz'] for f in files: - self.filesystem.CreateFile('%s/%s' % (directory, f)) + self.filesystem.create_file('%s/%s' % (directory, f)) files.sort() self.assertEqual(files, sorted(self.os.listdir(directory))) @@ -838,7 +839,7 @@ def testListdirUsesOpenFdAsPath(self): dir_path = 'xyzzy/plugh' files = ['foo', 'bar', 'baz'] for f in files: - self.filesystem.CreateFile('%s/%s' % (dir_path, f)) + self.filesystem.create_file('%s/%s' % (dir_path, f)) files.sort() path_des = self.os.open(dir_path, os.O_RDONLY) @@ -849,7 +850,7 @@ def testListdirReturnsList(self): self.os.mkdir(directory_root) directory = '%s/bug' % directory_root self.os.mkdir(directory) - self.filesystem.CreateFile('%s/%s' % (directory, 'foo')) + self.filesystem.create_file('%s/%s' % (directory, 'foo')) self.assertEqual(['foo'], self.os.listdir(directory)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), @@ -858,30 +859,30 @@ def testListdirOnSymlink(self): directory = 'xyzzy' files = ['foo', 'bar', 'baz'] for f in files: - self.filesystem.CreateFile('%s/%s' % (directory, f)) - self.filesystem.CreateLink('symlink', 'xyzzy') + self.filesystem.create_file('%s/%s' % (directory, f)) + self.filesystem.symlink('symlink', 'xyzzy') files.sort() self.assertEqual(files, sorted(self.os.listdir('symlink'))) def testListdirError(self): file_path = 'foo/bar/baz' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.listdir, file_path) def testExistsCurrentDir(self): - self.assertTrue(self.filesystem.Exists('.')) + self.assertTrue(self.filesystem.exists('.')) def testListdirCurrent(self): files = ['foo', 'bar', 'baz'] for f in files: - self.filesystem.CreateFile('%s' % f) + self.filesystem.create_file('%s' % f) files.sort() self.assertEqual(files, sorted(self.os.listdir('.'))) def testFdopen(self): fake_open = fake_filesystem.FakeFileOpen(self.filesystem) file_path1 = 'some_file1' - self.filesystem.CreateFile(file_path1, contents='contents here1') + self.filesystem.create_file(file_path1, contents='contents here1') fake_file1 = fake_open(file_path1, 'r') self.assertEqual(0, fake_file1.fileno()) @@ -899,9 +900,9 @@ def testClosedFileDescriptor(self): first_path = 'some_file1' second_path = 'some_file2' third_path = 'some_file3' - self.filesystem.CreateFile(first_path, contents='contents here1') - self.filesystem.CreateFile(second_path, contents='contents here2') - self.filesystem.CreateFile(third_path, contents='contents here3') + self.filesystem.create_file(first_path, contents='contents here1') + self.filesystem.create_file(second_path, contents='contents here2') + self.filesystem.create_file(third_path, contents='contents here3') fake_file1 = fake_open(first_path, 'r') fake_file2 = fake_open(second_path, 'r') @@ -923,9 +924,9 @@ def testClosedFileDescriptor(self): def testFdopenMode(self): fake_open = fake_filesystem.FakeFileOpen(self.filesystem) file_path1 = 'some_file1' - self.filesystem.CreateFile(file_path1, contents='contents here1', - st_mode=( - (stat.S_IFREG | 0o666) ^ stat.S_IWRITE)) + self.filesystem.create_file( + file_path1, contents='contents here1', + st_mode=((stat.S_IFREG | 0o666) ^ stat.S_IWRITE)) fake_file1 = fake_open(file_path1, 'r') self.assertEqual(0, fake_file1.fileno()) @@ -937,7 +938,7 @@ def testFdopenMode(self): def testFstat(self): directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path, contents='ABCDE') + self.filesystem.create_file(file_path, contents='ABCDE') fake_open = fake_filesystem.FakeFileOpen(self.filesystem) file_obj = fake_open(file_path) fileno = file_obj.fileno() @@ -948,7 +949,7 @@ def testFstat(self): def testStat(self): directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path, contents='ABCDE') + self.filesystem.create_file(file_path, contents='ABCDE') self.assertTrue(stat.S_IFDIR & self.os.stat(directory)[stat.ST_MODE]) self.assertTrue(stat.S_IFREG & self.os.stat(file_path)[stat.ST_MODE]) self.assertTrue(stat.S_IFREG & self.os.stat(file_path).st_mode) @@ -959,7 +960,7 @@ def testStat(self): def testStatUsesOpenFdAsPath(self): self.assertRaisesOSError(errno.EBADF, self.os.stat, 5) file_path = '/foo/bar' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) with FakeFileOpen(self.filesystem)(file_path) as f: self.assertTrue( @@ -976,8 +977,8 @@ def testStatNoFollowSymlinks(self): self.assertNotEqual(len(base_name), len(file_contents)) file_path = '%s/%s' % (directory, base_name) link_path = '%s/link' % directory - self.filesystem.CreateFile(file_path, contents=file_contents) - self.filesystem.CreateLink(link_path, base_name) + self.filesystem.create_file(file_path, contents=file_contents) + self.filesystem.symlink(link_path, base_name) self.assertEqual(len(file_contents), self.os.stat(file_path, follow_symlinks=False)[ stat.ST_SIZE]) @@ -995,8 +996,8 @@ def testLstat(self): self.assertNotEqual(len(base_name), len(file_contents)) file_path = '%s/%s' % (directory, base_name) link_path = '%s/link' % directory - self.filesystem.CreateFile(file_path, contents=file_contents) - self.filesystem.CreateLink(link_path, base_name) + self.filesystem.create_file(file_path, contents=file_contents) + self.filesystem.symlink(link_path, base_name) self.assertEqual(len(file_contents), self.os.lstat(file_path)[stat.ST_SIZE]) self.assertEqual(len(base_name), @@ -1009,8 +1010,8 @@ def testLstatUsesOpenFdAsPath(self): file_path = '/foo/bar' link_path = '/foo/link' file_contents = b'contents' - self.filesystem.CreateFile(file_path, contents=file_contents) - self.filesystem.CreateLink(link_path, file_path) + self.filesystem.create_file(file_path, contents=file_contents) + self.filesystem.symlink(link_path, file_path) with FakeFileOpen(self.filesystem)(file_path) as f: self.assertEqual(len(file_contents), @@ -1019,7 +1020,7 @@ def testLstatUsesOpenFdAsPath(self): def testStatNonExistentFile(self): # set up file_path = '/non/existent/file' - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) # actual tests try: # Use try-catch to check exception attributes. @@ -1034,12 +1035,12 @@ def testStatNonExistentFile(self): def testReadlink(self): link_path = 'foo/bar/baz' target = 'tarJAY' - self.filesystem.CreateLink(link_path, target) + self.filesystem.symlink(link_path, target) self.assertEqual(self.os.readlink(link_path), target) def checkReadlinkRaisesIfPathIsNotALink(self): file_path = 'foo/bar/eleventyone' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.EINVAL, self.os.readlink, file_path) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), @@ -1053,7 +1054,7 @@ def testReadlinkRaisesIfPathIsNotALinkPosix(self): self.checkReadlinkRaisesIfPathIsNotALink() def checkReadlinkRaisesIfPathHasFile(self, error_subtype): - self.filesystem.CreateFile('/a_file') + self.filesystem.create_file('/a_file') file_path = '/a_file/foo' self.assertRaisesOSError(error_subtype, self.os.readlink, file_path) file_path = '/a_file/foo/bar' @@ -1083,52 +1084,51 @@ def testReadlinkRaisesIfPathIsNone(self): @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testReadlinkWithLinksInPath(self): - self.filesystem.CreateLink('/meyer/lemon/pie', 'yum') - self.filesystem.CreateLink('/geo/metro', '/meyer') + self.filesystem.symlink('/meyer/lemon/pie', 'yum') + self.filesystem.symlink('/geo/metro', '/meyer') self.assertEqual('yum', self.os.readlink('/geo/metro/lemon/pie')) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testReadlinkWithChainedLinksInPath(self): - self.filesystem.CreateLink('/eastern/european/wolfhounds/chase', - 'cats') - self.filesystem.CreateLink('/russian', '/eastern/european') - self.filesystem.CreateLink('/dogs', '/russian/wolfhounds') + self.filesystem.symlink('/eastern/european/wolfhounds/chase', 'cats') + self.filesystem.symlink('/russian', '/eastern/european') + self.filesystem.symlink('/dogs', '/russian/wolfhounds') self.assertEqual('cats', self.os.readlink('/dogs/chase')) def testRemoveDir(self): directory = 'xyzzy' dir_path = '/%s/plugh' % directory - self.filesystem.CreateDirectory(dir_path) - self.assertTrue(self.filesystem.Exists(dir_path)) + self.filesystem.create_dir(dir_path) + self.assertTrue(self.filesystem.exists(dir_path)) self.assertRaisesOSError(errno.EISDIR, self.os.remove, dir_path) - self.assertTrue(self.filesystem.Exists(dir_path)) + self.assertTrue(self.filesystem.exists(dir_path)) self.os.chdir(directory) self.assertRaisesOSError(errno.EISDIR, self.os.remove, 'plugh') - self.assertTrue(self.filesystem.Exists(dir_path)) + self.assertTrue(self.filesystem.exists(dir_path)) self.assertRaisesOSError(errno.ENOENT, self.os.remove, '/plugh') def testRemoveFile(self): directory = 'zzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.os.remove(file_path) - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) def testRemoveFileNoDirectory(self): directory = 'zzy' file_name = 'plugh' file_path = '%s/%s' % (directory, file_name) - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.os.chdir(directory) self.os.remove(file_name) - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) def testRemoveFileWithoutPermissionRaises(self): path = self.os.path.join('/foo/bar') - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.os.chmod(path, 0o444) self.assertRaisesOSError(errno.EACCES, self.os.remove, path) @@ -1136,19 +1136,19 @@ def testRemoveOpenFileFailsUnderWindows(self): self.filesystem.is_windows_fs = True fake_open = fake_filesystem.FakeFileOpen(self.filesystem) path = self.os.path.join('/foo/bar') - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) fake_open(path, 'r') self.assertRaisesOSError(errno.EACCES, self.os.remove, path) - self.assertTrue(self.filesystem.Exists(path)) + self.assertTrue(self.filesystem.exists(path)) def testRemoveOpenFilePossibleUnderPosix(self): self.filesystem.is_windows_fs = False fake_open = fake_filesystem.FakeFileOpen(self.filesystem) path = self.os.path.join('/foo/bar') - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) fake_open(path, 'r') self.os.remove(path) - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) def testRemoveFileRelativePath(self): original_dir = self.os.getcwd() @@ -1157,19 +1157,19 @@ def testRemoveFileRelativePath(self): file_name = 'plugh' file_path = '%s/%s' % (directory, file_name) file_path_relative = self.os.path.join('..', file_name) - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) - self.filesystem.CreateDirectory(subdirectory) - self.assertTrue(self.filesystem.Exists(subdirectory)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) + self.filesystem.create_dir(subdirectory) + self.assertTrue(self.filesystem.exists(subdirectory)) self.os.chdir(subdirectory) self.os.remove(file_path_relative) - self.assertFalse(self.filesystem.Exists(file_path_relative)) + self.assertFalse(self.filesystem.exists(file_path_relative)) self.os.chdir(original_dir) - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) def testRemoveDirRaisesError(self): directory = 'zzy' - self.filesystem.CreateDirectory(directory) + self.filesystem.create_dir(directory) self.assertRaisesOSError(errno.EISDIR, self.os.remove, directory) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), @@ -1177,17 +1177,17 @@ def testRemoveDirRaisesError(self): def testRemoveSymlinkToDir(self): directory = 'zzy' link = 'link_to_dir' - self.filesystem.CreateDirectory(directory) + self.filesystem.create_dir(directory) self.os.symlink(directory, link) - self.assertTrue(self.filesystem.Exists(directory)) - self.assertTrue(self.filesystem.Exists(link)) + self.assertTrue(self.filesystem.exists(directory)) + self.assertTrue(self.filesystem.exists(link)) self.os.remove(link) - self.assertTrue(self.filesystem.Exists(directory)) - self.assertFalse(self.filesystem.Exists(link)) + self.assertTrue(self.filesystem.exists(directory)) + self.assertFalse(self.filesystem.exists(link)) def testUnlinkRaisesIfNotExist(self): file_path = '/file/does/not/exist' - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.ENOENT, self.os.unlink, file_path) def testRenameToNonexistentFile(self): @@ -1195,14 +1195,14 @@ def testRenameToNonexistentFile(self): directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/plugh_new' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents') - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertFalse(self.filesystem.Exists(new_file_path)) + self.filesystem.create_file(old_file_path, contents='test contents') + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertFalse(self.filesystem.exists(new_file_path)) self.os.rename(old_file_path, new_file_path) - self.assertFalse(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.assertFalse(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.assertEqual('test contents', - self.filesystem.GetObject(new_file_path).contents) + self.filesystem.get_object(new_file_path).contents) def testRenameDirToSymlinkPosix(self): self.filesystem.is_windows_fs = False @@ -1210,7 +1210,7 @@ def testRenameDirToSymlinkPosix(self): link_path = base_path + "/link" dir_path = base_path + "/dir" link_target = dir_path + "/link_target" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(link_target, link_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.rename, dir_path, link_path) @@ -1223,7 +1223,7 @@ def testRenameDirToSymlinkWindows(self): link_path = base_path + "/link" dir_path = base_path + "/dir" link_target = dir_path + "/link_target" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(link_target, link_path) self.assertRaisesOSError(errno.EEXIST, self.os.rename, dir_path, link_path) @@ -1231,27 +1231,27 @@ def testRenameDirToSymlinkWindows(self): def testRenameFileToSymlink(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) link_path = base_path + '/file_link' file_path = base_path + '/file' self.os.symlink(file_path, link_path) - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.rename(file_path, link_path) - self.assertFalse(self.filesystem.Exists(file_path)) - self.assertTrue(self.filesystem.Exists(link_path)) + self.assertFalse(self.filesystem.exists(file_path)) + self.assertTrue(self.filesystem.exists(link_path)) self.assertTrue(self.os.path.isfile(link_path)) def testRenameSymlinkToSymlink(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) link_path1 = base_path + '/link1' link_path2 = base_path + '/link2' self.os.symlink(base_path, link_path1) self.os.symlink(base_path, link_path2) self.os.rename(link_path1, link_path2) - self.assertFalse(self.filesystem.Exists(link_path1)) - self.assertTrue(self.filesystem.Exists(link_path2)) + self.assertFalse(self.filesystem.exists(link_path1)) + self.assertTrue(self.filesystem.exists(link_path2)) def testRenameSymlinkToSymlinkForParentRaises(self): self.filesystem.is_windows_fs = False @@ -1259,16 +1259,16 @@ def testRenameSymlinkToSymlinkForParentRaises(self): dir_link = base_path + "/dir_link" dir_path = base_path + "/dir" dir_in_dir_path = dir_link + "/inner_dir" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, dir_link) - self.filesystem.CreateDirectory(dir_in_dir_path) - self.assertRaisesOSError(errno.EINVAL, self.os.rename, dir_path, - dir_in_dir_path) + self.filesystem.create_dir(dir_in_dir_path) + self.assertRaisesOSError( + errno.EINVAL, self.os.rename, dir_path, dir_in_dir_path) def testRecursiveRenameRaises(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) new_path = base_path + "/new_dir" self.assertRaisesOSError(errno.EINVAL, self.os.rename, base_path, new_path) @@ -1277,23 +1277,23 @@ def testRenameFileToParentDirFile(self): """Regression test for issue 230.""" base_path = '/foo' dir_path = base_path + "/dir" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) file_path = base_path + "/old_file" new_file_path = dir_path + "/new_file" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.rename(file_path, new_file_path) def testRenameWithTargetParentFileRaisesPosix(self): self.filesystem.is_windows_fs = False file_path = "/foo/baz" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.rename, file_path, file_path + '/new') def testRenameWithTargetParentFileRaisesWindows(self): self.filesystem.is_windows_fs = True file_path = "/foo/baz" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.EACCES, self.os.rename, file_path, file_path + '/new') @@ -1302,7 +1302,7 @@ def testRenameSymlinkToSource(self): base_path = "/foo" link_path = base_path + "/slink" file_path = base_path + "/file" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.symlink(file_path, link_path) self.os.rename(link_path, file_path) self.assertFalse(self.os.path.exists(file_path)) @@ -1312,7 +1312,7 @@ def testRenameSymlinkToDirRaises(self): base_path = '/foo/bar' link_path = base_path + '/dir_link' dir_path = base_path + '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, link_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.rename, link_path, dir_path) @@ -1320,7 +1320,7 @@ def testRenameSymlinkToDirRaises(self): def testRenameBrokenSymlink(self): self.filesystem.is_windows_fs = False base_path = "/foo" - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) link_path = base_path + "/slink" file_path = base_path + "/file" self.os.symlink(file_path, link_path) @@ -1335,35 +1335,35 @@ def testChangeCaseInCaseInsensitiveFileSystem(self): directory = 'xyzzy' old_file_path = '/%s/fileName' % directory new_file_path = '/%s/FileNAME' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents') + self.filesystem.create_file(old_file_path, contents='test contents') self.assertEqual(old_file_path, - self.filesystem.NormalizeCase(old_file_path)) + self.filesystem._original_path(old_file_path)) self.os.rename(old_file_path, new_file_path) - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.assertEqual(new_file_path, - self.filesystem.NormalizeCase(old_file_path)) + self.filesystem._original_path(old_file_path)) def testRenameDirectory(self): """Can rename a directory to an unused name.""" for old_path, new_path in [('wxyyw', 'xyzzy'), ('/abccb', 'cdeed')]: - self.filesystem.CreateFile('%s/plugh' % old_path, contents='test') - self.assertTrue(self.filesystem.Exists(old_path)) - self.assertFalse(self.filesystem.Exists(new_path)) + self.filesystem.create_file('%s/plugh' % old_path, contents='test') + self.assertTrue(self.filesystem.exists(old_path)) + self.assertFalse(self.filesystem.exists(new_path)) self.os.rename(old_path, new_path) - self.assertFalse(self.filesystem.Exists(old_path)) - self.assertTrue(self.filesystem.Exists(new_path)) + self.assertFalse(self.filesystem.exists(old_path)) + self.assertTrue(self.filesystem.exists(new_path)) self.assertEqual( 'test', - self.filesystem.GetObject('%s/plugh' % new_path).contents) - self.assertEqual(3, self.filesystem.GetObject(new_path).st_nlink) + self.filesystem.get_object('%s/plugh' % new_path).contents) + self.assertEqual(3, self.filesystem.get_object(new_path).st_nlink) def testRenameDirectoryToExistingFileRaises(self): base_path = '/foo/bar' dir_path = base_path + "/dir" file_path = base_path + "/file" - self.filesystem.CreateDirectory(dir_path) - self.filesystem.CreateFile(file_path) + self.filesystem.create_dir(dir_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.rename, dir_path, file_path) @@ -1372,8 +1372,8 @@ def testRenameToExistingDirectoryShouldRaiseUnderWindows(self): self.filesystem.is_windows_fs = True old_path = '/foo/bar' new_path = '/foo/baz' - self.filesystem.CreateDirectory(old_path) - self.filesystem.CreateDirectory(new_path) + self.filesystem.create_dir(old_path) + self.filesystem.create_dir(new_path) self.assertRaisesOSError(errno.EEXIST, self.os.rename, old_path, new_path) @@ -1381,24 +1381,24 @@ def testRenameToAHardlinkOfSameFileShouldDoNothing(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' file_path = base_path + '/dir/file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) link_path = base_path + "/link" self.os.link(file_path, link_path) self.os.rename(file_path, link_path) - self.assertTrue(self.filesystem.Exists(file_path)) - self.assertTrue(self.filesystem.Exists(link_path)) + self.assertTrue(self.filesystem.exists(file_path)) + self.assertTrue(self.filesystem.exists(link_path)) def testHardlinkWorksWithSymlink(self): self.filesystem.is_windows_fs = False base_path = "/foo" - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) symlink_path = base_path + "/slink" self.os.symlink(base_path, symlink_path) file_path = base_path + "/slink/beta" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) link_path = base_path + "/slink/gamma" self.os.link(file_path, link_path) - self.assertTrue(self.filesystem.Exists(link_path)) + self.assertTrue(self.filesystem.exists(link_path)) @unittest.skipIf(sys.version_info < (3, 3), 'replace is new in Python 3.3') def testReplaceExistingDirectoryShouldRaiseUnderWindows(self): @@ -1406,8 +1406,8 @@ def testReplaceExistingDirectoryShouldRaiseUnderWindows(self): self.filesystem.is_windows_fs = True old_path = '/foo/bar' new_path = '/foo/baz' - self.filesystem.CreateDirectory(old_path) - self.filesystem.CreateDirectory(new_path) + self.filesystem.create_dir(old_path) + self.filesystem.create_dir(new_path) self.assertRaisesOSError(errno.EACCES, self.os.replace, old_path, new_path) @@ -1416,18 +1416,18 @@ def testRenameToExistingDirectoryUnderPosix(self): self.filesystem.is_windows_fs = False old_path = '/foo/bar' new_path = '/xyzzy' - self.filesystem.CreateDirectory(old_path + '/sub') - self.filesystem.CreateDirectory(new_path) + self.filesystem.create_dir(old_path + '/sub') + self.filesystem.create_dir(new_path) self.os.rename(old_path, new_path) - self.assertTrue(self.filesystem.Exists(new_path + '/sub')) - self.assertFalse(self.filesystem.Exists(old_path)) + self.assertTrue(self.filesystem.exists(new_path + '/sub')) + self.assertFalse(self.filesystem.exists(old_path)) def testRenameFileToExistingDirectoryRaisesUnderPosix(self): self.filesystem.is_windows_fs = False file_path = '/foo/bar/baz' new_path = '/xyzzy' - self.filesystem.CreateFile(file_path) - self.filesystem.CreateDirectory(new_path) + self.filesystem.create_file(file_path) + self.filesystem.create_dir(new_path) self.assertRaisesOSError(errno.EISDIR, self.os.rename, file_path, new_path) @@ -1436,17 +1436,17 @@ def testRenameToExistingDirectoryUnderPosixRaisesIfNotEmpty(self): self.filesystem.is_windows_fs = False old_path = '/foo/bar' new_path = '/foo/baz' - self.filesystem.CreateDirectory(old_path + '/sub') - self.filesystem.CreateDirectory(new_path + '/sub') + self.filesystem.create_dir(old_path + '/sub') + self.filesystem.create_dir(new_path + '/sub') self.assertRaisesOSError(errno.ENOTEMPTY, self.os.rename, old_path, new_path) def testRenameToAnotherDeviceShouldRaise(self): """Renaming to another filesystem device raises OSError.""" - self.filesystem.AddMountPoint('/mount') + self.filesystem.add_mount_point('/mount') old_path = '/foo/bar' new_path = '/mount/bar' - self.filesystem.CreateFile(old_path) + self.filesystem.create_file(old_path) self.assertRaisesOSError(errno.EXDEV, self.os.rename, old_path, new_path) @@ -1456,15 +1456,15 @@ def testRenameToExistentFilePosix(self): directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/plugh_new' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents 1') - self.filesystem.CreateFile(new_file_path, contents='test contents 2') - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.filesystem.create_file(old_file_path, contents='test contents 1') + self.filesystem.create_file(new_file_path, contents='test contents 2') + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.os.rename(old_file_path, new_file_path) - self.assertFalse(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.assertFalse(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.assertEqual('test contents 1', - self.filesystem.GetObject(new_file_path).contents) + self.filesystem.get_object(new_file_path).contents) def testRenameToExistentFileWindows(self): """Renaming a file to a used name raises OSError under Windows.""" @@ -1472,10 +1472,10 @@ def testRenameToExistentFileWindows(self): directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/plugh_new' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents 1') - self.filesystem.CreateFile(new_file_path, contents='test contents 2') - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.filesystem.create_file(old_file_path, contents='test contents 1') + self.filesystem.create_file(new_file_path, contents='test contents 2') + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.assertRaisesOSError(errno.EEXIST, self.os.rename, old_file_path, new_file_path) @@ -1486,30 +1486,30 @@ def testReplaceToExistentFile(self): directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/plugh_new' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents 1') - self.filesystem.CreateFile(new_file_path, contents='test contents 2') - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.filesystem.create_file(old_file_path, contents='test contents 1') + self.filesystem.create_file(new_file_path, contents='test contents 2') + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.os.replace(old_file_path, new_file_path) - self.assertFalse(self.filesystem.Exists(old_file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.assertFalse(self.filesystem.exists(old_file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) self.assertEqual('test contents 1', - self.filesystem.GetObject(new_file_path).contents) + self.filesystem.get_object(new_file_path).contents) def testRenameToNonexistentDir(self): """Can rename a file to a name in a nonexistent dir.""" directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/no_such_path/plugh_new' % directory - self.filesystem.CreateFile(old_file_path, contents='test contents') - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertFalse(self.filesystem.Exists(new_file_path)) + self.filesystem.create_file(old_file_path, contents='test contents') + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertFalse(self.filesystem.exists(new_file_path)) self.assertRaisesOSError(errno.ENOENT, self.os.rename, old_file_path, new_file_path) - self.assertTrue(self.filesystem.Exists(old_file_path)) - self.assertFalse(self.filesystem.Exists(new_file_path)) + self.assertTrue(self.filesystem.exists(old_file_path)) + self.assertFalse(self.filesystem.exists(new_file_path)) self.assertEqual('test contents', - self.filesystem.GetObject(old_file_path).contents) + self.filesystem.get_object(old_file_path).contents) def testRenameNonexistentFileShouldRaiseError(self): """Can't rename a file that doesn't exist.""" @@ -1521,25 +1521,25 @@ def testRenameEmptyDir(self): directory = 'xyzzy' before_dir = '%s/empty' % directory after_dir = '%s/unused' % directory - self.filesystem.CreateDirectory(before_dir) - self.assertTrue(self.filesystem.Exists('%s/.' % before_dir)) - self.assertFalse(self.filesystem.Exists(after_dir)) + self.filesystem.create_dir(before_dir) + self.assertTrue(self.filesystem.exists('%s/.' % before_dir)) + self.assertFalse(self.filesystem.exists(after_dir)) self.os.rename(before_dir, after_dir) - self.assertFalse(self.filesystem.Exists(before_dir)) - self.assertTrue(self.filesystem.Exists('%s/.' % after_dir)) + self.assertFalse(self.filesystem.exists(before_dir)) + self.assertTrue(self.filesystem.exists('%s/.' % after_dir)) def testRenameSymlink(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar/' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) link_path = base_path + "/link" self.os.symlink(base_path, link_path) file_path = link_path + "/file" new_file_path = link_path + "/new" - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.rename(file_path, new_file_path) - self.assertFalse(self.filesystem.Exists(file_path)) - self.assertTrue(self.filesystem.Exists(new_file_path)) + self.assertFalse(self.filesystem.exists(file_path)) + self.assertTrue(self.filesystem.exists(new_file_path)) def testRenameDir(self): """Test a rename of a directory.""" @@ -1548,19 +1548,19 @@ def testRenameDir(self): before_file = '%s/before/file' % directory after_dir = '%s/after' % directory after_file = '%s/after/file' % directory - self.filesystem.CreateDirectory(before_dir) - self.filesystem.CreateFile(before_file, contents='payload') - self.assertTrue(self.filesystem.Exists(before_dir)) - self.assertTrue(self.filesystem.Exists(before_file)) - self.assertFalse(self.filesystem.Exists(after_dir)) - self.assertFalse(self.filesystem.Exists(after_file)) + self.filesystem.create_dir(before_dir) + self.filesystem.create_file(before_file, contents='payload') + self.assertTrue(self.filesystem.exists(before_dir)) + self.assertTrue(self.filesystem.exists(before_file)) + self.assertFalse(self.filesystem.exists(after_dir)) + self.assertFalse(self.filesystem.exists(after_file)) self.os.rename(before_dir, after_dir) - self.assertFalse(self.filesystem.Exists(before_dir)) - self.assertFalse(self.filesystem.Exists(before_file)) - self.assertTrue(self.filesystem.Exists(after_dir)) - self.assertTrue(self.filesystem.Exists(after_file)) + self.assertFalse(self.filesystem.exists(before_dir)) + self.assertFalse(self.filesystem.exists(before_file)) + self.assertTrue(self.filesystem.exists(after_dir)) + self.assertTrue(self.filesystem.exists(after_file)) self.assertEqual('payload', - self.filesystem.GetObject(after_file).contents) + self.filesystem.get_object(after_file).contents) def testRenamePreservesStat(self): """Test if rename preserves mtime.""" @@ -1568,14 +1568,14 @@ def testRenamePreservesStat(self): directory = 'xyzzy' old_file_path = '%s/plugh_old' % directory new_file_path = '%s/plugh_new' % directory - old_file = self.filesystem.CreateFile(old_file_path) - old_file.SetMTime(old_file.st_mtime - 3600) + old_file = self.filesystem.create_file(old_file_path) + old_file.st_mtime = old_file.st_mtime - 3600 self.os.chown(old_file_path, 200, 200) self.os.chmod(old_file_path, 0o222) - new_file = self.filesystem.CreateFile(new_file_path) + new_file = self.filesystem.create_file(new_file_path) self.assertNotEqual(new_file.st_mtime, old_file.st_mtime) self.os.rename(old_file_path, new_file_path) - new_file = self.filesystem.GetObject(new_file_path) + new_file = self.filesystem.get_object(new_file_path) self.assertEqual(new_file.st_mtime, old_file.st_mtime) self.assertEqual(new_file.st_mode, old_file.st_mode) self.assertEqual(new_file.st_uid, old_file.st_uid) @@ -1586,100 +1586,100 @@ def testRenameSameFilenames(self): directory = 'xyzzy' file_contents = 'Spam eggs' file_path = '%s/eggs' % directory - self.filesystem.CreateFile(file_path, contents=file_contents) + self.filesystem.create_file(file_path, contents=file_contents) self.os.rename(file_path, file_path) self.assertEqual(file_contents, - self.filesystem.GetObject(file_path).contents) + self.filesystem.get_object(file_path).contents) def testRmdir(self): """Can remove a directory.""" directory = 'xyzzy' sub_dir = '/xyzzy/abccd' other_dir = '/xyzzy/cdeed' - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.os.rmdir(directory) - self.assertFalse(self.filesystem.Exists(directory)) - self.filesystem.CreateDirectory(sub_dir) - self.filesystem.CreateDirectory(other_dir) + self.assertFalse(self.filesystem.exists(directory)) + self.filesystem.create_dir(sub_dir) + self.filesystem.create_dir(other_dir) self.os.chdir(sub_dir) self.os.rmdir('../cdeed') - self.assertFalse(self.filesystem.Exists(other_dir)) + self.assertFalse(self.filesystem.exists(other_dir)) self.os.chdir('..') self.os.rmdir('abccd') - self.assertFalse(self.filesystem.Exists(sub_dir)) + self.assertFalse(self.filesystem.exists(sub_dir)) def testRmdirRaisesIfNotEmpty(self): """Raises an exception if the target directory is not empty.""" directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.ENOTEMPTY, self.os.rmdir, directory) def testRmdirRaisesIfNotDirectory(self): """Raises an exception if the target is not a directory.""" directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.ENOTDIR, self.os.rmdir, file_path) self.assertRaisesOSError(errno.EINVAL, self.os.rmdir, '.') def testRmdirRaisesIfNotExist(self): """Raises an exception if the target does not exist.""" directory = 'xyzzy' - self.assertFalse(self.filesystem.Exists(directory)) + self.assertFalse(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.ENOENT, self.os.rmdir, directory) def testRmdirViaSymlink(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' dir_path = base_path + '/alpha' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) link_path = base_path + '/beta' self.os.symlink(base_path, link_path) self.os.rmdir(link_path + '/alpha') - self.assertFalse(self.filesystem.Exists(dir_path)) + self.assertFalse(self.filesystem.exists(dir_path)) def RemovedirsCheck(self, directory): - self.assertTrue(self.filesystem.Exists(directory)) + self.assertTrue(self.filesystem.exists(directory)) self.os.removedirs(directory) - return not self.filesystem.Exists(directory) + return not self.filesystem.exists(directory) def testRemovedirs(self): data = ['test1', 'test1/test2', 'test1/extra', 'test1/test2/test3'] for directory in data: - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.ENOTEMPTY, self.RemovedirsCheck, data[0]) self.assertRaisesOSError(errno.ENOTEMPTY, self.RemovedirsCheck, data[1]) self.assertTrue(self.RemovedirsCheck(data[3])) - self.assertTrue(self.filesystem.Exists(data[0])) - self.assertFalse(self.filesystem.Exists(data[1])) - self.assertTrue(self.filesystem.Exists(data[2])) + self.assertTrue(self.filesystem.exists(data[0])) + self.assertFalse(self.filesystem.exists(data[1])) + self.assertTrue(self.filesystem.exists(data[2])) # Should raise because '/test1/extra' is all that is left, and # removedirs('/test1/extra') will eventually try to rmdir('/'). self.assertRaisesOSError(errno.EBUSY, self.RemovedirsCheck, data[2]) # However, it will still delete '/test1') in the process. - self.assertFalse(self.filesystem.Exists(data[0])) + self.assertFalse(self.filesystem.exists(data[0])) - self.filesystem.CreateDirectory('test1/test2') + self.filesystem.create_dir('test1/test2') # Add this to the root directory to avoid raising an exception. - self.filesystem.CreateDirectory('test3') + self.filesystem.create_dir('test3') self.assertTrue(self.RemovedirsCheck('test1/test2')) - self.assertFalse(self.filesystem.Exists('test1/test2')) - self.assertFalse(self.filesystem.Exists('test1')) + self.assertFalse(self.filesystem.exists('test1/test2')) + self.assertFalse(self.filesystem.exists('test1')) def testRemovedirsRaisesIfRemovingRoot(self): """Raises exception if asked to remove '/'.""" directory = '/' - self.assertTrue(self.filesystem.Exists(directory)) + self.assertTrue(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.EBUSY, self.os.removedirs, directory) def testRemovedirsRaisesIfCascadeRemovingRoot(self): @@ -1688,30 +1688,30 @@ def testRemovedirsRaisesIfCascadeRemovingRoot(self): All of other directories should still be removed, though. """ directory = '/foo/bar/' - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.EBUSY, self.os.removedirs, directory) head, unused_tail = self.os.path.split(directory) while head != '/': - self.assertFalse(self.filesystem.Exists(directory)) + self.assertFalse(self.filesystem.exists(directory)) head, unused_tail = self.os.path.split(head) def testRemovedirsWithTrailingSlash(self): """removedirs works on directory names with trailing slashes.""" # separate this case from the removing-root-directory case - self.filesystem.CreateDirectory('/baz') + self.filesystem.create_dir('/baz') directory = '/foo/bar/' - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.os.removedirs(directory) - self.assertFalse(self.filesystem.Exists(directory)) + self.assertFalse(self.filesystem.exists(directory)) def testRemoveDirsWithTopSymlinkFails(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' dir_path = base_path + "/dir" dir_link = base_path + "/dir_link" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, dir_link) self.assertRaisesOSError(errno.ENOTDIR, self.os.removedirs, dir_link) @@ -1720,36 +1720,36 @@ def testRemoveDirsWithNonTopSymlinkSucceeds(self): base_path = '/foo/bar' dir_path = base_path + "/dir" dir_link = base_path + "/dir_link" - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, dir_link) dir_in_dir = dir_link + "/dir2" - self.filesystem.CreateDirectory(dir_in_dir) + self.filesystem.create_dir(dir_in_dir) self.os.removedirs(dir_in_dir) - self.assertFalse(self.filesystem.Exists(dir_in_dir)) + self.assertFalse(self.filesystem.exists(dir_in_dir)) # ensure that the symlink is not removed - self.assertTrue(self.filesystem.Exists(dir_link)) + self.assertTrue(self.filesystem.exists(dir_link)) def testMkdir(self): """mkdir can create a relative directory.""" directory = 'xyzzy' - self.assertFalse(self.filesystem.Exists(directory)) + self.assertFalse(self.filesystem.exists(directory)) self.os.mkdir(directory) - self.assertTrue(self.filesystem.Exists('/%s' % directory)) + self.assertTrue(self.filesystem.exists('/%s' % directory)) self.os.chdir(directory) self.os.mkdir(directory) self.assertTrue( - self.filesystem.Exists('/%s/%s' % (directory, directory))) + self.filesystem.exists('/%s/%s' % (directory, directory))) self.os.chdir(directory) self.os.mkdir('../abccb') - self.assertTrue(self.filesystem.Exists('/%s/abccb' % directory)) + self.assertTrue(self.filesystem.exists('/%s/abccb' % directory)) def testMkdirWithTrailingSlash(self): """mkdir can create a directory named with a trailing slash.""" directory = '/foo/' - self.assertFalse(self.filesystem.Exists(directory)) + self.assertFalse(self.filesystem.exists(directory)) self.os.mkdir(directory) - self.assertTrue(self.filesystem.Exists(directory)) - self.assertTrue(self.filesystem.Exists('/foo')) + self.assertTrue(self.filesystem.exists(directory)) + self.assertTrue(self.filesystem.exists('/foo')) def testMkdirRaisesIfEmptyDirectoryName(self): """mkdir raises exeption if creating directory named ''.""" @@ -1760,7 +1760,7 @@ def testMkdirRaisesIfNoParent(self): """mkdir raises exception if parent directory does not exist.""" parent = 'xyzzy' directory = '%s/foo' % (parent,) - self.assertFalse(self.filesystem.Exists(parent)) + self.assertFalse(self.filesystem.exists(parent)) self.assertRaisesOSError(errno.ENOENT, self.os.mkdir, directory) def testMkdirRaisesOnSymlinkInPosix(self): @@ -1768,7 +1768,7 @@ def testMkdirRaisesOnSymlinkInPosix(self): base_path = '/foo/bar' link_path = base_path + '/link_to_dir' dir_path = base_path + '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, link_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.rmdir, link_path) @@ -1779,32 +1779,32 @@ def testMkdirRemovesSymlinkInWindows(self): base_path = '/foo/bar' link_path = base_path + '/link_to_dir' dir_path = base_path + '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.os.symlink(dir_path, link_path) self.os.rmdir(link_path) - self.assertFalse(self.filesystem.Exists(link_path)) - self.assertTrue(self.filesystem.Exists(dir_path)) + self.assertFalse(self.filesystem.exists(link_path)) + self.assertTrue(self.filesystem.exists(dir_path)) def testMkdirRaisesIfDirectoryExists(self): """mkdir raises exception if directory already exists.""" directory = 'xyzzy' - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, directory) def testMkdirRaisesIfFileExists(self): """mkdir raises exception if name already exists as a file.""" directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, file_path) def testMkdirRaisesIfParentIsFile(self): """mkdir raises exception if name already exists as a file.""" directory = 'xyzzy' file_path = '%s/plugh' % directory - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.ENOTDIR, self.os.mkdir, file_path + '/ff') @@ -1813,7 +1813,7 @@ def testMkdirRaisesWithSlashDot(self): self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, '/.') directory = '/xyzzy/.' self.assertRaisesOSError(errno.ENOENT, self.os.mkdir, directory) - self.filesystem.CreateDirectory('/xyzzy') + self.filesystem.create_dir('/xyzzy') self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, directory) def testMkdirRaisesWithDoubleDots(self): @@ -1821,13 +1821,13 @@ def testMkdirRaisesWithDoubleDots(self): self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, '/..') directory = '/xyzzy/dir1/dir2/../../dir3' self.assertRaisesOSError(errno.ENOENT, self.os.mkdir, directory) - self.filesystem.CreateDirectory('/xyzzy') + self.filesystem.create_dir('/xyzzy') self.assertRaisesOSError(errno.ENOENT, self.os.mkdir, directory) - self.filesystem.CreateDirectory('/xyzzy/dir1') + self.filesystem.create_dir('/xyzzy/dir1') self.assertRaisesOSError(errno.ENOENT, self.os.mkdir, directory) - self.filesystem.CreateDirectory('/xyzzy/dir1/dir2') + self.filesystem.create_dir('/xyzzy/dir1/dir2') self.os.mkdir(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.assertTrue(self.filesystem.exists(directory)) directory = '/xyzzy/dir1/..' self.assertRaisesOSError(errno.EEXIST, self.os.mkdir, directory) @@ -1846,27 +1846,27 @@ def testMkdirRaisesIfParentIsReadOnly(self): def testMkdirWithWithSymlinkParent(self): self.filesystem.is_windows_fs = False dir_path = '/foo/bar' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) link_path = '/foo/link' self.os.symlink(dir_path, link_path) new_dir = link_path + '/new_dir' self.os.mkdir(new_dir) - self.assertTrue(self.filesystem.Exists(new_dir)) + self.assertTrue(self.filesystem.exists(new_dir)) def testMakedirs(self): """makedirs can create a directory even if parent does not exist.""" parent = 'xyzzy' directory = '%s/foo' % (parent,) - self.assertFalse(self.filesystem.Exists(parent)) + self.assertFalse(self.filesystem.exists(parent)) self.os.makedirs(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.assertTrue(self.filesystem.exists(directory)) def testMakedirsRaisesIfParentIsFile(self): """makedirs raises exception if a parent component exists as a file.""" file_path = 'xyzzy' directory = '%s/plugh' % file_path - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.ENOTDIR, self.os.makedirs, directory) def testMakedirsRaisesIfParentIsBrokenLink(self): @@ -1880,7 +1880,7 @@ def testMakedirsRaisesIfParentIsBrokenLink(self): 'Links are not supported under Windows before Python 3.3') def testMakedirsRaisesIfParentIsLoopingLink(self): dir_path = '/foo/bar' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) link_path = dir_path + "/link" link_target = link_path + "/link" self.os.symlink(link_target, link_path) @@ -1889,12 +1889,12 @@ def testMakedirsRaisesIfParentIsLoopingLink(self): def testMakedirsIfParentIsSymlink(self): self.filesystem.is_windows_fs = False base_dir = "/foo/bar" - self.filesystem.CreateDirectory(base_dir) + self.filesystem.create_dir(base_dir) link_dir = base_dir + "/linked" self.os.symlink(base_dir, link_dir) new_dir = link_dir + '/f' self.os.makedirs(new_dir) - self.assertTrue(self.filesystem.Exists(new_dir)) + self.assertTrue(self.filesystem.exists(new_dir)) def testMakedirsRaisesIfAccessDenied(self): """makedirs raises exception if access denied.""" @@ -1913,12 +1913,12 @@ def testMakedirsRaisesIfAccessDenied(self): def testMakedirsExistOk(self): """makedirs uses the exist_ok argument""" directory = 'xyzzy/foo' - self.filesystem.CreateDirectory(directory) - self.assertTrue(self.filesystem.Exists(directory)) + self.filesystem.create_dir(directory) + self.assertTrue(self.filesystem.exists(directory)) self.assertRaisesOSError(errno.EEXIST, self.os.makedirs, directory) self.os.makedirs(directory, exist_ok=True) - self.assertTrue(self.filesystem.Exists(directory)) + self.assertTrue(self.filesystem.exists(directory)) # test fsync and fdatasync @@ -1940,8 +1940,8 @@ def testFsyncPass(self): # setup fake_open = fake_filesystem.FakeFileOpen(self.filesystem) test_file_path = 'test_file' - self.filesystem.CreateFile(test_file_path, - contents='dummy file contents') + self.filesystem.create_file(test_file_path, + contents='dummy file contents') test_file = fake_open(test_file_path, 'r') test_fd = test_file.fileno() # Test that this doesn't raise anything @@ -1953,8 +1953,8 @@ def testFdatasyncPass(self): # setup fake_open = fake_filesystem.FakeFileOpen(self.filesystem) test_file_path = 'test_file' - self.filesystem.CreateFile(test_file_path, - contents='dummy file contents') + self.filesystem.create_file(test_file_path, + contents='dummy file contents') test_file = fake_open(test_file_path, 'r') test_fd = test_file.fileno() # Test that this doesn't raise anything @@ -2009,7 +2009,7 @@ def testAccessSymlink(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.chmod(link_path, 0o400) # test file @@ -2037,7 +2037,7 @@ def testAccessSymlink(self): def testAccessNonExistentFile(self): # set up path = '/non/existent/file' - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) # actual tests self.assertFalse(self.os.access(path, self.os.F_OK)) self.assertFalse(self.os.access(path, self.os.R_OK)) @@ -2075,7 +2075,7 @@ def testChmodFollowSymlink(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.chmod(link_path, 0o6543) st = self.os.stat(link_path) @@ -2089,7 +2089,7 @@ def testChmodNoFollowSymlink(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.chmod(link_path, 0o6543, follow_symlinks=False) st = self.os.stat(link_path) @@ -2103,7 +2103,7 @@ def testLchmod(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.lchmod(link_path, 0o6543) st = self.os.stat(link_path) @@ -2125,7 +2125,7 @@ def testChmodDir(self): def testChmodNonExistent(self): # set up path = '/non/existent/file' - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) # actual tests try: # Use try-catch to check exception attributes. @@ -2138,7 +2138,7 @@ def testChmodNonExistent(self): def testChownExistingFile(self): # set up file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) # first set it make sure it's set self.os.chown(file_path, 100, 101) st = self.os.stat(file_path) @@ -2160,7 +2160,7 @@ def testChownExistingFile(self): def testChownUsesOpenFdAsPath(self): self.assertRaisesOSError(errno.EBADF, self.os.chown, 5, 100, 101) file_path = '/foo/bar' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) with FakeFileOpen(self.filesystem)(file_path) as f: self.os.chown(f.filedes, 100, 101) @@ -2171,9 +2171,9 @@ def testChownUsesOpenFdAsPath(self): 'follow_symlinks new in Python 3.3') def testChownFollowSymlink(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, file_path) + self.filesystem.symlink(link_path, file_path) self.os.chown(link_path, 100, 101) st = self.os.stat(link_path) @@ -2187,9 +2187,9 @@ def testChownFollowSymlink(self): 'follow_symlinks new in Python 3.3') def testChownNoFollowSymlink(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, file_path) + self.filesystem.symlink(link_path, file_path) self.os.chown(link_path, 100, 101, follow_symlinks=False) st = self.os.stat(link_path) @@ -2202,13 +2202,13 @@ def testChownNoFollowSymlink(self): def testChownBadArguments(self): """os.chown() with bad args (Issue #30)""" file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaises(TypeError, self.os.chown, file_path, 'username', -1) self.assertRaises(TypeError, self.os.chown, file_path, -1, 'groupname') def testChownNonexistingFileShouldRaiseOsError(self): file_path = 'some_file' - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) self.assertRaisesOSError(errno.ENOENT, self.os.chown, file_path, 100, 100) @@ -2217,13 +2217,13 @@ def testClassifyDirectoryContents(self): root_directory = '/foo' test_directories = ['bar1', 'baz2'] test_files = ['baz1', 'bar2', 'baz3'] - self.filesystem.CreateDirectory(root_directory) + self.filesystem.create_dir(root_directory) for directory in test_directories: directory = self.os.path.join(root_directory, directory) - self.filesystem.CreateDirectory(directory) + self.filesystem.create_dir(directory) for test_file in test_files: test_file = self.os.path.join(root_directory, test_file) - self.filesystem.CreateFile(test_file) + self.filesystem.create_file(test_file) test_directories.sort() test_files.sort() @@ -2238,15 +2238,15 @@ def testClassifyDirectoryContents(self): def testClassifyDoesNotHideExceptions(self): """_ClassifyDirectoryContents should not hide exceptions.""" directory = '/foo' - self.assertEqual(False, self.filesystem.Exists(directory)) - self.assertRaisesOSError(errno.ENOENT, - self.os._ClassifyDirectoryContents, directory) + self.assertEqual(False, self.filesystem.exists(directory)) + self.assertRaisesOSError(errno.ENOENT, self.os._classify_dir_contents, + directory) def testMkNodeCanCreateAFile(self): filename = 'foo' - self.assertFalse(self.filesystem.Exists(filename)) + self.assertFalse(self.filesystem.exists(filename)) self.os.mknod(filename) - self.assertTrue(self.filesystem.Exists(filename)) + self.assertTrue(self.filesystem.exists(filename)) def testMkNodeRaisesIfEmptyFileName(self): filename = '' @@ -2255,13 +2255,13 @@ def testMkNodeRaisesIfEmptyFileName(self): def testMkNodeRaisesIfParentDirDoesntExist(self): parent = 'xyzzy' filename = '%s/foo' % (parent,) - self.assertFalse(self.filesystem.Exists(parent)) + self.assertFalse(self.filesystem.exists(parent)) self.assertRaisesOSError(errno.ENOTDIR, self.os.mknod, filename) def testMkNodeRaisesIfFileExists(self): filename = '/tmp/foo' - self.filesystem.CreateFile(filename) - self.assertTrue(self.filesystem.Exists(filename)) + self.filesystem.create_file(filename) + self.assertTrue(self.filesystem.exists(filename)) self.assertRaisesOSError(errno.EEXIST, self.os.mknod, filename) def testMkNodeRaisesIfFilenameIsDot(self): @@ -2274,8 +2274,8 @@ def testMkNodeRaisesIfFilenameIsDoubleDot(self): def testMknodEmptyTailForExistingFileRaises(self): filename = '/tmp/foo' - self.filesystem.CreateFile(filename) - self.assertTrue(self.filesystem.Exists(filename)) + self.filesystem.create_file(filename) + self.assertTrue(self.filesystem.exists(filename)) self.assertRaisesOSError(errno.EEXIST, self.os.mknod, filename) def testMknodEmptyTailForNonexistentFileRaises(self): @@ -2293,8 +2293,8 @@ def testMknodeRaisesIfUnsupportedOptions(self): def testMknodeRaisesIfParentIsNotADirectory(self): filename1 = '/tmp/foo' - self.filesystem.CreateFile(filename1) - self.assertTrue(self.filesystem.Exists(filename1)) + self.filesystem.create_file(filename1) + self.assertTrue(self.filesystem.exists(filename1)) filename2 = '/tmp/foo/bar' self.assertRaisesOSError(errno.ENOTDIR, self.os.mknod, filename2) @@ -2302,18 +2302,18 @@ def testMknodeRaisesIfParentIsNotADirectory(self): 'Links are not supported under Windows before Python 3.3') def testSymlink(self): file_path = 'foo/bar/baz' - self.filesystem.CreateDirectory('foo/bar') + self.filesystem.create_dir('foo/bar') self.os.symlink('bogus', file_path) self.assertTrue(self.os.path.lexists(file_path)) self.assertFalse(self.os.path.exists(file_path)) - self.filesystem.CreateFile('foo/bar/bogus') + self.filesystem.create_file('foo/bar/bogus') self.assertTrue(self.os.path.lexists(file_path)) self.assertTrue(self.os.path.exists(file_path)) def testSymlinkOnNonexistingPathRaises(self): self.filesystem.is_windows_fs = False base_path = '/foo' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) dir_path = base_path + "/bar" link_path = dir_path + "/bar" self.assertRaisesOSError(errno.ENOENT, self.os.symlink, link_path, @@ -2340,7 +2340,7 @@ def testLinkDelete(self): file2_path = 'test_file2' contents1 = 'abcdef' # Create file - self.filesystem.CreateFile(file1_path, contents=contents1) + self.filesystem.create_file(file1_path, contents=contents1) # link to second file self.os.link(file1_path, file2_path) # delete first file @@ -2360,7 +2360,7 @@ def testLinkUpdate(self): contents1 = 'abcdef' contents2 = 'ghijkl' # Create file and link - self.filesystem.CreateFile(file1_path, contents=contents1) + self.filesystem.create_file(file1_path, contents=contents1) self.os.link(file1_path, file2_path) # assert that the second file contains contents1 with fake_open(file2_path) as f: @@ -2381,7 +2381,7 @@ def testLinkNonExistentParent(self): breaking_link_path = 'nonexistent/test_file2' contents1 = 'abcdef' # Create file and link - self.filesystem.CreateFile(file1_path, contents=contents1) + self.filesystem.create_file(file1_path, contents=contents1) # trying to create a link under a non-existent directory should fail self.assertRaisesOSError(errno.ENOENT, @@ -2391,7 +2391,7 @@ def testLinkNonExistentParent(self): 'Links are not supported under Windows before Python 3.3') def testLinkIsExistingFile(self): file_path = '/foo/bar' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesOSError(errno.EEXIST, self.os.link, file_path, file_path) @@ -2400,7 +2400,7 @@ def testLinkIsExistingFile(self): def testLinkTargetIsDir(self): dir_path = '/foo/bar' link_path = dir_path + '/link' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.filesystem.is_windows_fs = True self.assertRaisesOSError(errno.EACCES, self.os.link, dir_path, link_path) @@ -2415,7 +2415,7 @@ def testLinkCount1(self): file1_path = 'test_file1' file2_path = 'test_file2' file3_path = 'test_file3' - self.filesystem.CreateFile(file1_path) + self.filesystem.create_file(file1_path) # initial link count should be one self.assertEqual(self.os.stat(file1_path).st_nlink, 1) self.os.link(file1_path, file2_path) @@ -2436,14 +2436,14 @@ def testLinkCount1(self): self.assertEqual(self.os.stat(file2_path).st_nlink, 1) def testNLinkForDirectories(self): - self.filesystem.CreateDirectory('/foo/bar') - self.filesystem.CreateFile('/foo/baz') - self.assertEqual(2, self.filesystem.GetObject('/foo/bar').st_nlink) - self.assertEqual(4, self.filesystem.GetObject('/foo').st_nlink) - self.filesystem.CreateFile('/foo/baz2') - self.assertEqual(5, self.filesystem.GetObject('/foo').st_nlink) + self.filesystem.create_dir('/foo/bar') + self.filesystem.create_file('/foo/baz') + self.assertEqual(2, self.filesystem.get_object('/foo/bar').st_nlink) + self.assertEqual(4, self.filesystem.get_object('/foo').st_nlink) + self.filesystem.create_file('/foo/baz2') + self.assertEqual(5, self.filesystem.get_object('/foo').st_nlink) - self.filesystem.CreateFile('/foo/bar/baz') + self.filesystem.create_file('/foo/bar/baz') def testUMask(self): umask = os.umask(0o22) @@ -2507,8 +2507,8 @@ def setDummyTime(self, start): def testChmodStCtime(self): # set up file_path = 'some_file' - self.filesystem.CreateFile(file_path) - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path) + self.assertTrue(self.filesystem.exists(file_path)) self.dummy_time.start() st = self.os.stat(file_path) @@ -2633,7 +2633,7 @@ def testUtimeFollowSymlinks(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.utime(link_path, (1, 2)) st = self.os.stat(link_path) @@ -2646,7 +2646,7 @@ def testUtimeNoFollowSymlinks(self): path = '/some_file' self._CreateTestFile(path) link_path = '/link_to_some_file' - self.filesystem.CreateLink(link_path, path) + self.filesystem.symlink(link_path, path) self.os.utime(link_path, (1, 2), follow_symlinks=False) st = self.os.stat(link_path) @@ -2658,7 +2658,7 @@ def testUtimeNoFollowSymlinks(self): def testUtimeNonExistent(self): path = '/non/existent/file' - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) self.assertRaisesOSError(errno.ENOENT, self.os.utime, path, (1, 2)) def testUtimeInvalidTimesArgRaises(self): @@ -2687,7 +2687,7 @@ def testUtimeSetsSpecifiedTimeInNs(self): @unittest.skipIf(sys.version_info < (3, 3), 'ns new in Python 3.3') def testUtimeIncorrectNsArgumentRaises(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaises(TypeError, self.os.utime, file_path, ns=(200000000)) self.assertRaises(TypeError, self.os.utime, file_path, ns=('a', 'b')) @@ -2713,8 +2713,8 @@ class FakeOsModuleLowLevelFileOpTest(FakeOsModuleTestBase): def testOpenReadOnly(self): file_path = 'file1' - self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_RDONLY) self.assertEqual(0, file_des) @@ -2724,8 +2724,8 @@ def testOpenReadOnly(self): def testOpenReadOnlyWriteZeroBytes(self): # under Windows, writing an empty string to a read only file is not an error file_path = 'file1' - self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_RDONLY) self.filesystem.is_windows_fs = False @@ -2735,8 +2735,8 @@ def testOpenReadOnlyWriteZeroBytes(self): def testOpenWriteOnly(self): file_path = 'file1' - file_obj = self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + file_obj = self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_WRONLY) self.assertEqual(0, file_des) @@ -2745,8 +2745,8 @@ def testOpenWriteOnly(self): def testOpenWriteOnlyRaisesOnRead(self): file_path = 'file1' - self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_WRONLY) self.assertRaisesOSError(errno.EBADF, self.os.read, file_des, 5) @@ -2769,8 +2769,8 @@ def testOpenWriteOnlyReadZeroBytes(self): def testOpenReadWrite(self): file_path = 'file1' - file_obj = self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + file_obj = self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_RDWR) self.assertEqual(0, file_des) @@ -2813,15 +2813,15 @@ def testExclusiveOpenRaisesWithoutCreateMode(self): def testOpenRaisesIfParentDoesNotExist(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) path1 = base_path + '/alpha/alpha' self.assertRaisesOSError(errno.ENOENT, self.os.open, path1, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) def testOpenTruncate(self): file_path = 'file1' - file_obj = self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + file_obj = self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_RDWR | os.O_TRUNC) self.assertEqual(0, file_des) @@ -2834,14 +2834,14 @@ def testOpenTruncate(self): def testTempFile(self): file_name = 'foo' fd = self.os.open(file_name, os.O_CREAT | os.O_RDWR | os.O_TEMPORARY) - self.assertTrue(self.filesystem.Exists(file_name)) + self.assertTrue(self.filesystem.exists(file_name)) self.os.close(fd) - self.assertFalse(self.filesystem.Exists(file_name)) + self.assertFalse(self.filesystem.exists(file_name)) def testOpenAppend(self): file_path = 'file1' - file_obj = self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + file_obj = self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) file_des = self.os.open(file_path, os.O_WRONLY | os.O_APPEND) self.assertEqual(0, file_des) @@ -2854,13 +2854,13 @@ def testOpenCreate(self): self.assertEqual(0, file_des) self.assertTrue(self.os.path.exists(file_path)) self.assertEqual(4, self.os.write(file_des, b'test')) - file_obj = self.filesystem.GetObject(file_path) + file_obj = self.filesystem.get_object(file_path) self.assertEqual(b'test', file_obj.byte_contents) def testCanReadAfterCreateExclusive(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) path1 = base_path + "/alpha" fd0 = self.os.open(path1, os.O_CREAT | os.O_EXCL) self.assertEqual(b'', self.os.read(fd0, 0)) @@ -2887,8 +2887,8 @@ def testOpenExclusive(self): 'Exclusive mode new in Python 3.3') def testOpenExclusiveRaisesIfFileExists(self): file_path = 'file1' - self.filesystem.CreateFile(file_path, contents=b'contents', - st_mode=(stat.S_IFREG | 0o666)) + self.filesystem.create_file(file_path, contents=b'contents', + st_mode=(stat.S_IFREG | 0o666)) self.assertRaisesIOError(errno.EEXIST, self.os.open, file_path, os.O_RDWR | os.O_EXCL | os.O_CREAT) self.assertRaisesIOError(errno.EEXIST, self.os.open, file_path, @@ -2898,7 +2898,7 @@ def testOpenExclusiveRaisesIfFileExists(self): 'Exclusive mode new in Python 3.3') def testOpenExclusiveRaisesIfSymlinkExists(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) link_path = base_path + '/link' link_target = base_path + '/link_target' self.os.symlink(link_target, link_path) @@ -2908,7 +2908,7 @@ def testOpenExclusiveRaisesIfSymlinkExists(self): def testOpenDirectoryRaisesUnderWindows(self): self.filesystem.is_windows_fs = True dir_path = '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.assertRaisesOSError(errno.EPERM, self.os.open, dir_path, os.O_RDONLY) self.assertRaisesOSError(errno.EPERM, self.os.open, dir_path, @@ -2919,7 +2919,7 @@ def testOpenDirectoryRaisesUnderWindows(self): def testOpenDirectoryForWritingRaisesUnderPosix(self): self.filesystem.is_windows_fs = False dir_path = '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) self.assertRaisesOSError(errno.EISDIR, self.os.open, dir_path, os.O_WRONLY) self.assertRaisesOSError(errno.EISDIR, self.os.open, dir_path, @@ -2928,14 +2928,14 @@ def testOpenDirectoryForWritingRaisesUnderPosix(self): def testOpenDirectoryReadOnlyUnderPosix(self): self.filesystem.is_windows_fs = False dir_path = '/dir' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) file_des = self.os.open(dir_path, os.O_RDONLY) self.assertEqual(0, file_des) def testOpenModePosix(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + "/baz" fd0 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) stat0 = self.os.fstat(fd0) @@ -2946,7 +2946,7 @@ def testOpenModePosix(self): def testOpenModeWindows(self): self.filesystem.is_windows_fs = True base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + "/baz" fd0 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) stat0 = self.os.fstat(fd0) @@ -2954,7 +2954,7 @@ def testOpenModeWindows(self): def testWriteRead(self): file_path = 'file1' - self.filesystem.CreateFile(file_path, contents=b'orig contents') + self.filesystem.create_file(file_path, contents=b'orig contents') new_contents = b'1234567890abcdef' fake_open = fake_filesystem.FakeFileOpen(self.filesystem) @@ -2964,7 +2964,7 @@ def testWriteRead(self): self.assertEqual(len(new_contents), self.os.write(fileno, new_contents)) self.assertEqual(new_contents, - self.filesystem.GetObject(file_path).byte_contents) + self.filesystem.get_object(file_path).byte_contents) self.os.close(fileno) fh = fake_open(file_path, 'rb') @@ -2982,7 +2982,7 @@ def testWriteRead(self): def testWriteFromDifferentFDs(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + "/baz" fd0 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) fd1 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) @@ -2990,11 +2990,11 @@ def testWriteFromDifferentFDs(self): self.os.write(fd1, b'bb') self.assertEqual(4, self.os.path.getsize(file_path)) self.assertEqual(b'bbaa', - self.filesystem.GetObject(file_path).byte_contents) + self.filesystem.get_object(file_path).byte_contents) def testWriteFromDifferentFDsWithAppend(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + '/baz' fd0 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) fd1 = self.os.open(file_path, os.O_WRONLY | os.O_APPEND) @@ -3002,19 +3002,19 @@ def testWriteFromDifferentFDsWithAppend(self): self.os.write(fd1, b'bbb') self.assertEqual(6, self.os.path.getsize(file_path)) self.assertEqual(b'aaabbb', - self.filesystem.GetObject(file_path).byte_contents) + self.filesystem.get_object(file_path).byte_contents) def testReadOnlyReadAfterWrite(self): self.filesystem.is_windows_fs = False file_path = '/foo/bar/baz' - self.filesystem.CreateFile(file_path, contents=b'test') + self.filesystem.create_file(file_path, contents=b'test') fd = self.os.open(file_path, os.O_CREAT) self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) self.assertEqual(b'', self.os.read(fd, 0)) def testReadAfterClosingWriteDescriptor(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + '/baz' fd0 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) fd1 = self.os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC) @@ -3052,10 +3052,10 @@ def GetErrno(self): def testWalkTopDown(self): """Walk down ordering is correct.""" - self.filesystem.CreateFile('foo/1.txt') - self.filesystem.CreateFile('foo/bar1/2.txt') - self.filesystem.CreateFile('foo/bar1/baz/3.txt') - self.filesystem.CreateFile('foo/bar2/4.txt') + self.filesystem.create_file('foo/1.txt') + self.filesystem.create_file('foo/bar1/2.txt') + self.filesystem.create_file('foo/bar1/baz/3.txt') + self.filesystem.create_file('foo/bar2/4.txt') expected = [ ('foo', ['bar1', 'bar2'], ['1.txt']), ('foo/bar1', ['baz'], ['2.txt']), @@ -3066,10 +3066,10 @@ def testWalkTopDown(self): def testWalkBottomUp(self): """Walk up ordering is correct.""" - self.filesystem.CreateFile('foo/bar1/baz/1.txt') - self.filesystem.CreateFile('foo/bar1/2.txt') - self.filesystem.CreateFile('foo/bar2/3.txt') - self.filesystem.CreateFile('foo/4.txt') + self.filesystem.create_file('foo/bar1/baz/1.txt') + self.filesystem.create_file('foo/bar1/2.txt') + self.filesystem.create_file('foo/bar2/3.txt') + self.filesystem.create_file('foo/4.txt') expected = [ ('foo/bar1/baz', [], ['1.txt']), @@ -3082,14 +3082,14 @@ def testWalkBottomUp(self): def testWalkRaisesIfNonExistent(self): """Raises an exception when attempting to walk non-existent directory.""" directory = '/foo/bar' - self.assertEqual(False, self.filesystem.Exists(directory)) + self.assertEqual(False, self.filesystem.exists(directory)) generator = self.os.walk(directory) self.assertRaises(StopIteration, next, generator) def testWalkRaisesIfNotDirectory(self): """Raises an exception when attempting to walk a non-directory.""" filename = '/foo/bar' - self.filesystem.CreateFile(filename) + self.filesystem.create_file(filename) generator = self.os.walk(filename) self.assertRaises(StopIteration, next, generator) @@ -3097,7 +3097,7 @@ def testWalkCallsOnErrorIfNonExistent(self): """Calls onerror with correct errno when walking non-existent directory.""" self.ResetErrno() directory = '/foo/bar' - self.assertEqual(False, self.filesystem.Exists(directory)) + self.assertEqual(False, self.filesystem.exists(directory)) # Calling os.walk on a non-existent directory should trigger a call to the # onerror method. We do not actually care what, if anything, is returned. for unused_entry in self.os.walk(directory, onerror=self.StoreErrno): @@ -3108,8 +3108,8 @@ def testWalkCallsOnErrorIfNotDirectory(self): """Calls onerror with correct errno when walking non-directory.""" self.ResetErrno() filename = '/foo/bar' - self.filesystem.CreateFile(filename) - self.assertEqual(True, self.filesystem.Exists(filename)) + self.filesystem.create_file(filename) + self.assertEqual(True, self.filesystem.exists(filename)) # Calling os.walk on a file should trigger a call to the onerror method. # We do not actually care what, if anything, is returned. for unused_entry in self.os.walk(filename, onerror=self.StoreErrno): @@ -3121,11 +3121,11 @@ def testWalkSkipsRemovedDirectories(self): root = '/foo' visit = 'visit' no_visit = 'no_visit' - self.filesystem.CreateFile('%s/bar' % (root,)) - self.filesystem.CreateFile('%s/%s/1.txt' % (root, visit)) - self.filesystem.CreateFile('%s/%s/2.txt' % (root, visit)) - self.filesystem.CreateFile('%s/%s/3.txt' % (root, no_visit)) - self.filesystem.CreateFile('%s/%s/4.txt' % (root, no_visit)) + self.filesystem.create_file('%s/bar' % (root,)) + self.filesystem.create_file('%s/%s/1.txt' % (root, visit)) + self.filesystem.create_file('%s/%s/2.txt' % (root, visit)) + self.filesystem.create_file('%s/%s/3.txt' % (root, no_visit)) + self.filesystem.create_file('%s/%s/4.txt' % (root, no_visit)) generator = self.os.walk('/foo') root_contents = next(generator) @@ -3142,10 +3142,10 @@ def testWalkSkipsRemovedDirectories(self): def testWalkFollowsymlinkDisabled(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateFile('/linked/subfile') - self.filesystem.CreateFile('/foo/bar/baz') - self.filesystem.CreateFile('/foo/bar/xyzzy/plugh') - self.filesystem.CreateLink('/foo/created_link', '/linked') + self.filesystem.create_file('/linked/subfile') + self.filesystem.create_file('/foo/bar/baz') + self.filesystem.create_file('/foo/bar/xyzzy/plugh') + self.filesystem.symlink('/foo/created_link', '/linked') expected = [ ('/foo', ['bar', 'created_link'], []), @@ -3160,10 +3160,10 @@ def testWalkFollowsymlinkDisabled(self): def testWalkFollowsymlinkEnabled(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateFile('/linked/subfile') - self.filesystem.CreateFile('/foo/bar/baz') - self.filesystem.CreateFile('/foo/bar/xyzzy/plugh') - self.filesystem.CreateLink('/foo/created_link', '/linked') + self.filesystem.create_file('/linked/subfile') + self.filesystem.create_file('/foo/bar/baz') + self.filesystem.create_file('/foo/bar/xyzzy/plugh') + self.filesystem.symlink('/foo/created_link', '/linked') expected = [ ('/foo', ['bar', 'created_link'], []), @@ -3184,9 +3184,9 @@ def setUp(self): super(FakeOsModuleDirFdTest, self).setUp() self.os.supports_dir_fd = set() self.filesystem.is_windows_fs = False - self.filesystem.CreateDirectory('/foo/bar') + self.filesystem.create_dir('/foo/bar') self.dir_fd = self.os.open('/foo', os.O_RDONLY) - self.filesystem.CreateFile('/foo/baz') + self.filesystem.create_file('/foo/baz') def testAccess(self): self.assertRaises( @@ -3223,7 +3223,7 @@ def testLink(self): dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.link) self.os.link('baz', '/bat', dir_fd=self.dir_fd) - self.assertTrue(self.filesystem.Exists('/bat')) + self.assertTrue(self.filesystem.exists('/bat')) def testSymlink(self): self.assertRaises( @@ -3231,11 +3231,11 @@ def testSymlink(self): dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.symlink) self.os.symlink('baz', '/bat', dir_fd=self.dir_fd) - self.assertTrue(self.filesystem.Exists('/bat')) + self.assertTrue(self.filesystem.exists('/bat')) def testReadlink(self): - self.filesystem.CreateLink('/meyer/lemon/pie', '/foo/baz') - self.filesystem.CreateLink('/geo/metro', '/meyer') + self.filesystem.symlink('/meyer/lemon/pie', '/foo/baz') + self.filesystem.symlink('/geo/metro', '/meyer') self.assertRaises( NotImplementedError, self.os.readlink, '/geo/metro/lemon/pie', dir_fd=self.dir_fd) @@ -3262,14 +3262,14 @@ def testMkdir(self): NotImplementedError, self.os.mkdir, 'newdir', dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.mkdir) self.os.mkdir('newdir', dir_fd=self.dir_fd) - self.assertTrue(self.filesystem.Exists('/foo/newdir')) + self.assertTrue(self.filesystem.exists('/foo/newdir')) def testRmdir(self): self.assertRaises( NotImplementedError, self.os.rmdir, 'bar', dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.rmdir) self.os.rmdir('bar', dir_fd=self.dir_fd) - self.assertFalse(self.filesystem.Exists('/foo/bar')) + self.assertFalse(self.filesystem.exists('/foo/bar')) @unittest.skipIf(not hasattr(os, 'mknod'), 'mknod not on all platforms available') @@ -3278,7 +3278,7 @@ def testMknod(self): NotImplementedError, self.os.mknod, 'newdir', dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.mknod) self.os.mknod('newdir', dir_fd=self.dir_fd) - self.assertTrue(self.filesystem.Exists('/foo/newdir')) + self.assertTrue(self.filesystem.exists('/foo/newdir')) def testRename(self): self.assertRaises( @@ -3286,21 +3286,21 @@ def testRename(self): dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.rename) self.os.rename('bar', '/foo/batz', dir_fd=self.dir_fd) - self.assertTrue(self.filesystem.Exists('/foo/batz')) + self.assertTrue(self.filesystem.exists('/foo/batz')) def testRemove(self): self.assertRaises( NotImplementedError, self.os.remove, 'baz', dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.remove) self.os.remove('baz', dir_fd=self.dir_fd) - self.assertFalse(self.filesystem.Exists('/foo/baz')) + self.assertFalse(self.filesystem.exists('/foo/baz')) def testUnlink(self): self.assertRaises( NotImplementedError, self.os.unlink, 'baz', dir_fd=self.dir_fd) self.os.supports_dir_fd.add(os.unlink) self.os.unlink('baz', dir_fd=self.dir_fd) - self.assertFalse(self.filesystem.Exists('/foo/baz')) + self.assertFalse(self.filesystem.exists('/foo/baz')) def testUtime(self): self.assertRaises( @@ -3328,18 +3328,17 @@ def setUp(self): super(FakeScandirTest, self).setUp() directory = '/xyzzy/plugh' link_dir = '/linked/plugh' - linked_file_path = self.filesystem.JoinPaths(link_dir, 'file') - linked_dir_path = self.filesystem.JoinPaths(link_dir, 'dir') - - self.filesystem.CreateDirectory(linked_dir_path) - self.filesystem.CreateFile(linked_file_path, st_size=100) - self.filesystem.CreateDirectory( - self.filesystem.JoinPaths(directory, 'dir')) - self.filesystem.CreateFile( - self.filesystem.JoinPaths(directory, 'file'), st_size=500) - self.filesystem.CreateLink(self.filesystem.JoinPaths( + linked_file_path = self.filesystem.joinpaths(link_dir, 'file') + linked_dir_path = self.filesystem.joinpaths(link_dir, 'dir') + + self.filesystem.create_dir(linked_dir_path) + self.filesystem.create_file(linked_file_path, st_size=100) + self.filesystem.create_dir(self.filesystem.joinpaths(directory, 'dir')) + self.filesystem.create_file( + self.filesystem.joinpaths(directory, 'file'), st_size=500) + self.filesystem.symlink(self.filesystem.joinpaths( directory, 'link_file'), linked_file_path) - self.filesystem.CreateLink(self.filesystem.JoinPaths( + self.filesystem.symlink(self.filesystem.joinpaths( directory, 'link_dir'), linked_dir_path) self.dir_entries = [entry for entry in self.os.scandir(directory)] @@ -3376,15 +3375,16 @@ def testIsLink(self): self.assertTrue(self.dir_entries[3].is_symlink()) def testInode(self): - self.assertEqual(self.filesystem.GetObject('/xyzzy/plugh/dir').st_ino, + self.assertEqual(self.filesystem.get_object('/xyzzy/plugh/dir').st_ino, self.dir_entries[0].inode()) - self.assertEqual(self.filesystem.GetObject('/xyzzy/plugh/file').st_ino, - self.dir_entries[1].inode()) self.assertEqual( - self.filesystem.GetObject('/xyzzy/plugh/link_dir').st_ino, + self.filesystem.get_object('/xyzzy/plugh/file').st_ino, + self.dir_entries[1].inode()) + self.assertEqual( + self.filesystem.get_object('/xyzzy/plugh/link_dir').st_ino, self.dir_entries[2].inode()) self.assertEqual( - self.filesystem.GetObject('/xyzzy/plugh/link_file').st_ino, + self.filesystem.get_object('/xyzzy/plugh/link_file').st_ino, self.dir_entries[3].inode()) def testStat(self): @@ -3393,12 +3393,10 @@ def testStat(self): self.assertEqual(len('/linked/plugh/file'), self.dir_entries[3].stat( follow_symlinks=False).st_size) - self.assertEqual( - self.filesystem.ResolveObject('/xyzzy/plugh/dir').st_ctime, - self.dir_entries[0].stat().st_ctime) - self.assertEqual( - self.filesystem.ResolveObject('/linked/plugh/dir').st_mtime, - self.dir_entries[2].stat().st_mtime) + self.assertEqual(self.filesystem.resolve('/xyzzy/plugh/dir').st_ctime, + self.dir_entries[0].stat().st_ctime) + self.assertEqual(self.filesystem.resolve('/linked/plugh/dir').st_mtime, + self.dir_entries[2].stat().st_mtime) def testIndexAccessToStatTimesReturnsInt(self): self.assertEqual(self.os.stat('/xyzzy/plugh/dir')[stat.ST_CTIME], @@ -3408,7 +3406,7 @@ def testIndexAccessToStatTimesReturnsInt(self): def testStatInoDevPosix(self): self.filesystem.is_windows_fs = False - file_obj = self.filesystem.ResolveObject('/linked/plugh/file') + file_obj = self.filesystem.resolve('/linked/plugh/file') self.assertEqual(file_obj.st_ino, self.dir_entries[3].stat().st_ino) self.assertEqual(file_obj.st_dev, self.dir_entries[3].stat().st_dev) @@ -3432,14 +3430,14 @@ def testFileSizeUpdatedViaClose(self): self.os.mkdir(file_dir) fh = self.open(file_path, 'w') self.assertEqual(0, self.os.stat(file_path)[stat.ST_SIZE]) - self.assertEqual('', self.filesystem.GetObject(file_path).contents) + self.assertEqual('', self.filesystem.get_object(file_path).contents) fh.write(content) self.assertEqual(0, self.os.stat(file_path)[stat.ST_SIZE]) - self.assertEqual('', self.filesystem.GetObject(file_path).contents) + self.assertEqual('', self.filesystem.get_object(file_path).contents) fh.close() self.assertEqual(len(content), self.os.stat(file_path)[stat.ST_SIZE]) self.assertEqual(content, - self.filesystem.GetObject(file_path).contents) + self.filesystem.get_object(file_path).contents) def testFileSizeNotResetAfterClose(self): file_dir = 'xyzzy' @@ -3448,29 +3446,29 @@ def testFileSizeNotResetAfterClose(self): size = 1234 # The file has size, but no content. When the file is opened for reading, # its size should be preserved. - self.filesystem.CreateFile(file_path, st_size=size) + self.filesystem.create_file(file_path, st_size=size) fh = self.open(file_path, 'r') fh.close() - self.assertEqual(size, self.open(file_path, 'r').Size()) + self.assertEqual(size, self.open(file_path, 'r').size()) def testFileSizeAfterWrite(self): file_path = 'test_file' original_content = 'abcdef' original_size = len(original_content) - self.filesystem.CreateFile(file_path, contents=original_content) + self.filesystem.create_file(file_path, contents=original_content) added_content = 'foo bar' expected_size = original_size + len(added_content) fh = self.open(file_path, 'a') fh.write(added_content) - self.assertEqual(original_size, fh.Size()) + self.assertEqual(original_size, fh.size()) fh.close() - self.assertEqual(expected_size, self.open(file_path, 'r').Size()) + self.assertEqual(expected_size, self.open(file_path, 'r').size()) def testLargeFileSizeAfterWrite(self): file_path = 'test_file' original_content = 'abcdef' original_size = len(original_content) - self.filesystem.CreateFile(file_path, st_size=original_size) + self.filesystem.create_file(file_path, st_size=original_size) added_content = 'foo bar' fh = self.open(file_path, 'a') self.assertRaises(fake_filesystem.FakeLargeFileIoException, @@ -3485,18 +3483,18 @@ def testFileSizeUpdatedViaFlush(self): self.os.mkdir(file_dir) fh = self.open(file_path, 'w') self.assertEqual(0, self.os.stat(file_path)[stat.ST_SIZE]) - self.assertEqual('', self.filesystem.GetObject(file_path).contents) + self.assertEqual('', self.filesystem.get_object(file_path).contents) fh.write(content) self.assertEqual(0, self.os.stat(file_path)[stat.ST_SIZE]) - self.assertEqual('', self.filesystem.GetObject(file_path).contents) + self.assertEqual('', self.filesystem.get_object(file_path).contents) fh.flush() self.assertEqual(len(content), self.os.stat(file_path)[stat.ST_SIZE]) self.assertEqual(content, - self.filesystem.GetObject(file_path).contents) + self.filesystem.get_object(file_path).contents) fh.close() self.assertEqual(len(content), self.os.stat(file_path)[stat.ST_SIZE]) self.assertEqual(content, - self.filesystem.GetObject(file_path).contents) + self.filesystem.get_object(file_path).contents) def testFileSizeTruncation(self): """test that file size gets updated via open().""" @@ -3511,12 +3509,12 @@ def testFileSizeTruncation(self): fh.close() self.assertEqual(len(content), self.os.stat(file_path)[stat.ST_SIZE]) self.assertEqual(content, - self.filesystem.GetObject(file_path).contents) + self.filesystem.get_object(file_path).contents) # test file truncation fh = self.open(file_path, 'w') self.assertEqual(0, self.os.stat(file_path)[stat.ST_SIZE]) - self.assertEqual('', self.filesystem.GetObject(file_path).contents) + self.assertEqual('', self.filesystem.get_object(file_path).contents) fh.close() @@ -3541,15 +3539,15 @@ def tearDown(self): def testCreateTopLevelDirectory(self): top_level_dir = '/x' - self.assertFalse(self.filesystem.Exists(top_level_dir)) - self.filesystem.CreateDirectory(top_level_dir) - self.assertTrue(self.filesystem.Exists('/')) - self.assertTrue(self.filesystem.Exists(top_level_dir)) - self.filesystem.CreateDirectory('%s/po' % top_level_dir) - self.filesystem.CreateFile('%s/po/control' % top_level_dir) - self.filesystem.CreateFile('%s/po/experiment' % top_level_dir) - self.filesystem.CreateDirectory('%s/gv' % top_level_dir) - self.filesystem.CreateFile('%s/gv/control' % top_level_dir) + self.assertFalse(self.filesystem.exists(top_level_dir)) + self.filesystem.create_dir(top_level_dir) + self.assertTrue(self.filesystem.exists('/')) + self.assertTrue(self.filesystem.exists(top_level_dir)) + self.filesystem.create_dir('%s/po' % top_level_dir) + self.filesystem.create_file('%s/po/control' % top_level_dir) + self.filesystem.create_file('%s/po/experiment' % top_level_dir) + self.filesystem.create_dir('%s/gv' % top_level_dir) + self.filesystem.create_file('%s/gv/control' % top_level_dir) expected = [ ('/', ['x'], []), @@ -3583,7 +3581,7 @@ def checkAbspath(self, is_windows): self.filesystem.is_windows_fs = is_windows filename = u'foo' abspath = u'!%s' % filename - self.filesystem.CreateFile(abspath) + self.filesystem.create_file(abspath) self.assertEqual(abspath, self.path.abspath(abspath)) self.assertEqual(abspath, self.path.abspath(filename)) self.assertEqual(abspath, self.path.abspath(u'..!%s' % filename)) @@ -3600,7 +3598,7 @@ def checkAbspathBytes(self, is_windows): self.filesystem.is_windows_fs = is_windows filename = b'foo' abspath = b'!' + filename - self.filesystem.CreateFile(abspath) + self.filesystem.create_file(abspath) self.assertEqual(abspath, self.path.abspath(abspath)) self.assertEqual(abspath, self.path.abspath(filename)) self.assertEqual(abspath, self.path.abspath(b'..!' + filename)) @@ -3620,7 +3618,7 @@ def testAbspathDealsWithRelativeNonRootPath(self): filename = '!foo!bar!baz' file_components = filename.split(self.path.sep) basedir = '!%s' % (file_components[0],) - self.filesystem.CreateFile(filename) + self.filesystem.create_file(filename) self.os.chdir(basedir) self.assertEqual(basedir, self.path.abspath(self.path.curdir)) self.assertEqual('!', self.path.abspath('..')) @@ -3663,8 +3661,8 @@ def testRelpath(self): def testRealpathVsAbspath(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateFile('!george!washington!bridge') - self.filesystem.CreateLink('!first!president', '!george!washington') + self.filesystem.create_file('!george!washington!bridge') + self.filesystem.symlink('!first!president', '!george!washington') self.assertEqual('!first!president!bridge', self.os.path.abspath('!first!president!bridge')) self.assertEqual('!george!washington!bridge', @@ -3678,8 +3676,8 @@ def testRealpathVsAbspath(self): def testSamefile(self): file_path1 = '!foo!bar!baz' file_path2 = '!foo!bar!boo' - self.filesystem.CreateFile(file_path1) - self.filesystem.CreateFile(file_path2) + self.filesystem.create_file(file_path1) + self.filesystem.create_file(file_path2) self.assertTrue(self.path.samefile(file_path1, file_path1)) self.assertFalse(self.path.samefile(file_path1, file_path2)) self.assertTrue( @@ -3687,7 +3685,7 @@ def testSamefile(self): def testExists(self): file_path = 'foo!bar!baz' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertTrue(self.path.exists(file_path)) self.assertFalse(self.path.exists('!some!other!bogus!path')) @@ -3695,11 +3693,11 @@ def testExists(self): 'Links are not supported under Windows before Python 3.3') def testLexists(self): file_path = 'foo!bar!baz' - self.filesystem.CreateDirectory('foo!bar') - self.filesystem.CreateLink(file_path, 'bogus') + self.filesystem.create_dir('foo!bar') + self.filesystem.symlink(file_path, 'bogus') self.assertTrue(self.path.lexists(file_path)) self.assertFalse(self.path.exists(file_path)) - self.filesystem.CreateFile('foo!bar!bogus') + self.filesystem.create_file('foo!bar!bogus') self.assertTrue(self.path.exists(file_path)) def testDirname(self): @@ -3737,18 +3735,18 @@ def testGetsizePathNonexistent(self): def testGetsizeFileEmpty(self): file_path = 'foo!bar!baz' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertEqual(0, self.path.getsize(file_path)) def testGetsizeFileNonZeroSize(self): file_path = 'foo!bar!baz' - self.filesystem.CreateFile(file_path, contents='1234567') + self.filesystem.create_file(file_path, contents='1234567') self.assertEqual(7, self.path.getsize(file_path)) def testGetsizeDirEmpty(self): # For directories, only require that the size is non-negative. dir_path = 'foo!bar' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) size = self.path.getsize(dir_path) self.assertFalse(int(size) < 0, 'expected non-negative size; actual: %s' % size) @@ -3756,19 +3754,19 @@ def testGetsizeDirEmpty(self): def testGetsizeDirNonZeroSize(self): # For directories, only require that the size is non-negative. dir_path = 'foo!bar' - self.filesystem.CreateFile(self.filesystem.JoinPaths(dir_path, 'baz')) + self.filesystem.create_file(self.filesystem.joinpaths(dir_path, 'baz')) size = self.path.getsize(dir_path) self.assertFalse(int(size) < 0, 'expected non-negative size; actual: %s' % size) def testIsdir(self): - self.filesystem.CreateFile('foo!bar') + self.filesystem.create_file('foo!bar') self.assertTrue(self.path.isdir('foo')) self.assertFalse(self.path.isdir('foo!bar')) self.assertFalse(self.path.isdir('it_dont_exist')) def testIsdirWithCwdChange(self): - self.filesystem.CreateFile('!foo!bar!baz') + self.filesystem.create_file('!foo!bar!baz') self.assertTrue(self.path.isdir('!foo')) self.assertTrue(self.path.isdir('!foo!bar')) self.assertTrue(self.path.isdir('foo')) @@ -3779,16 +3777,16 @@ def testIsdirWithCwdChange(self): self.assertTrue(self.path.isdir('bar')) def testIsfile(self): - self.filesystem.CreateFile('foo!bar') + self.filesystem.create_file('foo!bar') self.assertFalse(self.path.isfile('foo')) self.assertTrue(self.path.isfile('foo!bar')) self.assertFalse(self.path.isfile('it_dont_exist')) def testGetMtime(self): - test_file = self.filesystem.CreateFile('foo!bar1.txt') + test_file = self.filesystem.create_file('foo!bar1.txt') time.time.start() self.assertEqual(10, test_file.st_mtime) - test_file.SetMTime(24) + test_file.st_mtime = 24 self.assertEqual(24, self.path.getmtime('foo!bar1.txt')) def testGetMtimeRaisesOSError(self): @@ -3799,9 +3797,9 @@ def testGetMtimeRaisesOSError(self): @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testIslink(self): - self.filesystem.CreateDirectory('foo') - self.filesystem.CreateFile('foo!regular_file') - self.filesystem.CreateLink('foo!link_to_file', 'regular_file') + self.filesystem.create_dir('foo') + self.filesystem.create_file('foo!regular_file') + self.filesystem.symlink('foo!link_to_file', 'regular_file') self.assertFalse(self.path.islink('foo')) # An object can be both a link and a file or file, according to the @@ -3818,7 +3816,7 @@ def testIsmount(self): self.assertFalse(self.path.ismount('')) self.assertTrue(self.path.ismount('!')) self.assertFalse(self.path.ismount('!mount!')) - self.filesystem.AddMountPoint('!mount') + self.filesystem.add_mount_point('!mount') self.assertTrue(self.path.ismount('!mount')) self.assertTrue(self.path.ismount('!mount!')) @@ -3828,7 +3826,7 @@ def testIsmountWithDriveLetters(self): self.assertTrue(self.path.ismount('c:!')) self.assertFalse(self.path.ismount('c:')) self.assertTrue(self.path.ismount('z:!')) - self.filesystem.AddMountPoint('!mount') + self.filesystem.add_mount_point('!mount') self.assertTrue(self.path.ismount('!mount')) self.assertTrue(self.path.ismount('!mount!')) @@ -3844,7 +3842,7 @@ def testIsmountWithUncPaths(self): def testIsmountWithAlternatePathSeparator(self): self.filesystem.alternative_path_separator = '!' - self.filesystem.AddMountPoint('!mount') + self.filesystem.add_mount_point('!mount') self.assertTrue(self.path.ismount('!mount')) self.assertTrue(self.path.ismount('!mount!')) self.assertTrue(self.path.ismount('!mount!!')) @@ -3854,8 +3852,8 @@ def testIsmountWithAlternatePathSeparator(self): @unittest.skipIf(sys.version_info >= (3, 0), 'os.path.walk removed in Python 3') def testWalk(self): - self.filesystem.CreateFile('!foo!bar!baz') - self.filesystem.CreateFile('!foo!bar!xyzzy!plugh') + self.filesystem.create_file('!foo!bar!baz') + self.filesystem.create_file('!foo!bar!xyzzy!plugh') visited_nodes = [] def RecordVisitedNodes(visited, dirname, fnames): @@ -3924,9 +3922,9 @@ def testDeleteOnClose(self): self.file = fake_filesystem.FakeFileOpen(self.filesystem, delete_on_close=True) fh = self.file(file_path, 'w') - self.assertTrue(self.filesystem.Exists(file_path)) + self.assertTrue(self.filesystem.exists(file_path)) fh.close() - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) def testNoDeleteOnCloseByDefault(self): file_dir = 'boo' @@ -3934,19 +3932,19 @@ def testNoDeleteOnCloseByDefault(self): self.file = fake_filesystem.FakeFileOpen(self.filesystem) self.os.mkdir(file_dir) fh = self.file(file_path, 'w') - self.assertTrue(self.filesystem.Exists(file_path)) + self.assertTrue(self.filesystem.exists(file_path)) fh.close() - self.assertTrue(self.filesystem.Exists(file_path)) + self.assertTrue(self.filesystem.exists(file_path)) def testCompatibilityOfWithStatement(self): self.file = fake_filesystem.FakeFileOpen(self.filesystem, delete_on_close=True) file_path = 'foo' - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) with self.file(file_path, 'w') as _: - self.assertTrue(self.filesystem.Exists(file_path)) + self.assertTrue(self.filesystem.exists(file_path)) # After the 'with' statement, the close() method should have been called. - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) def testUnicodeContents(self): self.file = fake_filesystem.FakeFileOpen(self.filesystem) @@ -4019,7 +4017,7 @@ def testOpenValidFile(self): 'we are all together\n' ] file_path = 'foo!bar.txt' - self.filesystem.CreateFile(file_path, contents=''.join(contents)) + self.filesystem.create_file(file_path, contents=''.join(contents)) self.assertEqual(contents, self.file(file_path).readlines()) def testOpenValidArgs(self): @@ -4028,7 +4026,7 @@ def testOpenValidArgs(self): 'Came down on her head', ] file_path = 'abbey_road!maxwell' - self.filesystem.CreateFile(file_path, contents=''.join(contents)) + self.filesystem.create_file(file_path, contents=''.join(contents)) self.assertEqual( contents, self.open(file_path, mode='r', buffering=1).readlines()) if sys.version_info >= (3, 0): @@ -4042,7 +4040,7 @@ def testOpenValidArgs(self): def testOpenNewlineArg(self): file_path = 'some_file' file_contents = 'two\r\nlines' - self.filesystem.CreateFile(file_path, contents=file_contents) + self.filesystem.create_file(file_path, contents=file_contents) fake_file = self.open(file_path, mode='r', newline=None) self.assertEqual(['two\n', 'lines'], fake_file.readlines()) fake_file = self.open(file_path, mode='r', newline='') @@ -4062,7 +4060,7 @@ def testOpenValidFileWithCwd(self): 'we are all together\n' ] file_path = '!foo!bar.txt' - self.filesystem.CreateFile(file_path, contents=''.join(contents)) + self.filesystem.create_file(file_path, contents=''.join(contents)) self.filesystem.cwd = '!foo' self.assertEqual(contents, self.file(file_path).readlines()) @@ -4072,13 +4070,13 @@ def testIterateOverFile(self): 'Came down on her head', ] file_path = 'abbey_road!maxwell' - self.filesystem.CreateFile(file_path, contents='\n'.join(contents)) + self.filesystem.create_file(file_path, contents='\n'.join(contents)) result = [line.rstrip() for line in self.file(file_path)] self.assertEqual(contents, result) def testOpenDirectoryError(self): directory_path = 'foo!bar' - self.filesystem.CreateDirectory(directory_path) + self.filesystem.create_dir(directory_path) if self.filesystem.is_windows_fs: self.assertRaisesOSError(errno.EPERM, self.file.__call__, directory_path) @@ -4122,7 +4120,7 @@ def testCreateFileWithAppend(self): 'Exclusive mode new in Python 3.3') def testExclusiveCreateFileFailure(self): file_path = '!foo!bar' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.assertRaisesIOError(errno.EEXIST, self.file, file_path, 'x') self.assertRaisesIOError(errno.EEXIST, self.file, file_path, 'xb') @@ -4130,7 +4128,7 @@ def testExclusiveCreateFileFailure(self): 'Exclusive mode new in Python 3.3') def testExclusiveCreateFile(self): file_path = '!foo!bar' - self.filesystem.CreateDirectory('!foo') + self.filesystem.create_dir('!foo') contents = 'String contents' fake_file = self.file(file_path, 'x') fake_file.write(contents) @@ -4141,7 +4139,7 @@ def testExclusiveCreateFile(self): 'Exclusive mode new in Python 3.3') def testExclusiveCreateBinaryFile(self): file_path = '!foo!bar' - self.filesystem.CreateDirectory('!foo') + self.filesystem.create_dir('!foo') contents = b'Binary contents' fake_file = self.file(file_path, 'xb') fake_file.write(contents) @@ -4150,7 +4148,7 @@ def testExclusiveCreateBinaryFile(self): def testOverwriteExistingFile(self): file_path = 'overwrite!this!file' - self.filesystem.CreateFile(file_path, contents='To disappear') + self.filesystem.create_file(file_path, contents='To disappear') new_contents = [ 'Only these lines', 'should be in the file.', @@ -4168,7 +4166,7 @@ def testAppendExistingFile(self): 'Contents of original file' 'Appended contents', ] - self.filesystem.CreateFile(file_path, contents=contents[0]) + self.filesystem.create_file(file_path, contents=contents[0]) fake_file = self.file(file_path, 'a') for line in contents[1:]: fake_file.write(line + '\n') @@ -4179,8 +4177,8 @@ def testAppendExistingFile(self): def testOpenWithWplus(self): # set up file_path = 'wplus_file' - self.filesystem.CreateFile(file_path, contents='old contents') - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path, contents='old contents') + self.assertTrue(self.filesystem.exists(file_path)) fake_file = self.file(file_path, 'r') self.assertEqual('old contents', fake_file.read()) fake_file.close() @@ -4194,8 +4192,8 @@ def testOpenWithWplus(self): def testOpenWithWplusTruncation(self): # set up file_path = 'wplus_file' - self.filesystem.CreateFile(file_path, contents='old contents') - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path, contents='old contents') + self.assertTrue(self.filesystem.exists(file_path)) fake_file = self.file(file_path, 'r') self.assertEqual('old contents', fake_file.read()) fake_file.close() @@ -4217,7 +4215,7 @@ def testOpenWithAppendFlag(self): 'like you a lot.\n' ] file_path = 'append!this!file' - self.filesystem.CreateFile(file_path, contents=''.join(contents)) + self.filesystem.create_file(file_path, contents=''.join(contents)) fake_file = self.file(file_path, 'a') expected_error = (IOError if sys.version_info < (3,) else io.UnsupportedOperation) @@ -4234,8 +4232,8 @@ def testOpenWithAppendFlag(self): def testAppendWithAplus(self): # set up file_path = 'aplus_file' - self.filesystem.CreateFile(file_path, contents='old contents') - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path, contents='old contents') + self.assertTrue(self.filesystem.exists(file_path)) fake_file = self.file(file_path, 'r') self.assertEqual('old contents', fake_file.read()) fake_file.close() @@ -4252,8 +4250,8 @@ def testAppendWithAplus(self): def testAppendWithAplusReadWithLoop(self): # set up file_path = 'aplus_file' - self.filesystem.CreateFile(file_path, contents='old contents') - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path, contents='old contents') + self.assertTrue(self.filesystem.exists(file_path)) fake_file = self.file(file_path, 'r') self.assertEqual('old contents', fake_file.read()) fake_file.close() @@ -4275,8 +4273,8 @@ def testReadEmptyFileWithAplus(self): def testReadWithRplus(self): # set up file_path = 'rplus_file' - self.filesystem.CreateFile(file_path, contents='old contents here') - self.assertTrue(self.filesystem.Exists(file_path)) + self.filesystem.create_file(file_path, contents='old contents here') + self.assertTrue(self.filesystem.exists(file_path)) fake_file = self.file(file_path, 'r') self.assertEqual('old contents here', fake_file.read()) fake_file.close() @@ -4293,7 +4291,7 @@ def testOpenStCtime(self): # set up time.time = _DummyTime(100, 10) file_path = 'some_file' - self.assertFalse(self.filesystem.Exists(file_path)) + self.assertFalse(self.filesystem.exists(file_path)) # tests fake_file = self.file(file_path, 'w') time.time.start() @@ -4344,7 +4342,7 @@ def testOpenStCtime(self): self.assertEqual(160, st.st_mtime) def _CreateWithPermission(self, file_path, perm_bits): - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.chmod(file_path, perm_bits) st = self.os.stat(file_path) self.assertModeEqual(perm_bits, st.st_mode) @@ -4394,8 +4392,8 @@ def testFollowLinkRead(self): link_path = '!foo!bar!baz' target = '!tarJAY' target_contents = 'real baz contents' - self.filesystem.CreateFile(target, contents=target_contents) - self.filesystem.CreateLink(link_path, target) + self.filesystem.create_file(target, contents=target_contents) + self.filesystem.symlink(link_path, target) self.assertEqual(target, self.os.readlink(link_path)) fh = self.open(link_path, 'r') got_contents = fh.read() @@ -4408,8 +4406,8 @@ def testFollowLinkWrite(self): link_path = '!foo!bar!TBD' target = '!tarJAY' target_contents = 'real baz contents' - self.filesystem.CreateLink(link_path, target) - self.assertFalse(self.filesystem.Exists(target)) + self.filesystem.symlink(link_path, target) + self.assertFalse(self.filesystem.exists(target)) fh = self.open(link_path, 'w') fh.write(target_contents) @@ -4425,10 +4423,10 @@ def testFollowIntraPathLinkWrite(self): # Test a link in the middle of of a file path. link_path = '!foo!build!local_machine!output!1' target = '!tmp!output!1' - self.filesystem.CreateDirectory('!tmp!output') - self.filesystem.CreateLink('!foo!build!local_machine', '!tmp') - self.assertFalse(self.filesystem.Exists(link_path)) - self.assertFalse(self.filesystem.Exists(target)) + self.filesystem.create_dir('!tmp!output') + self.filesystem.symlink('!foo!build!local_machine', '!tmp') + self.assertFalse(self.filesystem.exists(link_path)) + self.assertFalse(self.filesystem.exists(target)) target_contents = 'real baz contents' fh = self.open(link_path, 'w') @@ -4442,7 +4440,7 @@ def testFollowIntraPathLinkWrite(self): def testOpenRaisesOnSymlinkLoop(self): self.filesystem.is_windows_fs = False base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + '/baz' self.os.symlink(file_path, file_path) self.assertRaisesIOError(errno.ELOOP, self.open, file_path) @@ -4451,9 +4449,9 @@ def testFileDescriptorsForDifferentFiles(self): first_path = 'some_file1' second_path = 'some_file2' third_path = 'some_file3' - self.filesystem.CreateFile(first_path, contents='contents here1') - self.filesystem.CreateFile(second_path, contents='contents here2') - self.filesystem.CreateFile(third_path, contents='contents here3') + self.filesystem.create_file(first_path, contents='contents here1') + self.filesystem.create_file(second_path, contents='contents here2') + self.filesystem.create_file(third_path, contents='contents here3') fake_file1 = self.open(first_path, 'r') fake_file2 = self.open(second_path, 'r') @@ -4465,8 +4463,8 @@ def testFileDescriptorsForDifferentFiles(self): def testFileDescriptorsForTheSameFileAreDifferent(self): first_path = 'some_file1' second_path = 'some_file2' - self.filesystem.CreateFile(first_path, contents='contents here1') - self.filesystem.CreateFile(second_path, contents='contents here2') + self.filesystem.create_file(first_path, contents='contents here1') + self.filesystem.create_file(second_path, contents='contents here2') fake_file1 = self.open(first_path, 'r') fake_file2 = self.open(second_path, 'r') @@ -4479,9 +4477,9 @@ def testReusedFileDescriptorsDoNotAffectOthers(self): first_path = 'some_file1' second_path = 'some_file2' third_path = 'some_file3' - self.filesystem.CreateFile(first_path, contents='contents here1') - self.filesystem.CreateFile(second_path, contents='contents here2') - self.filesystem.CreateFile(third_path, contents='contents here3') + self.filesystem.create_file(first_path, contents='contents here1') + self.filesystem.create_file(second_path, contents='contents here2') + self.filesystem.create_file(third_path, contents='contents here3') fake_file1 = self.open(first_path, 'r') fake_file2 = self.open(second_path, 'r') @@ -4503,7 +4501,7 @@ def testReusedFileDescriptorsDoNotAffectOthers(self): def testIntertwinedReadWrite(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) with self.open(file_path, 'a') as writer: with self.open(file_path, 'r') as reader: writes = ['hello', 'world\n', 'somewhere\nover', 'the\n', @@ -4528,7 +4526,7 @@ def testIntertwinedReadWrite(self): 'Python 3 specific string handling') def testIntertwinedReadWritePython3Str(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) with self.open(file_path, 'a', encoding='utf-8') as writer: with self.open(file_path, 'r', encoding='utf-8') as reader: writes = ['привет', 'мир\n', 'где-то\за', 'радугой'] @@ -4550,7 +4548,7 @@ def testIntertwinedReadWritePython3Str(self): def testOpenIoErrors(self): file_path = 'some_file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) with self.open(file_path, 'a') as fh: self.assertRaises(IOError, fh.read) @@ -4572,8 +4570,8 @@ def _IteratorOpen(file_path, mode): def testCanReadFromBlockDevice(self): device_path = 'device' - self.filesystem.CreateFile(device_path, stat.S_IFBLK - | fake_filesystem.PERM_ALL) + self.filesystem.create_file(device_path, stat.S_IFBLK + | fake_filesystem.PERM_ALL) with self.open(device_path, 'r') as fh: self.assertEqual('', fh.read()) @@ -4666,8 +4664,8 @@ def testAppendExistingFile(self): u'Оригинальное содержание' u'Дополнительное содержание', ] - self.filesystem.CreateFile(self.file_path, contents=contents[0], - encoding='cyrillic') + self.filesystem.create_file(self.file_path, contents=contents[0], + encoding='cyrillic') fake_file = self.open(self.file_path, 'a', encoding='cyrillic') for line in contents[1:]: fake_file.write(line + '\n') @@ -4677,9 +4675,9 @@ def testAppendExistingFile(self): self.assertEqual(contents, result) def testOpenWithWplus(self): - self.filesystem.CreateFile(self.file_path, - contents=u'старое содержание', - encoding='cyrillic') + self.filesystem.create_file(self.file_path, + contents=u'старое содержание', + encoding='cyrillic') fake_file = self.open(self.file_path, 'r', encoding='cyrillic') self.assertEqual(u'старое содержание', fake_file.read()) fake_file.close() @@ -4700,8 +4698,8 @@ def testOpenWithAppendFlag(self): u'В саду ягода-малинка,\n', u'малинка моя.\n' ] - self.filesystem.CreateFile(self.file_path, contents=''.join(contents), - encoding='cyrillic') + self.filesystem.create_file(self.file_path, contents=''.join(contents), + encoding='cyrillic') fake_file = self.open(self.file_path, 'a', encoding='cyrillic') expected_error = (IOError if sys.version_info < (3,) else io.UnsupportedOperation) @@ -4716,9 +4714,9 @@ def testOpenWithAppendFlag(self): self.assertEqual(contents + additional_contents, result) def testAppendWithAplus(self): - self.filesystem.CreateFile(self.file_path, - contents=u'старое содержание', - encoding='cyrillic') + self.filesystem.create_file(self.file_path, + contents=u'старое содержание', + encoding='cyrillic') fake_file = self.open(self.file_path, 'r', encoding='cyrillic') fake_file.close() @@ -4733,9 +4731,9 @@ def testAppendWithAplus(self): fake_file.close() def testReadWithRplus(self): - self.filesystem.CreateFile(self.file_path, - contents=u'старое содержание здесь', - encoding='cyrillic') + self.filesystem.create_file(self.file_path, + contents=u'старое содержание здесь', + encoding='cyrillic') fake_file = self.open(self.file_path, 'r', encoding='cyrillic') fake_file.close() @@ -4749,7 +4747,7 @@ def testReadWithRplus(self): def testAccessingClosedFileRaises(self): # self.filesystem.is_windows_fs = False - self.filesystem.CreateFile(self.file_path, contents=b'test') + self.filesystem.create_file(self.file_path, contents=b'test') fake_file = self.open(self.file_path, 'r') fake_file.close() self.assertRaises(ValueError, lambda: fake_file.read(1)) @@ -4763,7 +4761,7 @@ def testAccessingClosedFileRaises(self): 'file.next() not available in Python 3') def test284(self): base_path = '/foo/bar' - self.filesystem.CreateDirectory(base_path) + self.filesystem.create_dir(base_path) file_path = base_path + "/baz" f0 = self.open(file_path, 'w') f0.write('test') @@ -4783,7 +4781,7 @@ class OpenWithFileDescriptorTest(FakeFileOpenTestBase): 'only tested on 3.0 or greater') def testOpenWithFileDescriptor(self): file_path = 'this!file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) fd = self.os.open(file_path, os.O_CREAT) self.assertEqual(fd, self.open(fd, 'r').fileno()) @@ -4791,7 +4789,7 @@ def testOpenWithFileDescriptor(self): 'only tested on 3.0 or greater') def testClosefdWithFileDescriptor(self): file_path = 'this!file' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) fd = self.os.open(file_path, os.O_CREAT) fh = self.open(fd, 'r', closefd=False) fh.close() @@ -4808,7 +4806,8 @@ def setUp(self): self.os = fake_filesystem.FakeOsModule(self.filesystem) self.file_path = 'some_file' self.file_contents = b'real binary contents: \x1f\x8b' - self.filesystem.CreateFile(self.file_path, contents=self.file_contents) + self.filesystem.create_file(self.file_path, + contents=self.file_contents) def OpenFakeFile(self, mode): return self.file(self.file_path, mode=mode) @@ -4862,7 +4861,8 @@ def setUp(self): # For python 3.x, text file newlines are converted to \n if sys.version_info >= (3, 0): self.read_contents = 'two\nlines' - self.filesystem.CreateFile(self.file_path, contents=self.file_contents) + self.filesystem.create_file(self.file_path, + contents=self.file_contents) # It's reasonable to assume the file exists at this point def OpenFakeFile(self, mode): @@ -4937,60 +4937,60 @@ def testEmptyFilepathRaisesIOError(self): def testNormalPath(self): self.__WriteToFile('foo') - self.assertTrue(self.filesystem.Exists('foo')) + self.assertTrue(self.filesystem.exists('foo')) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testLinkWithinSameDirectory(self): final_target = '!foo!baz' - self.filesystem.CreateLink('!foo!bar', 'baz') + self.filesystem.symlink('!foo!bar', 'baz') self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) self.assertEqual(1, self.os.stat(final_target)[stat.ST_SIZE]) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testLinkToSubDirectory(self): final_target = '!foo!baz!bip' - self.filesystem.CreateDirectory('!foo!baz') - self.filesystem.CreateLink('!foo!bar', 'baz!bip') + self.filesystem.create_dir('!foo!baz') + self.filesystem.symlink('!foo!bar', 'baz!bip') self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) self.assertEqual(1, self.os.stat(final_target)[stat.ST_SIZE]) - self.assertTrue(self.filesystem.Exists('!foo!baz')) + self.assertTrue(self.filesystem.exists('!foo!baz')) # Make sure that intermediate directory got created. - new_dir = self.filesystem.GetObject('!foo!baz') + new_dir = self.filesystem.get_object('!foo!baz') self.assertTrue(stat.S_IFDIR & new_dir.st_mode) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testLinkToParentDirectory(self): final_target = '!baz!bip' - self.filesystem.CreateDirectory('!foo') - self.filesystem.CreateDirectory('!baz') - self.filesystem.CreateLink('!foo!bar', '..!baz') + self.filesystem.create_dir('!foo') + self.filesystem.create_dir('!baz') + self.filesystem.symlink('!foo!bar', '..!baz') self.__WriteToFile('!foo!bar!bip') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) self.assertEqual(1, self.os.stat(final_target)[stat.ST_SIZE]) - self.assertTrue(self.filesystem.Exists('!foo!bar')) + self.assertTrue(self.filesystem.exists('!foo!bar')) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testLinkToAbsolutePath(self): final_target = '!foo!baz!bip' - self.filesystem.CreateDirectory('!foo!baz') - self.filesystem.CreateLink('!foo!bar', final_target) + self.filesystem.create_dir('!foo!baz') + self.filesystem.symlink('!foo!bar', final_target) self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testRelativeLinksWorkAfterChdir(self): final_target = '!foo!baz!bip' - self.filesystem.CreateDirectory('!foo!baz') - self.filesystem.CreateLink('!foo!bar', '.!baz!bip') + self.filesystem.create_dir('!foo!baz') + self.filesystem.symlink('!foo!bar', '.!baz!bip') self.assertEqual(final_target, - self.filesystem.ResolvePath('!foo!bar')) + self.filesystem.resolve_path('!foo!bar')) self.assertTrue(self.os.path.islink('!foo!bar')) self.os.chdir('!foo') @@ -4998,19 +4998,19 @@ def testRelativeLinksWorkAfterChdir(self): self.assertTrue(self.os.path.islink('bar')) self.assertEqual('!foo!baz!bip', - self.filesystem.ResolvePath('bar')) + self.filesystem.resolve_path('bar')) self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testAbsoluteLinksWorkAfterChdir(self): final_target = '!foo!baz!bip' - self.filesystem.CreateDirectory('!foo!baz') - self.filesystem.CreateLink('!foo!bar', final_target) + self.filesystem.create_dir('!foo!baz') + self.filesystem.symlink('!foo!bar', final_target) self.assertEqual(final_target, - self.filesystem.ResolvePath('!foo!bar')) + self.filesystem.resolve_path('!foo!bar')) os_module = fake_filesystem.FakeOsModule(self.filesystem) self.assertTrue(os_module.path.islink('!foo!bar')) @@ -5019,22 +5019,22 @@ def testAbsoluteLinksWorkAfterChdir(self): self.assertTrue(os_module.path.islink('bar')) self.assertEqual('!foo!baz!bip', - self.filesystem.ResolvePath('bar')) + self.filesystem.resolve_path('bar')) self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testChdirThroughRelativeLink(self): - self.filesystem.CreateDirectory('!x!foo') - self.filesystem.CreateDirectory('!x!bar') - self.filesystem.CreateLink('!x!foo!bar', '..!bar') - self.assertEqual('!x!bar', self.filesystem.ResolvePath('!x!foo!bar')) + self.filesystem.create_dir('!x!foo') + self.filesystem.create_dir('!x!bar') + self.filesystem.symlink('!x!foo!bar', '..!bar') + self.assertEqual('!x!bar', self.filesystem.resolve_path('!x!foo!bar')) self.os.chdir('!x!foo') self.assertEqual('!x!foo', self.os.getcwd()) - self.assertEqual('!x!bar', self.filesystem.ResolvePath('bar')) + self.assertEqual('!x!bar', self.filesystem.resolve_path('bar')) self.os.chdir('bar') self.assertEqual('!x!bar', self.os.getcwd()) @@ -5045,7 +5045,7 @@ def testChdirUsesOpenFdAsPath(self): self.filesystem.is_windows_fs = False self.assertRaisesOSError(errno.EBADF, self.os.chdir, 5) dir_path = '!foo!bar' - self.filesystem.CreateDirectory(dir_path) + self.filesystem.create_dir(dir_path) path_des = self.os.open(dir_path, os.O_RDONLY) self.os.chdir(path_des) @@ -5057,8 +5057,8 @@ def testChdirUsesOpenFdAsPath(self): def testReadLinkToLink(self): # Write into the final link target and read back from a file which will # point to that. - self.filesystem.CreateLink('!foo!bar', 'link') - self.filesystem.CreateLink('!foo!link', 'baz') + self.filesystem.symlink('!foo!bar', 'link') + self.filesystem.symlink('!foo!link', 'baz') self.__WriteToFile('!foo!baz') fh = self.open('!foo!bar', 'r') self.assertEqual('x', fh.read()) @@ -5067,10 +5067,10 @@ def testReadLinkToLink(self): 'Links are not supported under Windows before Python 3.3') def testWriteLinkToLink(self): final_target = '!foo!baz' - self.filesystem.CreateLink('!foo!bar', 'link') - self.filesystem.CreateLink('!foo!link', 'baz') + self.filesystem.symlink('!foo!bar', 'link') + self.filesystem.symlink('!foo!link', 'baz') self.__WriteToFile('!foo!bar') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') @@ -5078,27 +5078,27 @@ def testMultipleLinks(self): final_target = '!a!link1!c!link2!e' self.os.makedirs('!a!link1!c!link2') - self.filesystem.CreateLink('!a!b', 'link1') - self.assertEqual('!a!link1', self.filesystem.ResolvePath('!a!b')) - self.assertEqual('!a!link1!c', self.filesystem.ResolvePath('!a!b!c')) + self.filesystem.symlink('!a!b', 'link1') + self.assertEqual('!a!link1', self.filesystem.resolve_path('!a!b')) + self.assertEqual('!a!link1!c', self.filesystem.resolve_path('!a!b!c')) - self.filesystem.CreateLink('!a!link1!c!d', 'link2') - self.assertTrue(self.filesystem.Exists('!a!link1!c!d')) - self.assertTrue(self.filesystem.Exists('!a!b!c!d')) + self.filesystem.symlink('!a!link1!c!d', 'link2') + self.assertTrue(self.filesystem.exists('!a!link1!c!d')) + self.assertTrue(self.filesystem.exists('!a!b!c!d')) final_target = '!a!link1!c!link2!e' - self.assertFalse(self.filesystem.Exists(final_target)) + self.assertFalse(self.filesystem.exists(final_target)) self.__WriteToFile('!a!b!c!d!e') - self.assertTrue(self.filesystem.Exists(final_target)) + self.assertTrue(self.filesystem.exists(final_target)) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testUtimeLink(self): """os.utime() and os.stat() via symbolic link (issue #49)""" - self.filesystem.CreateDirectory('!foo!baz') + self.filesystem.create_dir('!foo!baz') self.__WriteToFile('!foo!baz!bip') link_name = '!foo!bar' - self.filesystem.CreateLink(link_name, '!foo!baz!bip') + self.filesystem.symlink(link_name, '!foo!baz!bip') self.os.utime(link_name, (1, 2)) st = self.os.stat(link_name) @@ -5111,20 +5111,20 @@ def testUtimeLink(self): def testTooManyLinks(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateLink('!a!loop', 'loop') - self.assertFalse(self.filesystem.Exists('!a!loop')) + self.filesystem.symlink('!a!loop', 'loop') + self.assertFalse(self.filesystem.exists('!a!loop')) def testThatDriveLettersArePreserved(self): self.filesystem.is_windows_fs = True self.assertEqual('c:!foo!bar', - self.filesystem.ResolvePath('c:!foo!!bar')) + self.filesystem.resolve_path('c:!foo!!bar')) @unittest.skipIf(sys.version_info < (2, 7, 8), 'UNC path support since Python 2.7.8') def testThatUncPathsArePreserved(self): self.filesystem.is_windows_fs = True self.assertEqual('!!foo!bar!baz', - self.filesystem.ResolvePath('!!foo!bar!baz!!')) + self.filesystem.resolve_path('!!foo!bar!baz!!')) class PathManipulationTestBase(TestCase): @@ -5133,125 +5133,124 @@ def setUp(self): class CollapsePathPipeSeparatorTest(PathManipulationTestBase): - """Tests CollapsePath (mimics os.path.normpath) using | as path separator.""" + """Tests normpath (mimics os.path.normpath) using | as path separator.""" def testEmptyPathBecomesDotPath(self): - self.assertEqual('.', self.filesystem.CollapsePath('')) + self.assertEqual('.', self.filesystem.normpath('')) def testDotPathUnchanged(self): - self.assertEqual('.', self.filesystem.CollapsePath('.')) + self.assertEqual('.', self.filesystem.normpath('.')) def testSlashesAreNotCollapsed(self): """Tests that '/' is not treated specially if the path separator is '|'. In particular, multiple slashes should not be collapsed. """ - self.assertEqual('/', self.filesystem.CollapsePath('/')) - self.assertEqual('/////', self.filesystem.CollapsePath('/////')) + self.assertEqual('/', self.filesystem.normpath('/')) + self.assertEqual('/////', self.filesystem.normpath('/////')) def testRootPath(self): - self.assertEqual('|', self.filesystem.CollapsePath('|')) + self.assertEqual('|', self.filesystem.normpath('|')) def testMultipleSeparatorsCollapsedIntoRootPath(self): - self.assertEqual('|', self.filesystem.CollapsePath('|||||')) + self.assertEqual('|', self.filesystem.normpath('|||||')) def testAllDotPathsRemovedButOne(self): - self.assertEqual('.', self.filesystem.CollapsePath('.|.|.|.')) + self.assertEqual('.', self.filesystem.normpath('.|.|.|.')) def testAllDotPathsRemovedIfAnotherPathComponentExists(self): - self.assertEqual('|', self.filesystem.CollapsePath('|.|.|.|')) - self.assertEqual('foo|bar', - self.filesystem.CollapsePath('foo|.|.|.|bar')) + self.assertEqual('|', self.filesystem.normpath('|.|.|.|')) + self.assertEqual('foo|bar', self.filesystem.normpath('foo|.|.|.|bar')) def testIgnoresUpLevelReferencesStartingFromRoot(self): - self.assertEqual('|', self.filesystem.CollapsePath('|..|..|..|')) + self.assertEqual('|', self.filesystem.normpath('|..|..|..|')) self.assertEqual( - '|', self.filesystem.CollapsePath('|..|..|foo|bar|..|..|')) + '|', self.filesystem.normpath('|..|..|foo|bar|..|..|')) self.filesystem.is_windows_fs = False # shall not be handled as UNC path - self.assertEqual('|', self.filesystem.CollapsePath('||..|.|..||')) + self.assertEqual('|', self.filesystem.normpath('||..|.|..||')) def testConservesUpLevelReferencesStartingFromCurrentDirectory(self): self.assertEqual( - '..|..', self.filesystem.CollapsePath('..|foo|bar|..|..|..')) + '..|..', self.filesystem.normpath('..|foo|bar|..|..|..')) def testCombineDotAndUpLevelReferencesInAbsolutePath(self): self.assertEqual( - '|yes', self.filesystem.CollapsePath('|||||.|..|||yes|no|..|.|||')) + '|yes', self.filesystem.normpath('|||||.|..|||yes|no|..|.|||')) def testDotsInPathCollapsesToLastPath(self): self.assertEqual( - 'bar', self.filesystem.CollapsePath('foo|..|bar')) + 'bar', self.filesystem.normpath('foo|..|bar')) self.assertEqual( - 'bar', self.filesystem.CollapsePath('foo|..|yes|..|no|..|bar')) + 'bar', self.filesystem.normpath('foo|..|yes|..|no|..|bar')) class SplitPathTest(PathManipulationTestBase): - """Tests SplitPath (which mimics os.path.split) using | as path separator.""" + """Tests splitpath (which mimics os.path.splitpath) using | as path separator.""" def testEmptyPath(self): - self.assertEqual(('', ''), self.filesystem.SplitPath('')) + self.assertEqual(('', ''), self.filesystem.splitpath('')) def testNoSeparators(self): - self.assertEqual(('', 'ab'), self.filesystem.SplitPath('ab')) + self.assertEqual(('', 'ab'), self.filesystem.splitpath('ab')) def testSlashesDoNotSplit(self): """Tests that '/' is not treated specially if the path separator is '|'.""" - self.assertEqual(('', 'a/b'), self.filesystem.SplitPath('a/b')) + self.assertEqual(('', 'a/b'), self.filesystem.splitpath('a/b')) def testEliminateTrailingSeparatorsFromHead(self): - self.assertEqual(('a', 'b'), self.filesystem.SplitPath('a|b')) - self.assertEqual(('a', 'b'), self.filesystem.SplitPath('a|||b')) - self.assertEqual(('|a', 'b'), self.filesystem.SplitPath('|a||b')) - self.assertEqual(('a|b', 'c'), self.filesystem.SplitPath('a|b|c')) - self.assertEqual(('|a|b', 'c'), self.filesystem.SplitPath('|a|b|c')) + self.assertEqual(('a', 'b'), self.filesystem.splitpath('a|b')) + self.assertEqual(('a', 'b'), self.filesystem.splitpath('a|||b')) + self.assertEqual(('|a', 'b'), self.filesystem.splitpath('|a||b')) + self.assertEqual(('a|b', 'c'), self.filesystem.splitpath('a|b|c')) + self.assertEqual(('|a|b', 'c'), self.filesystem.splitpath('|a|b|c')) def testRootSeparatorIsNotStripped(self): - self.assertEqual(('|', ''), self.filesystem.SplitPath('|||')) - self.assertEqual(('|', 'a'), self.filesystem.SplitPath('|a')) - self.assertEqual(('|', 'a'), self.filesystem.SplitPath('|||a')) + self.assertEqual(('|', ''), self.filesystem.splitpath('|||')) + self.assertEqual(('|', 'a'), self.filesystem.splitpath('|a')) + self.assertEqual(('|', 'a'), self.filesystem.splitpath('|||a')) def testEmptyTailIfPathEndsInSeparator(self): - self.assertEqual(('a|b', ''), self.filesystem.SplitPath('a|b|')) + self.assertEqual(('a|b', ''), self.filesystem.splitpath('a|b|')) def testEmptyPathComponentsArePreservedInHead(self): - self.assertEqual(('|a||b', 'c'), self.filesystem.SplitPath('|a||b||c')) + self.assertEqual(('|a||b', 'c'), self.filesystem.splitpath('|a||b||c')) class JoinPathTest(PathManipulationTestBase): """Tests JoinPath (which mimics os.path.join) using | as path separator.""" def testOneEmptyComponent(self): - self.assertEqual('', self.filesystem.JoinPaths('')) + self.assertEqual('', self.filesystem.joinpaths('')) def testMultipleEmptyComponents(self): - self.assertEqual('', self.filesystem.JoinPaths('', '', '')) + self.assertEqual('', self.filesystem.joinpaths('', '', '')) def testSeparatorsNotStrippedFromSingleComponent(self): - self.assertEqual('||a||', self.filesystem.JoinPaths('||a||')) + self.assertEqual('||a||', self.filesystem.joinpaths('||a||')) def testOneSeparatorAddedBetweenComponents(self): self.assertEqual('a|b|c|d', - self.filesystem.JoinPaths('a', 'b', 'c', 'd')) + self.filesystem.joinpaths('a', 'b', 'c', 'd')) def testNoSeparatorAddedForComponentsEndingInSeparator(self): - self.assertEqual('a|b|c', self.filesystem.JoinPaths('a|', 'b|', 'c')) + self.assertEqual('a|b|c', self.filesystem.joinpaths('a|', 'b|', 'c')) self.assertEqual('a|||b|||c', - self.filesystem.JoinPaths('a|||', 'b|||', 'c')) + self.filesystem.joinpaths('a|||', 'b|||', 'c')) def testComponentsPrecedingAbsoluteComponentAreIgnored(self): self.assertEqual('|c|d', - self.filesystem.JoinPaths('a', '|b', '|c', 'd')) + self.filesystem.joinpaths('a', '|b', '|c', 'd')) def testOneSeparatorAddedForTrailingEmptyComponents(self): - self.assertEqual('a|', self.filesystem.JoinPaths('a', '')) - self.assertEqual('a|', self.filesystem.JoinPaths('a', '', '')) + self.assertEqual('a|', self.filesystem.joinpaths('a', '')) + self.assertEqual('a|', self.filesystem.joinpaths('a', '', '')) def testNoSeparatorAddedForLeadingEmptyComponents(self): - self.assertEqual('a', self.filesystem.JoinPaths('', 'a')) + self.assertEqual('a', self.filesystem.joinpaths('', 'a')) def testInternalEmptyComponentsIgnored(self): - self.assertEqual('a|b', self.filesystem.JoinPaths('a', '', 'b')) - self.assertEqual('a|b|', self.filesystem.JoinPaths('a|', '', 'b|')) + self.assertEqual('a|b', self.filesystem.joinpaths('a', '', 'b')) + self.assertEqual('a|b|', self.filesystem.joinpaths('a|', '', 'b|')) class PathSeparatorTest(TestCase): @@ -5268,24 +5267,26 @@ def setUp(self): self.filesystem.is_case_sensitive = False def testNormalizeCase(self): - self.filesystem.CreateFile('/Foo/Bar') - self.assertEqual('/Foo/Bar', self.filesystem.NormalizeCase('/foo/bar')) - self.assertEqual('/Foo/Bar', self.filesystem.NormalizeCase('/FOO/BAR')) + self.filesystem.create_file('/Foo/Bar') + self.assertEqual('/Foo/Bar', + self.filesystem._original_path('/foo/bar')) + self.assertEqual('/Foo/Bar', + self.filesystem._original_path('/FOO/BAR')) def testNormalizeCaseForDrive(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateFile('C:/Foo/Bar') + self.filesystem.create_file('C:/Foo/Bar') self.assertEqual('C:/Foo/Bar', - self.filesystem.NormalizeCase('c:/foo/bar')) + self.filesystem._original_path('c:/foo/bar')) self.assertEqual('C:/Foo/Bar', - self.filesystem.NormalizeCase('C:/FOO/BAR')) + self.filesystem._original_path('C:/FOO/BAR')) def testNormalizeCaseForNonExistingFile(self): - self.filesystem.CreateDirectory('/Foo/Bar') + self.filesystem.create_dir('/Foo/Bar') self.assertEqual('/Foo/Bar/baz', - self.filesystem.NormalizeCase('/foo/bar/baz')) + self.filesystem._original_path('/foo/bar/baz')) self.assertEqual('/Foo/Bar/BAZ', - self.filesystem.NormalizeCase('/FOO/BAR/BAZ')) + self.filesystem._original_path('/FOO/BAR/BAZ')) @unittest.skipIf(not TestCase.is_windows, 'Regression test for Windows problem only') @@ -5296,7 +5297,7 @@ def testNormalizeCaseForLazilyAddedEmptyFile(self): filesystem.add_real_directory(real_dir_path) initPyPath = os.path.join(real_dir_path, '__init__.py') self.assertEqual(initPyPath, - filesystem.NormalizeCase(initPyPath.upper())) + filesystem._original_path(initPyPath.upper())) class AlternativePathSeparatorTest(TestCase): @@ -5320,17 +5321,17 @@ def testAltSep(self): self.assertEqual('?', fake_os.path.altsep) def testCollapsePathWithMixedSeparators(self): - self.assertEqual('!foo!bar', self.filesystem.CollapsePath('!foo??bar')) + self.assertEqual('!foo!bar', self.filesystem.normpath('!foo??bar')) def testNormalizePathWithMixedSeparators(self): path = 'foo?..?bar' - self.assertEqual('!bar', self.filesystem.NormalizePath(path)) + self.assertEqual('!bar', self.filesystem.absnormpath(path)) def testExistsWithMixedSeparators(self): - self.filesystem.CreateFile('?foo?bar?baz') - self.filesystem.CreateFile('!foo!bar!xyzzy!plugh') - self.assertTrue(self.filesystem.Exists('!foo!bar!baz')) - self.assertTrue(self.filesystem.Exists('?foo?bar?xyzzy?plugh')) + self.filesystem.create_file('?foo?bar?baz') + self.filesystem.create_file('!foo!bar!xyzzy!plugh') + self.assertTrue(self.filesystem.exists('!foo!bar!baz')) + self.assertTrue(self.filesystem.exists('?foo?bar?xyzzy?plugh')) class DriveLetterSupportTest(TestCase): @@ -5347,76 +5348,76 @@ def testInitialValue(self): def testCollapsePath(self): self.assertEqual('c:!foo!bar', - self.filesystem.CollapsePath('c:!!foo!!bar')) + self.filesystem.normpath('c:!!foo!!bar')) @unittest.skipIf(sys.version_info < (2, 7, 8), 'UNC path support since Python 2.7.8') def testCollapseUncPath(self): self.assertEqual('!!foo!bar!baz', - self.filesystem.CollapsePath('!!foo!bar!!baz!!')) + self.filesystem.normpath('!!foo!bar!!baz!!')) def testNormalizePathStr(self): self.filesystem.cwd = u'' self.assertEqual(u'c:!foo!bar', - self.filesystem.NormalizePath(u'c:!foo!!bar')) + self.filesystem.absnormpath(u'c:!foo!!bar')) self.filesystem.cwd = u'c:!foo' - self.assertEqual(u'c:!foo!bar', self.filesystem.NormalizePath(u'bar')) + self.assertEqual(u'c:!foo!bar', self.filesystem.absnormpath(u'bar')) def testNormalizePathBytes(self): self.filesystem.cwd = b'' self.assertEqual(b'c:!foo!bar', - self.filesystem.NormalizePath(b'c:!foo!!bar')) + self.filesystem.absnormpath(b'c:!foo!!bar')) self.filesystem.cwd = b'c:!foo' - self.assertEqual(b'c:!foo!bar', self.filesystem.NormalizePath(b'bar')) + self.assertEqual(b'c:!foo!bar', self.filesystem.absnormpath(b'bar')) def testSplitPathStr(self): self.assertEqual((u'c:!foo', u'bar'), - self.filesystem.SplitPath(u'c:!foo!bar')) - self.assertEqual((u'c:', u'foo'), self.filesystem.SplitPath(u'c:!foo')) + self.filesystem.splitpath(u'c:!foo!bar')) + self.assertEqual((u'c:', u'foo'), self.filesystem.splitpath(u'c:!foo')) def testSplitPathBytes(self): self.assertEqual((b'c:!foo', b'bar'), - self.filesystem.SplitPath(b'c:!foo!bar')) - self.assertEqual((b'c:', b'foo'), self.filesystem.SplitPath(b'c:!foo')) + self.filesystem.splitpath(b'c:!foo!bar')) + self.assertEqual((b'c:', b'foo'), self.filesystem.splitpath(b'c:!foo')) def testCharactersBeforeRootIgnoredInJoinPaths(self): - self.assertEqual('c:d', self.filesystem.JoinPaths('b', 'c:', 'd')) + self.assertEqual('c:d', self.filesystem.joinpaths('b', 'c:', 'd')) def testResolvePath(self): self.assertEqual('c:!foo!bar', - self.filesystem.ResolvePath('c:!foo!bar')) + self.filesystem.resolve_path('c:!foo!bar')) def testGetPathComponents(self): self.assertEqual(['c:', 'foo', 'bar'], - self.filesystem.GetPathComponents('c:!foo!bar')) - self.assertEqual(['c:'], self.filesystem.GetPathComponents('c:')) + self.filesystem._path_components('c:!foo!bar')) + self.assertEqual(['c:'], self.filesystem._path_components('c:')) def testSplitDriveStr(self): self.assertEqual((u'c:', u'!foo!bar'), - self.filesystem.SplitDrive(u'c:!foo!bar')) + self.filesystem.splitdrive(u'c:!foo!bar')) self.assertEqual((u'', u'!foo!bar'), - self.filesystem.SplitDrive(u'!foo!bar')) + self.filesystem.splitdrive(u'!foo!bar')) self.assertEqual((u'c:', u'foo!bar'), - self.filesystem.SplitDrive(u'c:foo!bar')) + self.filesystem.splitdrive(u'c:foo!bar')) self.assertEqual((u'', u'foo!bar'), - self.filesystem.SplitDrive(u'foo!bar')) + self.filesystem.splitdrive(u'foo!bar')) def testSplitDriveBytes(self): self.assertEqual((b'c:', b'!foo!bar'), - self.filesystem.SplitDrive(b'c:!foo!bar')) + self.filesystem.splitdrive(b'c:!foo!bar')) self.assertEqual((b'', b'!foo!bar'), - self.filesystem.SplitDrive(b'!foo!bar')) + self.filesystem.splitdrive(b'!foo!bar')) @unittest.skipIf(sys.version_info < (2, 7, 8), 'UNC path support since Python 2.7.8') def testSplitDriveWithUncPath(self): self.assertEqual(('!!foo!bar', '!baz'), - self.filesystem.SplitDrive('!!foo!bar!baz')) - self.assertEqual(('', '!!foo'), self.filesystem.SplitDrive('!!foo')) + self.filesystem.splitdrive('!!foo!bar!baz')) + self.assertEqual(('', '!!foo'), self.filesystem.splitdrive('!!foo')) self.assertEqual(('', '!!foo!!bar'), - self.filesystem.SplitDrive('!!foo!!bar')) + self.filesystem.splitdrive('!!foo!!bar')) self.assertEqual(('!!foo!bar', '!!'), - self.filesystem.SplitDrive('!!foo!bar!!')) + self.filesystem.splitdrive('!!foo!bar!!')) class DiskSpaceTest(TestCase): @@ -5429,7 +5430,7 @@ def testDiskUsageOnFileCreation(self): fake_open = fake_filesystem.FakeFileOpen(self.filesystem) total_size = 100 - self.filesystem.AddMountPoint('mount', total_size) + self.filesystem.add_mount_point('mount', total_size) def create_too_large_file(): with fake_open('!mount!file', 'w') as dest: @@ -5437,215 +5438,221 @@ def create_too_large_file(): self.assertRaises((OSError, IOError), create_too_large_file) - self.assertEqual(0, self.filesystem.GetDiskUsage('!mount').used) + self.assertEqual(0, self.filesystem.get_disk_usage('!mount').used) with fake_open('!mount!file', 'w') as dest: dest.write('a' * total_size) self.assertEqual(total_size, - self.filesystem.GetDiskUsage('!mount').used) + self.filesystem.get_disk_usage('!mount').used) def testFileSystemSizeAfterLargeFileCreation(self): filesystem = fake_filesystem.FakeFilesystem(path_separator='!', total_size=1024 * 1024 * 1024 * 100) - filesystem.CreateFile('!foo!baz', st_size=1024 * 1024 * 1024 * 10) + filesystem.create_file('!foo!baz', st_size=1024 * 1024 * 1024 * 10) self.assertEqual((1024 * 1024 * 1024 * 100, 1024 * 1024 * 1024 * 10, - 1024 * 1024 * 1024 * 90), filesystem.GetDiskUsage()) + 1024 * 1024 * 1024 * 90), + filesystem.get_disk_usage()) def testFileSystemSizeAfterBinaryFileCreation(self): - self.filesystem.CreateFile('!foo!bar', contents=b'xyzzy') - self.assertEqual((100, 5, 95), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', contents=b'xyzzy') + self.assertEqual((100, 5, 95), self.filesystem.get_disk_usage()) def testFileSystemSizeAfterAsciiStringFileCreation(self): - self.filesystem.CreateFile('!foo!bar', contents=u'complicated') - self.assertEqual((100, 11, 89), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', contents=u'complicated') + self.assertEqual((100, 11, 89), self.filesystem.get_disk_usage()) def testFileSystemSizeAfter2ByteUnicodeStringFileCreation(self): - self.filesystem.CreateFile('!foo!bar', contents=u'сложно', - encoding='utf-8') - self.assertEqual((100, 12, 88), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', contents=u'сложно', + encoding='utf-8') + self.assertEqual((100, 12, 88), self.filesystem.get_disk_usage()) def testFileSystemSizeAfter3ByteUnicodeStringFileCreation(self): - self.filesystem.CreateFile('!foo!bar', contents=u'複雑', - encoding='utf-8') - self.assertEqual((100, 6, 94), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', contents=u'複雑', + encoding='utf-8') + self.assertEqual((100, 6, 94), self.filesystem.get_disk_usage()) def testFileSystemSizeAfterFileDeletion(self): - self.filesystem.CreateFile('!foo!bar', contents=b'xyzzy') - self.filesystem.CreateFile('!foo!baz', st_size=20) - self.filesystem.RemoveObject('!foo!bar') - self.assertEqual((100, 20, 80), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', contents=b'xyzzy') + self.filesystem.create_file('!foo!baz', st_size=20) + self.filesystem.remove_object('!foo!bar') + self.assertEqual((100, 20, 80), self.filesystem.get_disk_usage()) def testFileSystemSizeAfterDirectoryRemoval(self): - self.filesystem.CreateFile('!foo!bar', st_size=10) - self.filesystem.CreateFile('!foo!baz', st_size=20) - self.filesystem.CreateFile('!foo1!bar', st_size=40) - self.filesystem.RemoveObject('!foo') - self.assertEqual((100, 40, 60), self.filesystem.GetDiskUsage()) + self.filesystem.create_file('!foo!bar', st_size=10) + self.filesystem.create_file('!foo!baz', st_size=20) + self.filesystem.create_file('!foo1!bar', st_size=40) + self.filesystem.remove_object('!foo') + self.assertEqual((100, 40, 60), self.filesystem.get_disk_usage()) def testCreatingFileWithFittingContent(self): - initial_usage = self.filesystem.GetDiskUsage() + initial_usage = self.filesystem.get_disk_usage() try: - self.filesystem.CreateFile('!foo!bar', contents=b'a' * 100) + self.filesystem.create_file('!foo!bar', contents=b'a' * 100) except IOError: self.fail( 'File with contents fitting into disk space could not be written.') self.assertEqual(initial_usage.used + 100, - self.filesystem.GetDiskUsage().used) + self.filesystem.get_disk_usage().used) def testCreatingFileWithContentTooLarge(self): def create_large_file(): - self.filesystem.CreateFile('!foo!bar', contents=b'a' * 101) + self.filesystem.create_file('!foo!bar', contents=b'a' * 101) - initial_usage = self.filesystem.GetDiskUsage() + initial_usage = self.filesystem.get_disk_usage() self.assertRaises(IOError, create_large_file) - self.assertEqual(initial_usage, self.filesystem.GetDiskUsage()) + self.assertEqual(initial_usage, self.filesystem.get_disk_usage()) def testCreatingFileWithFittingSize(self): - initial_usage = self.filesystem.GetDiskUsage() + initial_usage = self.filesystem.get_disk_usage() try: - self.filesystem.CreateFile('!foo!bar', st_size=100) + self.filesystem.create_file('!foo!bar', st_size=100) except IOError: self.fail( 'File with size fitting into disk space could not be written.') self.assertEqual(initial_usage.used + 100, - self.filesystem.GetDiskUsage().used) + self.filesystem.get_disk_usage().used) def testCreatingFileWithSizeTooLarge(self): - initial_usage = self.filesystem.GetDiskUsage() + initial_usage = self.filesystem.get_disk_usage() def create_large_file(): - self.filesystem.CreateFile('!foo!bar', st_size=101) + self.filesystem.create_file('!foo!bar', st_size=101) self.assertRaises(IOError, create_large_file) - self.assertEqual(initial_usage, self.filesystem.GetDiskUsage()) + self.assertEqual(initial_usage, self.filesystem.get_disk_usage()) def testResizeFileWithFittingSize(self): - file_object = self.filesystem.CreateFile('!foo!bar', st_size=50) + file_object = self.filesystem.create_file('!foo!bar', st_size=50) try: - file_object.SetLargeFileSize(100) - file_object.SetContents(b'a' * 100) + file_object.set_large_file_size(100) + file_object.set_contents(b'a' * 100) except IOError: self.fail( 'Resizing file failed although disk space was sufficient.') def testResizeFileWithSizeTooLarge(self): - file_object = self.filesystem.CreateFile('!foo!bar', st_size=50) - self.assertRaisesIOError(errno.ENOSPC, file_object.SetLargeFileSize, + file_object = self.filesystem.create_file('!foo!bar', st_size=50) + self.assertRaisesIOError(errno.ENOSPC, file_object.set_large_file_size, 200) - self.assertRaisesIOError(errno.ENOSPC, file_object.SetContents, + self.assertRaisesIOError(errno.ENOSPC, file_object.set_contents, 'a' * 150) def testFileSystemSizeAfterDirectoryRename(self): - self.filesystem.CreateFile('!foo!bar', st_size=20) + self.filesystem.create_file('!foo!bar', st_size=20) self.os.rename('!foo', '!baz') - self.assertEqual(20, self.filesystem.GetDiskUsage().used) + self.assertEqual(20, self.filesystem.get_disk_usage().used) def testFileSystemSizeAfterFileRename(self): - self.filesystem.CreateFile('!foo!bar', st_size=20) + self.filesystem.create_file('!foo!bar', st_size=20) self.os.rename('!foo!bar', '!foo!baz') - self.assertEqual(20, self.filesystem.GetDiskUsage().used) + self.assertEqual(20, self.filesystem.get_disk_usage().used) @unittest.skipIf(TestCase.is_windows and sys.version_info < (3, 3), 'Links are not supported under Windows before Python 3.3') def testThatHardLinkDoesNotChangeUsedSize(self): file1_path = 'test_file1' file2_path = 'test_file2' - self.filesystem.CreateFile(file1_path, st_size=20) - self.assertEqual(20, self.filesystem.GetDiskUsage().used) + self.filesystem.create_file(file1_path, st_size=20) + self.assertEqual(20, self.filesystem.get_disk_usage().used) # creating a hard link shall not increase used space self.os.link(file1_path, file2_path) - self.assertEqual(20, self.filesystem.GetDiskUsage().used) + self.assertEqual(20, self.filesystem.get_disk_usage().used) # removing a file shall not decrease used space if a hard link still exists self.os.unlink(file1_path) - self.assertEqual(20, self.filesystem.GetDiskUsage().used) + self.assertEqual(20, self.filesystem.get_disk_usage().used) self.os.unlink(file2_path) - self.assertEqual(0, self.filesystem.GetDiskUsage().used) + self.assertEqual(0, self.filesystem.get_disk_usage().used) def testThatTheSizeOfCorrectMountPointIsUsed(self): - self.filesystem.AddMountPoint('!mount_limited', total_size=50) - self.filesystem.AddMountPoint('!mount_unlimited') + self.filesystem.add_mount_point('!mount_limited', total_size=50) + self.filesystem.add_mount_point('!mount_unlimited') self.assertRaisesIOError(errno.ENOSPC, - self.filesystem.CreateFile, + self.filesystem.create_file, '!mount_limited!foo', st_size=60) - self.assertRaisesIOError(errno.ENOSPC, self.filesystem.CreateFile, + self.assertRaisesIOError(errno.ENOSPC, self.filesystem.create_file, '!bar', st_size=110) try: - self.filesystem.CreateFile('!foo', st_size=60) - self.filesystem.CreateFile('!mount_limited!foo', st_size=40) - self.filesystem.CreateFile('!mount_unlimited!foo', st_size=1000000) + self.filesystem.create_file('!foo', st_size=60) + self.filesystem.create_file('!mount_limited!foo', st_size=40) + self.filesystem.create_file('!mount_unlimited!foo', + st_size=1000000) except IOError: self.fail( 'File with contents fitting into disk space could not be written.') def testThatDiskUsageOfCorrectMountPointIsUsed(self): - self.filesystem.AddMountPoint('!mount1', total_size=20) - self.filesystem.AddMountPoint('!mount1!bar!mount2', total_size=50) + self.filesystem.add_mount_point('!mount1', total_size=20) + self.filesystem.add_mount_point('!mount1!bar!mount2', total_size=50) - self.filesystem.CreateFile('!foo!bar', st_size=10) - self.filesystem.CreateFile('!mount1!foo!bar', st_size=10) - self.filesystem.CreateFile('!mount1!bar!mount2!foo!bar', st_size=10) + self.filesystem.create_file('!foo!bar', st_size=10) + self.filesystem.create_file('!mount1!foo!bar', st_size=10) + self.filesystem.create_file('!mount1!bar!mount2!foo!bar', st_size=10) - self.assertEqual(90, self.filesystem.GetDiskUsage('!foo').free) - self.assertEqual(10, self.filesystem.GetDiskUsage('!mount1!foo').free) - self.assertEqual(40, self.filesystem.GetDiskUsage( + self.assertEqual(90, self.filesystem.get_disk_usage('!foo').free) + self.assertEqual(10, + self.filesystem.get_disk_usage('!mount1!foo').free) + self.assertEqual(40, self.filesystem.get_disk_usage( '!mount1!bar!mount2').free) def testSetLargerDiskSize(self): - self.filesystem.AddMountPoint('!mount1', total_size=20) + self.filesystem.add_mount_point('!mount1', total_size=20) self.assertRaisesIOError(errno.ENOSPC, - self.filesystem.CreateFile, '!mount1!foo', + self.filesystem.create_file, '!mount1!foo', st_size=100) - self.filesystem.SetDiskUsage(total_size=200, path='!mount1') - self.filesystem.CreateFile('!mount1!foo', st_size=100) - self.assertEqual(100, self.filesystem.GetDiskUsage('!mount1!foo').free) + self.filesystem.set_disk_usage(total_size=200, path='!mount1') + self.filesystem.create_file('!mount1!foo', st_size=100) + self.assertEqual(100, + self.filesystem.get_disk_usage('!mount1!foo').free) def testSetSmallerDiskSize(self): - self.filesystem.AddMountPoint('!mount1', total_size=200) - self.filesystem.CreateFile('!mount1!foo', st_size=100) + self.filesystem.add_mount_point('!mount1', total_size=200) + self.filesystem.create_file('!mount1!foo', st_size=100) self.assertRaisesIOError(errno.ENOSPC, - self.filesystem.SetDiskUsage, total_size=50, + self.filesystem.set_disk_usage, total_size=50, path='!mount1') - self.filesystem.SetDiskUsage(total_size=150, path='!mount1') - self.assertEqual(50, self.filesystem.GetDiskUsage('!mount1!foo').free) + self.filesystem.set_disk_usage(total_size=150, path='!mount1') + self.assertEqual(50, + self.filesystem.get_disk_usage('!mount1!foo').free) def testDiskSizeOnUnlimitedDisk(self): - self.filesystem.AddMountPoint('!mount1') - self.filesystem.CreateFile('!mount1!foo', st_size=100) - self.filesystem.SetDiskUsage(total_size=1000, path='!mount1') - self.assertEqual(900, self.filesystem.GetDiskUsage('!mount1!foo').free) + self.filesystem.add_mount_point('!mount1') + self.filesystem.create_file('!mount1!foo', st_size=100) + self.filesystem.set_disk_usage(total_size=1000, path='!mount1') + self.assertEqual(900, + self.filesystem.get_disk_usage('!mount1!foo').free) def testDiskSizeOnAutoMountedDriveOnFileCreation(self): self.filesystem.is_windows_fs = True # drive d: shall be auto-mounted and the used size adapted - self.filesystem.CreateFile('d:!foo!bar', st_size=100) - self.filesystem.SetDiskUsage(total_size=1000, path='d:') - self.assertEqual(self.filesystem.GetDiskUsage('d:!foo').free, 900) + self.filesystem.create_file('d:!foo!bar', st_size=100) + self.filesystem.set_disk_usage(total_size=1000, path='d:') + self.assertEqual(self.filesystem.get_disk_usage('d:!foo').free, 900) def testDiskSizeOnAutoMountedDriveOnDirectoryCreation(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateDirectory('d:!foo!bar') - self.filesystem.CreateFile('d:!foo!bar!baz', st_size=100) - self.filesystem.CreateFile('d:!foo!baz', st_size=100) - self.filesystem.SetDiskUsage(total_size=1000, path='d:') - self.assertEqual(self.filesystem.GetDiskUsage('d:!foo').free, 800) + self.filesystem.create_dir('d:!foo!bar') + self.filesystem.create_file('d:!foo!bar!baz', st_size=100) + self.filesystem.create_file('d:!foo!baz', st_size=100) + self.filesystem.set_disk_usage(total_size=1000, path='d:') + self.assertEqual(self.filesystem.get_disk_usage('d:!foo').free, 800) @unittest.skipIf(sys.version_info < (3, 0), 'Tests byte contents in Python3') def testCopyingPreservesByteContents(self): - source_file = self.filesystem.CreateFile('foo', contents=b'somebytes') - dest_file = self.filesystem.CreateFile('bar') - dest_file.SetContents(source_file.contents) + source_file = self.filesystem.create_file('foo', contents=b'somebytes') + dest_file = self.filesystem.create_file('bar') + dest_file.set_contents(source_file.contents) self.assertEqual(dest_file.contents, source_file.contents) @@ -5653,64 +5660,63 @@ class MountPointTest(TestCase): def setUp(self): self.filesystem = fake_filesystem.FakeFilesystem(path_separator='!', total_size=100) - self.filesystem.AddMountPoint('!foo') - self.filesystem.AddMountPoint('!bar') - self.filesystem.AddMountPoint('!foo!baz') + self.filesystem.add_mount_point('!foo') + self.filesystem.add_mount_point('!bar') + self.filesystem.add_mount_point('!foo!baz') def testThatNewMountPointsGetNewDeviceNumber(self): - self.assertEqual(1, self.filesystem.GetObject('!').st_dev) - self.assertEqual(2, self.filesystem.GetObject('!foo').st_dev) - self.assertEqual(3, self.filesystem.GetObject('!bar').st_dev) - self.assertEqual(4, self.filesystem.GetObject('!foo!baz').st_dev) + self.assertEqual(1, self.filesystem.get_object('!').st_dev) + self.assertEqual(2, self.filesystem.get_object('!foo').st_dev) + self.assertEqual(3, self.filesystem.get_object('!bar').st_dev) + self.assertEqual(4, self.filesystem.get_object('!foo!baz').st_dev) def testThatNewDirectoriesGetCorrectDeviceNumber(self): - self.assertEqual(1, - self.filesystem.CreateDirectory('!foo1!bar').st_dev) - self.assertEqual(2, self.filesystem.CreateDirectory('!foo!bar').st_dev) - self.assertEqual(4, self.filesystem.CreateDirectory( - '!foo!baz!foo!bar').st_dev) + self.assertEqual(1, self.filesystem.create_dir('!foo1!bar').st_dev) + self.assertEqual(2, self.filesystem.create_dir('!foo!bar').st_dev) + self.assertEqual(4, + self.filesystem.create_dir('!foo!baz!foo!bar').st_dev) def testThatNewFilesGetCorrectDeviceNumber(self): - self.assertEqual(1, self.filesystem.CreateFile('!foo1!bar').st_dev) - self.assertEqual(2, self.filesystem.CreateFile('!foo!bar').st_dev) - self.assertEqual(4, - self.filesystem.CreateFile('!foo!baz!foo!bar').st_dev) + self.assertEqual(1, self.filesystem.create_file('!foo1!bar').st_dev) + self.assertEqual(2, self.filesystem.create_file('!foo!bar').st_dev) + self.assertEqual(4, self.filesystem.create_file( + '!foo!baz!foo!bar').st_dev) def testThatMountPointCannotBeAddedTwice(self): - self.assertRaisesOSError(errno.EEXIST, self.filesystem.AddMountPoint, + self.assertRaisesOSError(errno.EEXIST, self.filesystem.add_mount_point, '!foo') - self.assertRaisesOSError(errno.EEXIST, self.filesystem.AddMountPoint, + self.assertRaisesOSError(errno.EEXIST, self.filesystem.add_mount_point, '!foo!') def testThatDrivesAreAutoMounted(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateDirectory('d:!foo!bar') - self.filesystem.CreateFile('d:!foo!baz') - self.filesystem.CreateFile('z:!foo!baz') - self.assertEqual(5, self.filesystem.GetObject('d:').st_dev) - self.assertEqual(5, self.filesystem.GetObject('d:!foo!bar').st_dev) - self.assertEqual(5, self.filesystem.GetObject('d:!foo!baz').st_dev) - self.assertEqual(6, self.filesystem.GetObject('z:!foo!baz').st_dev) + self.filesystem.create_dir('d:!foo!bar') + self.filesystem.create_file('d:!foo!baz') + self.filesystem.create_file('z:!foo!baz') + self.assertEqual(5, self.filesystem.get_object('d:').st_dev) + self.assertEqual(5, self.filesystem.get_object('d:!foo!bar').st_dev) + self.assertEqual(5, self.filesystem.get_object('d:!foo!baz').st_dev) + self.assertEqual(6, self.filesystem.get_object('z:!foo!baz').st_dev) def testThatDrivesAreAutoMountedCaseInsensitive(self): self.filesystem.is_windows_fs = True self.filesystem.is_case_sensitive = False - self.filesystem.CreateDirectory('D:!foo!bar') - self.filesystem.CreateFile('e:!foo!baz') - self.assertEqual(5, self.filesystem.GetObject('D:').st_dev) - self.assertEqual(5, self.filesystem.GetObject('d:!foo!bar').st_dev) - self.assertEqual(6, self.filesystem.GetObject('e:!foo').st_dev) - self.assertEqual(6, self.filesystem.GetObject('E:!Foo!Baz').st_dev) + self.filesystem.create_dir('D:!foo!bar') + self.filesystem.create_file('e:!foo!baz') + self.assertEqual(5, self.filesystem.get_object('D:').st_dev) + self.assertEqual(5, self.filesystem.get_object('d:!foo!bar').st_dev) + self.assertEqual(6, self.filesystem.get_object('e:!foo').st_dev) + self.assertEqual(6, self.filesystem.get_object('E:!Foo!Baz').st_dev) @unittest.skipIf(sys.version_info < (2, 7, 8), 'UNC path support since Python 2.7.8') def testThatUncPathsAreAutoMounted(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateDirectory('!!foo!bar!baz') - self.filesystem.CreateFile('!!foo!bar!bip!bop') - self.assertEqual(5, self.filesystem.GetObject('!!foo!bar').st_dev) - self.assertEqual(5, - self.filesystem.GetObject('!!foo!bar!bip!bop').st_dev) + self.filesystem.create_dir('!!foo!bar!baz') + self.filesystem.create_file('!!foo!bar!bip!bop') + self.assertEqual(5, self.filesystem.get_object('!!foo!bar').st_dev) + self.assertEqual(5, self.filesystem.get_object( + '!!foo!bar!bip!bop').st_dev) class RealFileSystemAccessTest(TestCase): @@ -5723,30 +5729,30 @@ def testAddNonExistingRealFileRaises(self): nonexisting_path = os.path.join('nonexisting', 'test.txt') self.assertRaises(OSError, self.filesystem.add_real_file, nonexisting_path) - self.assertFalse(self.filesystem.Exists(nonexisting_path)) + self.assertFalse(self.filesystem.exists(nonexisting_path)) def testAddNonExistingRealDirectoryRaises(self): nonexisting_path = '/nonexisting' self.assertRaisesIOError(errno.ENOENT, self.filesystem.add_real_directory, nonexisting_path) - self.assertFalse(self.filesystem.Exists(nonexisting_path)) + self.assertFalse(self.filesystem.exists(nonexisting_path)) def testExistingFakeFileRaises(self): real_file_path = __file__ - self.filesystem.CreateFile(real_file_path) + self.filesystem.create_file(real_file_path) self.assertRaisesOSError(errno.EEXIST, self.filesystem.add_real_file, real_file_path) def testExistingFakeDirectoryRaises(self): real_dir_path = os.path.dirname(__file__) - self.filesystem.CreateDirectory(real_dir_path) + self.filesystem.create_dir(real_dir_path) self.assertRaisesOSError(errno.EEXIST, self.filesystem.add_real_directory, real_dir_path) def checkFakeFileStat(self, fake_file, real_file_path): - self.assertTrue(self.filesystem.Exists(real_file_path)) + self.assertTrue(self.filesystem.exists(real_file_path)) real_stat = os.stat(real_file_path) self.assertIsNone(fake_file._byte_contents) self.assertEqual(fake_file.st_size, real_stat.st_size) @@ -5798,14 +5804,14 @@ def testAddExistingRealFileReadWrite(self): def testAddExistingRealDirectoryReadOnly(self): real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') self.filesystem.add_real_directory(real_dir_path) - self.assertTrue(self.filesystem.Exists(real_dir_path)) - self.assertTrue(self.filesystem.Exists( + self.assertTrue(self.filesystem.exists(real_dir_path)) + self.assertTrue(self.filesystem.exists( os.path.join(real_dir_path, 'fake_filesystem.py'))) - self.assertTrue(self.filesystem.Exists( + self.assertTrue(self.filesystem.exists( os.path.join(real_dir_path, 'fake_pathlib.py'))) file_path = os.path.join(real_dir_path, 'fake_filesystem_shutil.py') - fake_file = self.filesystem.ResolveObject(file_path) + fake_file = self.filesystem.resolve(file_path) self.checkFakeFileStat(fake_file, file_path) self.checkReadOnlyFile(fake_file, file_path) @@ -5813,63 +5819,63 @@ def testAddExistingRealDirectoryTree(self): real_dir_path = os.path.dirname(__file__) self.filesystem.add_real_directory(real_dir_path) self.assertTrue( - self.filesystem.Exists( + self.filesystem.exists( os.path.join(real_dir_path, 'fake_filesystem_test.py'))) self.assertTrue( - self.filesystem.Exists( + self.filesystem.exists( os.path.join(real_dir_path, 'pyfakefs', 'fake_filesystem.py'))) self.assertTrue( - self.filesystem.Exists( + self.filesystem.exists( os.path.join(real_dir_path, 'pyfakefs', '__init__.py'))) def testGetObjectFromLazilyAddedRealDirectory(self): self.filesystem.is_case_sensitive = True real_dir_path = os.path.dirname(__file__) self.filesystem.add_real_directory(real_dir_path) - self.assertTrue(self.filesystem.GetObject( + self.assertTrue(self.filesystem.get_object( os.path.join(real_dir_path, 'pyfakefs', 'fake_filesystem.py'))) self.assertTrue( - self.filesystem.GetObject( + self.filesystem.get_object( os.path.join(real_dir_path, 'pyfakefs', '__init__.py'))) def testAddExistingRealDirectoryLazily(self): disk_size = 1024 * 1024 * 1024 real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') - self.filesystem.SetDiskUsage(disk_size, real_dir_path) + self.filesystem.set_disk_usage(disk_size, real_dir_path) self.filesystem.add_real_directory(real_dir_path) # the directory contents have not been read, the the disk usage has not changed self.assertEqual(disk_size, - self.filesystem.GetDiskUsage(real_dir_path).free) + self.filesystem.get_disk_usage(real_dir_path).free) # checking for existence shall read the directory contents self.assertTrue( - self.filesystem.GetObject( + self.filesystem.get_object( os.path.join(real_dir_path, 'fake_filesystem.py'))) # so now the free disk space shall have decreased self.assertGreater(disk_size, - self.filesystem.GetDiskUsage(real_dir_path).free) + self.filesystem.get_disk_usage(real_dir_path).free) def testAddExistingRealDirectoryNotLazily(self): disk_size = 1024 * 1024 * 1024 real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') - self.filesystem.SetDiskUsage(disk_size, real_dir_path) + self.filesystem.set_disk_usage(disk_size, real_dir_path) self.filesystem.add_real_directory(real_dir_path, lazy_read=False) # the directory has been read, so the file sizes have been subtracted from the free space self.assertGreater(disk_size, - self.filesystem.GetDiskUsage(real_dir_path).free) + self.filesystem.get_disk_usage(real_dir_path).free) def testAddExistingRealDirectoryReadWrite(self): real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') self.filesystem.add_real_directory(real_dir_path, read_only=False) - self.assertTrue(self.filesystem.Exists(real_dir_path)) - self.assertTrue(self.filesystem.Exists( + self.assertTrue(self.filesystem.exists(real_dir_path)) + self.assertTrue(self.filesystem.exists( os.path.join(real_dir_path, 'fake_filesystem.py'))) - self.assertTrue(self.filesystem.Exists( + self.assertTrue(self.filesystem.exists( os.path.join(real_dir_path, 'fake_pathlib.py'))) file_path = os.path.join(real_dir_path, 'pytest_plugin.py') - fake_file = self.filesystem.ResolveObject(file_path) + fake_file = self.filesystem.resolve(file_path) self.checkFakeFileStat(fake_file, file_path) self.checkWritableFile(fake_file, file_path) @@ -5878,13 +5884,13 @@ def testAddExistingRealPathsReadOnly(self): real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') self.filesystem.add_real_paths([real_file_path, real_dir_path]) - fake_file = self.filesystem.ResolveObject(real_file_path) + fake_file = self.filesystem.resolve(real_file_path) self.checkFakeFileStat(fake_file, real_file_path) self.checkReadOnlyFile(fake_file, real_file_path) real_file_path = os.path.join(real_dir_path, 'fake_filesystem_shutil.py') - fake_file = self.filesystem.ResolveObject(real_file_path) + fake_file = self.filesystem.resolve(real_file_path) self.checkFakeFileStat(fake_file, real_file_path) self.checkReadOnlyFile(fake_file, real_file_path) @@ -5894,12 +5900,12 @@ def testAddExistingRealPathsReadWrite(self): self.filesystem.add_real_paths([real_file_path, real_dir_path], read_only=False) - fake_file = self.filesystem.ResolveObject(real_file_path) + fake_file = self.filesystem.resolve(real_file_path) self.checkFakeFileStat(fake_file, real_file_path) self.checkWritableFile(fake_file, real_file_path) real_file_path = os.path.join(real_dir_path, 'fake_pathlib.py') - fake_file = self.filesystem.ResolveObject(real_file_path) + fake_file = self.filesystem.resolve(real_file_path) self.checkFakeFileStat(fake_file, real_file_path) self.checkWritableFile(fake_file, real_file_path) diff --git a/fake_filesystem_unittest_test.py b/fake_filesystem_unittest_test.py index e11a7b1b..dbdda7a2 100755 --- a/fake_filesystem_unittest_test.py +++ b/fake_filesystem_unittest_test.py @@ -52,7 +52,7 @@ def test_file(self): self.assertFalse(os.path.exists('/fake_file.txt')) with file('/fake_file.txt', 'w') as f: f.write("This test file was created using the file() function.\n") - self.assertTrue(self.fs.Exists('/fake_file.txt')) + self.assertTrue(self.fs.exists('/fake_file.txt')) with file('/fake_file.txt') as f: content = f.read() self.assertEqual(content, @@ -63,7 +63,7 @@ def test_open(self): self.assertFalse(os.path.exists('/fake_file.txt')) with open('/fake_file.txt', 'w') as f: f.write("This test file was created using the open() function.\n") - self.assertTrue(self.fs.Exists('/fake_file.txt')) + self.assertTrue(self.fs.exists('/fake_file.txt')) with open('/fake_file.txt') as f: content = f.read() self.assertEqual(content, @@ -74,7 +74,7 @@ def test_io_open(self): self.assertFalse(os.path.exists('/fake_file.txt')) with io.open('/fake_file.txt', 'w') as f: f.write("This test file was created using the io.open() function.\n") - self.assertTrue(self.fs.Exists('/fake_file.txt')) + self.assertTrue(self.fs.exists('/fake_file.txt')) with open('/fake_file.txt') as f: content = f.read() self.assertEqual(content, @@ -82,22 +82,22 @@ def test_io_open(self): def test_os(self): """Fake os module is bound""" - self.assertFalse(self.fs.Exists('/test/dir1/dir2')) + self.assertFalse(self.fs.exists('/test/dir1/dir2')) os.makedirs('/test/dir1/dir2') - self.assertTrue(self.fs.Exists('/test/dir1/dir2')) + self.assertTrue(self.fs.exists('/test/dir1/dir2')) def test_glob(self): """Fake glob module is bound""" is_windows = sys.platform.startswith('win') self.assertEqual(glob.glob('/test/dir1/dir*'), []) - self.fs.CreateDirectory('/test/dir1/dir2a') + self.fs.create_dir('/test/dir1/dir2a') matching_paths = glob.glob('/test/dir1/dir*') if is_windows: self.assertEqual(matching_paths, [r'\test\dir1\dir2a']) else: self.assertEqual(matching_paths, ['/test/dir1/dir2a']) - self.fs.CreateDirectory('/test/dir1/dir2b') + self.fs.create_dir('/test/dir1/dir2b') matching_paths = sorted(glob.glob('/test/dir1/dir*')) if is_windows: self.assertEqual(matching_paths, [r'\test\dir1\dir2a', r'\test\dir1\dir2b']) @@ -106,13 +106,13 @@ def test_glob(self): def test_shutil(self): """Fake shutil module is bound""" - self.fs.CreateDirectory('/test/dir1/dir2a') - self.fs.CreateDirectory('/test/dir1/dir2b') - self.assertTrue(self.fs.Exists('/test/dir1/dir2b')) - self.assertTrue(self.fs.Exists('/test/dir1/dir2a')) + self.fs.create_dir('/test/dir1/dir2a') + self.fs.create_dir('/test/dir1/dir2b') + self.assertTrue(self.fs.exists('/test/dir1/dir2b')) + self.assertTrue(self.fs.exists('/test/dir1/dir2a')) shutil.rmtree('/test/dir1') - self.assertFalse(self.fs.Exists('/test/dir1')) + self.assertFalse(self.fs.exists('/test/dir1')) @unittest.skipIf(sys.version_info < (3, 4), "pathlib new in Python 3.4") def test_fakepathlib(self): @@ -121,9 +121,9 @@ def test_fakepathlib(self): f.write('text') is_windows = sys.platform.startswith('win') if is_windows: - self.assertTrue(self.fs.Exists(r'\fake_file.txt')) + self.assertTrue(self.fs.exists(r'\fake_file.txt')) else: - self.assertTrue(self.fs.Exists('/fake_file.txt')) + self.assertTrue(self.fs.exists('/fake_file.txt')) class TestImportAsOtherName(fake_filesystem_unittest.TestCase): @@ -137,8 +137,8 @@ def setUp(self): def testFileExists(self): file_path = '/foo/bar/baz' - self.fs.CreateFile(file_path) - self.assertTrue(self.fs.Exists(file_path)) + self.fs.create_file(file_path) + self.assertTrue(self.fs.exists(file_path)) self.assertTrue(check_if_exists(file_path)) @@ -232,10 +232,10 @@ def testCopyRealFile(self): def testCopyRealFileDeprecatedArguments(self): '''Deprecated copyRealFile() arguments''' real_file_path = __file__ - self.assertFalse(self.fs.Exists(real_file_path)) + self.assertFalse(self.fs.exists(real_file_path)) # Specify redundant fake file path self.copyRealFile(real_file_path, real_file_path) - self.assertTrue(self.fs.Exists(real_file_path)) + self.assertTrue(self.fs.exists(real_file_path)) # Test deprecated argument values with self.assertRaises(ValueError): @@ -250,7 +250,7 @@ def testAddRealFile(self): # are done in fake_filesystem_test.RealFileSystemAccessTest real_file_path = __file__ fake_file = self.fs.add_real_file(real_file_path) - self.assertTrue(self.fs.Exists(real_file_path)) + self.assertTrue(self.fs.exists(real_file_path)) self.assertIsNone(fake_file._byte_contents) self.assertEqual(self.real_byte_contents, fake_file.byte_contents) @@ -262,8 +262,8 @@ def testAddRealDirectory(self): # Note: this test fails (add_real_directory raises) if 'genericpath' is not added to SKIPNAMES real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs') self.fs.add_real_directory(real_dir_path) - self.assertTrue(self.fs.Exists(real_dir_path)) - self.assertTrue(self.fs.Exists(os.path.join(real_dir_path, 'fake_filesystem.py'))) + self.assertTrue(self.fs.exists(real_dir_path)) + self.assertTrue(self.fs.exists(os.path.join(real_dir_path, 'fake_filesystem.py'))) if __name__ == "__main__": diff --git a/fake_filesystem_vs_real_test.py b/fake_filesystem_vs_real_test.py index b0246923..7c8112d0 100755 --- a/fake_filesystem_vs_real_test.py +++ b/fake_filesystem_vs_real_test.py @@ -108,7 +108,7 @@ def setUp(self): self.assertTrue(os.access(self.real_base, os.W_OK)) self.fake_filesystem = fake_filesystem.FakeFilesystem() - self.fake_filesystem.CreateDirectory(self.fake_base) + self.fake_filesystem.create_dir(self.fake_base) self.fake_os = fake_filesystem.FakeOsModule(self.fake_filesystem) self.fake_open = fake_filesystem.FakeFileOpen(self.fake_filesystem) self._created_files = [] diff --git a/fake_pathlib_test.py b/fake_pathlib_test.py index 4e6e4322..1109ba32 100644 --- a/fake_pathlib_test.py +++ b/fake_pathlib_test.py @@ -191,12 +191,12 @@ def setUp(self): self.filesystem.is_windows_fs = False pathlib = fake_pathlib.FakePathlibModule(self.filesystem) self.path = pathlib.Path - self.filesystem.CreateFile('/home/jane/test.py', st_size=100, st_mode=stat.S_IFREG | 0o666) - self.filesystem.CreateDirectory('/home/john') - self.filesystem.CreateLink('/john', '/home/john') - self.filesystem.CreateLink('/test.py', '/home/jane/test.py') - self.filesystem.CreateLink('/broken_dir_link', '/home/none') - self.filesystem.CreateLink('/broken_file_link', '/home/none/test.py') + self.filesystem.create_file('/home/jane/test.py', st_size=100, st_mode=stat.S_IFREG | 0o666) + self.filesystem.create_dir('/home/john') + self.filesystem.symlink('/john', '/home/john') + self.filesystem.symlink('/test.py', '/home/jane/test.py') + self.filesystem.symlink('/broken_dir_link', '/home/none') + self.filesystem.symlink('/broken_file_link', '/home/none/test.py') def test_exists(self): self.assertTrue(self.path('/home/jane/test.py').exists()) @@ -232,7 +232,7 @@ def test_is_symlink(self): self.assertTrue(self.path('/broken_file_link').is_symlink()) def test_stat(self): - file_object = self.filesystem.ResolveObject('/home/jane/test.py') + file_object = self.filesystem.resolve('/home/jane/test.py') stat_result = self.path('/test.py').stat() self.assertFalse(stat_result.st_mode & stat.S_IFDIR) @@ -243,7 +243,7 @@ def test_stat(self): self.assertEqual(stat_result[stat.ST_MTIME], int(file_object.st_mtime)) def test_lstat(self): - link_object = self.filesystem.LResolveObject('/test.py') + link_object = self.filesystem.lresolve('/test.py') stat_result = self.path('/test.py').lstat() self.assertTrue(stat_result.st_mode & stat.S_IFREG) @@ -253,15 +253,15 @@ def test_lstat(self): self.assertEqual(stat_result.st_mtime, link_object.st_mtime) def test_chmod(self): - file_object = self.filesystem.ResolveObject('/home/jane/test.py') - link_object = self.filesystem.LResolveObject('/test.py') + file_object = self.filesystem.resolve('/home/jane/test.py') + link_object = self.filesystem.lresolve('/test.py') self.path('/test.py').chmod(0o444) self.assertEqual(file_object.st_mode, stat.S_IFREG | 0o444) self.assertEqual(link_object.st_mode, stat.S_IFLNK | 0o777) def test_lchmod(self): - file_object = self.filesystem.ResolveObject('/home/jane/test.py') - link_object = self.filesystem.LResolveObject('/test.py') + file_object = self.filesystem.resolve('/home/jane/test.py') + link_object = self.filesystem.lresolve('/test.py') if not hasattr(os, "lchmod"): self.assertRaises(NotImplementedError, self.path('/test.py').lchmod, 0o444) else: @@ -271,8 +271,8 @@ def test_lchmod(self): def test_resolve(self): self.filesystem.cwd = '/home/antoine' - self.filesystem.CreateDirectory('/home/antoine/docs') - self.filesystem.CreateFile('/home/antoine/setup.py') + self.filesystem.create_dir('/home/antoine/docs') + self.filesystem.create_file('/home/antoine/setup.py') self.assertEqual(self.path().resolve(), self.path('/home/antoine')) self.assertEqual(self.path('docs/../setup.py').resolve(), @@ -286,14 +286,14 @@ def test_resolve_nonexisting_file(self): @unittest.skipIf(sys.version_info >= (3, 6), 'Changed behavior in Python 3.6') def test_resolve_file_as_parent_windows(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateFile('/a_file') + self.filesystem.create_file('/a_file') path = self.path('/a_file/this can not exist') self.assertRaises(FileNotFoundError, path.resolve) @unittest.skipIf(sys.version_info >= (3, 6), 'Changed behavior in Python 3.6') def test_resolve_file_as_parent_posix(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateFile('/a_file') + self.filesystem.create_file('/a_file') path = self.path('/a_file/this can not exist') self.assertRaises(NotADirectoryError, path.resolve) @@ -337,10 +337,10 @@ def setUp(self): self.path = pathlib.Path def test_exists(self): - self.filesystem.CreateFile('!home!jane!test.py') - self.filesystem.CreateDirectory('!home!john') - self.filesystem.CreateLink('!john', '!home!john') - self.filesystem.CreateLink('!none', '!home!none') + self.filesystem.create_file('!home!jane!test.py') + self.filesystem.create_dir('!home!john') + self.filesystem.symlink('!john', '!home!john') + self.filesystem.symlink('!none', '!home!none') self.assertTrue(self.path('!home!jane!test.py').exists()) self.assertTrue(self.path('!home!jane').exists()) @@ -349,14 +349,14 @@ def test_exists(self): self.assertFalse(self.path('!home!jane!test').exists()) def test_open(self): - self.filesystem.CreateDirectory('!foo') + self.filesystem.create_dir('!foo') self.assertRaises(OSError, self.path('!foo!bar.txt').open) self.path('!foo!bar.txt').open('w') - self.assertTrue(self.filesystem.Exists('!foo!bar.txt')) + self.assertTrue(self.filesystem.exists('!foo!bar.txt')) @unittest.skipIf(sys.version_info < (3, 5), 'New in version 3.5') def test_read_text(self): - self.filesystem.CreateFile('text_file', contents='ерунда', encoding='cyrillic') + self.filesystem.create_file('text_file', contents='ерунда', encoding='cyrillic') file_path = self.path('text_file') self.assertEqual(file_path.read_text(encoding='cyrillic'), 'ерунда') @@ -364,13 +364,13 @@ def test_read_text(self): def test_write_text(self): file_path = self.path('text_file') file_path.write_text('ανοησίες', encoding='greek') - self.assertTrue(self.filesystem.Exists('text_file')) - file_object = self.filesystem.ResolveObject('text_file') + self.assertTrue(self.filesystem.exists('text_file')) + file_object = self.filesystem.resolve('text_file') self.assertEqual(file_object.byte_contents.decode('greek'), 'ανοησίες') @unittest.skipIf(sys.version_info < (3, 5), 'New in version 3.5') def test_read_bytes(self): - self.filesystem.CreateFile('binary_file', contents=b'Binary file contents') + self.filesystem.create_file('binary_file', contents=b'Binary file contents') file_path = self.path('binary_file') self.assertEqual(file_path.read_bytes(), b'Binary file contents') @@ -378,54 +378,54 @@ def test_read_bytes(self): def test_write_bytes(self): file_path = self.path('binary_file') file_path.write_bytes(b'Binary file contents') - self.assertTrue(self.filesystem.Exists('binary_file')) - file_object = self.filesystem.ResolveObject('binary_file') + self.assertTrue(self.filesystem.exists('binary_file')) + file_object = self.filesystem.resolve('binary_file') self.assertEqual(file_object.byte_contents, b'Binary file contents') def test_rename(self): - self.filesystem.CreateFile('!foo!bar.txt', contents='test') + self.filesystem.create_file('!foo!bar.txt', contents='test') self.path('!foo!bar.txt').rename('foo!baz.txt') - self.assertFalse(self.filesystem.Exists('!foo!bar.txt')) - file_obj = self.filesystem.ResolveObject('foo!baz.txt') + self.assertFalse(self.filesystem.exists('!foo!bar.txt')) + file_obj = self.filesystem.resolve('foo!baz.txt') self.assertTrue(file_obj) self.assertEqual(file_obj.contents, 'test') def test_replace(self): - self.filesystem.CreateFile('!foo!bar.txt', contents='test') - self.filesystem.CreateFile('!bar!old.txt', contents='replaced') + self.filesystem.create_file('!foo!bar.txt', contents='test') + self.filesystem.create_file('!bar!old.txt', contents='replaced') self.path('!bar!old.txt').replace('foo!bar.txt') - self.assertFalse(self.filesystem.Exists('!bar!old.txt')) - file_obj = self.filesystem.ResolveObject('foo!bar.txt') + self.assertFalse(self.filesystem.exists('!bar!old.txt')) + file_obj = self.filesystem.resolve('foo!bar.txt') self.assertTrue(file_obj) self.assertEqual(file_obj.contents, 'replaced') def test_unlink(self): - self.filesystem.CreateFile('!foo!bar.txt', contents='test') - self.assertTrue(self.filesystem.Exists('!foo!bar.txt')) + self.filesystem.create_file('!foo!bar.txt', contents='test') + self.assertTrue(self.filesystem.exists('!foo!bar.txt')) self.path('!foo!bar.txt').unlink() - self.assertFalse(self.filesystem.Exists('!foo!bar.txt')) + self.assertFalse(self.filesystem.exists('!foo!bar.txt')) def test_touch_non_existing(self): - self.filesystem.CreateDirectory('!foo') + self.filesystem.create_dir('!foo') self.path('!foo!bar.txt').touch(mode=0o444) - file_obj = self.filesystem.ResolveObject('!foo!bar.txt') + file_obj = self.filesystem.resolve('!foo!bar.txt') self.assertTrue(file_obj) self.assertEqual(file_obj.contents, '') self.assertTrue(file_obj.st_mode, stat.S_IFREG | 0o444) def test_touch_existing(self): - self.filesystem.CreateFile('!foo!bar.txt', contents='test') + self.filesystem.create_file('!foo!bar.txt', contents='test') file_path = self.path('!foo!bar.txt') self.assertRaises(FileExistsError, file_path.touch, exist_ok=False) file_path.touch() - file_obj = self.filesystem.ResolveObject('!foo!bar.txt') + file_obj = self.filesystem.resolve('!foo!bar.txt') self.assertTrue(file_obj) self.assertEqual(file_obj.contents, 'test') @unittest.skipIf(sys.version_info < (3, 5), 'New in version 3.5') def test_samefile(self): - self.filesystem.CreateFile('!foo!bar.txt') - self.filesystem.CreateFile('!foo!baz.txt') + self.filesystem.create_file('!foo!bar.txt') + self.filesystem.create_file('!foo!baz.txt') self.assertRaises(OSError, self.path('!foo!other').samefile, '!foo!other.txt') path = self.path('!foo!bar.txt') self.assertRaises(OSError, path.samefile, '!foo!other.txt') @@ -436,72 +436,72 @@ def test_samefile(self): self.assertTrue(path.samefile(self.path('!foo!..!foo!bar.txt'))) def test_symlink_to(self): - self.filesystem.CreateFile('!foo!bar.txt') + self.filesystem.create_file('!foo!bar.txt') path = self.path('!link_to_bar') path.symlink_to('!foo!bar.txt') - self.assertTrue(self.filesystem.Exists('!link_to_bar')) - file_obj = self.filesystem.ResolveObject('!foo!bar.txt') - linked_file_obj = self.filesystem.ResolveObject('!link_to_bar') + self.assertTrue(self.filesystem.exists('!link_to_bar')) + file_obj = self.filesystem.resolve('!foo!bar.txt') + linked_file_obj = self.filesystem.resolve('!link_to_bar') self.assertEqual(file_obj, linked_file_obj) - link__obj = self.filesystem.LResolveObject('!link_to_bar') + link__obj = self.filesystem.lresolve('!link_to_bar') self.assertTrue(path.is_symlink()) def test_mkdir(self): self.assertRaises(FileNotFoundError, self.path('!foo!bar').mkdir) self.path('!foo!bar').mkdir(parents=True) - self.assertTrue(self.filesystem.Exists('!foo!bar')) + self.assertTrue(self.filesystem.exists('!foo!bar')) self.assertRaises(FileExistsError, self.path('!foo!bar').mkdir) @unittest.skipIf(sys.version_info < (3, 5), 'exist_ok argument new in Python 3.5') def test_mkdir_exist_ok(self): - self.filesystem.CreateDirectory('!foo!bar') + self.filesystem.create_dir('!foo!bar') self.path('foo!bar').mkdir(exist_ok=True) - self.filesystem.CreateFile('!foo!bar!baz') + self.filesystem.create_file('!foo!bar!baz') self.assertRaises(FileExistsError, self.path('!foo!bar!baz').mkdir, exist_ok=True) def test_rmdir(self): - self.filesystem.CreateDirectory('!foo!bar') + self.filesystem.create_dir('!foo!bar') self.path('!foo!bar').rmdir() - self.assertFalse(self.filesystem.Exists('!foo!bar')) - self.assertTrue(self.filesystem.Exists('!foo')) - self.filesystem.CreateFile('!foo!baz') + self.assertFalse(self.filesystem.exists('!foo!bar')) + self.assertTrue(self.filesystem.exists('!foo')) + self.filesystem.create_file('!foo!baz') self.assertRaises(OSError, self.path('!foo').rmdir) - self.assertTrue(self.filesystem.Exists('!foo')) + self.assertTrue(self.filesystem.exists('!foo')) def test_iterdir(self): - self.filesystem.CreateFile('!foo!bar!file1') - self.filesystem.CreateFile('!foo!bar!file2') - self.filesystem.CreateFile('!foo!bar!file3') + self.filesystem.create_file('!foo!bar!file1') + self.filesystem.create_file('!foo!bar!file2') + self.filesystem.create_file('!foo!bar!file3') path = self.path('!foo!bar') contents = [entry for entry in path.iterdir()] self.assertEqual(3, len(contents)) self.assertIn(self.path('!foo!bar!file2'), contents) def test_glob(self): - self.filesystem.CreateFile('!foo!setup.py') - self.filesystem.CreateFile('!foo!all_tests.py') - self.filesystem.CreateFile('!foo!README.md') - self.filesystem.CreateFile('!foo!setup.pyc') + self.filesystem.create_file('!foo!setup.py') + self.filesystem.create_file('!foo!all_tests.py') + self.filesystem.create_file('!foo!README.md') + self.filesystem.create_file('!foo!setup.pyc') path = self.path('!foo') self.assertEqual(sorted(path.glob('*.py')), [self.path('!foo!all_tests.py'), self.path('!foo!setup.py')]) def test_glob_case_windows(self): self.filesystem.is_windows_fs = True - self.filesystem.CreateFile('!foo!setup.py') - self.filesystem.CreateFile('!foo!all_tests.PY') - self.filesystem.CreateFile('!foo!README.md') - self.filesystem.CreateFile('!foo!example.Py') + self.filesystem.create_file('!foo!setup.py') + self.filesystem.create_file('!foo!all_tests.PY') + self.filesystem.create_file('!foo!README.md') + self.filesystem.create_file('!foo!example.Py') path = self.path('!foo') self.assertEqual(sorted(path.glob('*.py')), [self.path('!foo!all_tests.PY'), self.path('!foo!example.Py'), self.path('!foo!setup.py')]) def test_glob_case_posix(self): self.filesystem.is_windows_fs = False - self.filesystem.CreateFile('!foo!setup.py') - self.filesystem.CreateFile('!foo!all_tests.PY') - self.filesystem.CreateFile('!foo!README.md') - self.filesystem.CreateFile('!foo!example.Py') + self.filesystem.create_file('!foo!setup.py') + self.filesystem.create_file('!foo!all_tests.PY') + self.filesystem.create_file('!foo!README.md') + self.filesystem.create_file('!foo!example.Py') path = self.path('!foo') self.assertEqual(sorted(path.glob('*.py')), [self.path('!foo!setup.py')]) @@ -572,25 +572,25 @@ def test_expanduser(self): def test_getmtime(self): dir1 = 'foo!bar1.txt' - path_obj = self.filesystem.CreateFile(dir1) - path_obj.SetMTime(24) + path_obj = self.filesystem.create_file(dir1) + path_obj.st_mtime = 24 self.assertEqual(self.os.path.getmtime(dir1), self.os.path.getmtime(self.path(dir1))) def test_getctime(self): dir1 = 'foo!bar1.txt' - path_obj = self.filesystem.CreateFile(dir1) - path_obj.SetCTime(42) + path_obj = self.filesystem.create_file(dir1) + path_obj.st_ctime = 42 self.assertEqual(self.os.path.getctime(dir1), self.os.path.getctime(self.path(dir1))) def test_getatime(self): dir1 = 'foo!bar1.txt' - path_obj = self.filesystem.CreateFile(dir1) - path_obj.SetATime(11) + path_obj = self.filesystem.create_file(dir1) + path_obj.st_atime = 11 self.assertEqual(self.os.path.getatime(dir1), self.os.path.getatime(self.path(dir1))) def test_getsize(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path, contents='1234567') + self.filesystem.create_file(path, contents='1234567') self.assertEqual(self.os.path.getsize(path), self.os.path.getsize(self.path(path))) def test_isabs(self): @@ -599,17 +599,17 @@ def test_isabs(self): def test_isfile(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.assertEqual(self.os.path.isfile(path), self.os.path.isfile(self.path(path))) def test_islink(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.assertEqual(self.os.path.islink(path), self.os.path.islink(self.path(path))) def test_isdir(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.assertEqual(self.os.path.isdir(path), self.os.path.isdir(self.path(path))) def test_ismount(self): @@ -618,25 +618,25 @@ def test_ismount(self): def test_access(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path, contents='1234567') + self.filesystem.create_file(path, contents='1234567') self.assertEqual(self.os.access(path, os.R_OK), self.os.access(self.path(path), os.R_OK)) def test_chdir(self): path = '!foo!bar!baz' - self.filesystem.CreateDirectory(path) + self.filesystem.create_dir(path) self.os.chdir(self.path(path)) self.assertEqual(path, self.filesystem.cwd) def test_chmod(self): path = '!some_file' - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.os.chmod(self.path(path), 0o400) self.assertEqual(stat.S_IMODE(0o400), stat.S_IMODE(self.os.stat(path).st_mode)) def test_link(self): file1_path = 'test_file1' file2_path = 'test_file2' - self.filesystem.CreateFile(file1_path) + self.filesystem.create_file(file1_path) self.os.link(self.path(file1_path), file2_path) self.assertTrue(self.os.path.exists(file2_path)) self.os.unlink(file2_path) @@ -648,67 +648,67 @@ def test_link(self): def test_listdir(self): path = '!foo!bar' - self.filesystem.CreateDirectory(path) - self.filesystem.CreateFile(path + 'baz.txt') + self.filesystem.create_dir(path) + self.filesystem.create_file(path + 'baz.txt') self.assertEqual(self.os.listdir(path), self.os.listdir(self.path(path))) def test_mkdir(self): path = '!foo' self.os.mkdir(self.path(path)) - self.assertTrue(self.filesystem.Exists(path)) + self.assertTrue(self.filesystem.exists(path)) def test_makedirs(self): path = '!foo!bar' self.os.makedirs(self.path(path)) - self.assertTrue(self.filesystem.Exists(path)) + self.assertTrue(self.filesystem.exists(path)) def test_readlink(self): link_path = 'foo!bar!baz' target = 'tarJAY' - self.filesystem.CreateLink(link_path, target) + self.filesystem.symlink(link_path, target) self.assertEqual(self.os.readlink(self.path(link_path)), target) def test_remove(self): path = '!test.txt' - self.filesystem.CreateFile(path) + self.filesystem.create_file(path) self.os.remove(self.path(path)) - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) def test_rename(self): path1 = 'test1.txt' path2 = 'test2.txt' - self.filesystem.CreateFile(path1) + self.filesystem.create_file(path1) self.os.rename(self.path(path1), path2) - self.assertTrue(self.filesystem.Exists(path2)) + self.assertTrue(self.filesystem.exists(path2)) self.os.rename(self.path(path2), self.path(path1)) - self.assertTrue(self.filesystem.Exists(path1)) + self.assertTrue(self.filesystem.exists(path1)) def test_replace(self): path1 = 'test1.txt' path2 = 'test2.txt' - self.filesystem.CreateFile(path1) + self.filesystem.create_file(path1) self.os.replace(self.path(path1), path2) - self.assertTrue(self.filesystem.Exists(path2)) + self.assertTrue(self.filesystem.exists(path2)) self.os.replace(self.path(path2), self.path(path1)) - self.assertTrue(self.filesystem.Exists(path1)) + self.assertTrue(self.filesystem.exists(path1)) def test_rmdir(self): path = '!foo!bar' - self.filesystem.CreateDirectory(path) + self.filesystem.create_dir(path) self.os.rmdir(self.path(path)) - self.assertFalse(self.filesystem.Exists(path)) + self.assertFalse(self.filesystem.exists(path)) def test_scandir(self): directory = '!xyzzy!plugh' - self.filesystem.CreateDirectory(directory) - self.filesystem.CreateFile(directory + '!test.txt') + self.filesystem.create_dir(directory) + self.filesystem.create_file(directory + '!test.txt') dir_entries = [entry for entry in self.os.scandir(self.path(directory))] self.assertEqual(1, len(dir_entries)) def test_symlink(self): file_path = 'test_file1' link_path = 'link' - self.filesystem.CreateFile(file_path) + self.filesystem.create_file(file_path) self.os.symlink(self.path(file_path), link_path) self.assertTrue(self.os.path.exists(link_path)) self.os.remove(link_path) @@ -717,12 +717,12 @@ def test_symlink(self): def test_stat(self): path = 'foo!bar!baz' - self.filesystem.CreateFile(path, contents='1234567') + self.filesystem.create_file(path, contents='1234567') self.assertEqual(self.os.stat(path), self.os.stat(self.path(path))) def test_utime(self): path = '!some_file' - self.filesystem.CreateFile(path, contents='test') + self.filesystem.create_file(path, contents='test') self.os.utime(self.path(path), (1, 2)) st = self.os.stat(path) self.assertEqual(1, st.st_atime) diff --git a/fake_tempfile_test.py b/fake_tempfile_test.py index c0de2018..e074f6f6 100755 --- a/fake_tempfile_test.py +++ b/fake_tempfile_test.py @@ -40,21 +40,21 @@ def setUp(self): def testNamedTemporaryFile(self): obj = tempfile.NamedTemporaryFile() - self.assertTrue(self.fs.GetObject(obj.name)) + self.assertTrue(self.fs.get_object(obj.name)) obj.close() - self.assertRaises(IOError, self.fs.GetObject, obj.name) + self.assertRaises(IOError, self.fs.get_object, obj.name) def testNamedTemporaryFileNoDelete(self): obj = tempfile.NamedTemporaryFile(delete=False) obj.write(b'foo') obj.close() - file_obj = self.fs.GetObject(obj.name) + file_obj = self.fs.get_object(obj.name) contents = file_obj.contents self.assertEqual('foo', contents) obj = tempfile.NamedTemporaryFile(mode='w', delete=False) obj.write('foo') obj.close() - file_obj = self.fs.GetObject(obj.name) + file_obj = self.fs.get_object(obj.name) self.assertEqual('foo', file_obj.contents) def testMkstemp(self): @@ -63,8 +63,8 @@ def testMkstemp(self): self.assertEqual(2, len(temporary)) self.assertTrue(temporary[1].startswith(os.path.join(tempfile.gettempdir(), 'tmp'))) self.assertEqual(next_fd, temporary[0]) - self.assertTrue(self.fs.Exists(temporary[1])) - self.assertEqual(self.fs.GetObject(temporary[1]).st_mode, + self.assertTrue(self.fs.exists(temporary[1])) + self.assertEqual(self.fs.get_object(temporary[1]).st_mode, stat.S_IFREG | 0o600) fh = os.fdopen(temporary[0], 'w+b') self.assertEqual(temporary[0], fh.fileno()) @@ -74,29 +74,29 @@ def testMkstempDir(self): # expect fail: /dir does not exist self.assertRaises(OSError, tempfile.mkstemp, dir='/dir') # expect pass: /dir exists - self.fs.CreateDirectory('/dir') + self.fs.create_dir('/dir') next_fd = len(self.fs.open_files) temporary = tempfile.mkstemp(dir='/dir') self.assertEqual(2, len(temporary)) self.assertEqual(next_fd, temporary[0]) self.assertTrue(temporary[1].startswith(os.path.join(os.sep, 'dir', 'tmp'))) - self.assertTrue(self.fs.Exists(temporary[1])) - self.assertEqual(self.fs.GetObject(temporary[1]).st_mode, + self.assertTrue(self.fs.exists(temporary[1])) + self.assertEqual(self.fs.get_object(temporary[1]).st_mode, stat.S_IFREG | 0o600) def testMkdtemp(self): dirname = tempfile.mkdtemp() self.assertTrue(dirname) - self.assertTrue(self.fs.Exists(dirname)) - self.assertEqual(self.fs.GetObject(dirname).st_mode, + self.assertTrue(self.fs.exists(dirname)) + self.assertEqual(self.fs.get_object(dirname).st_mode, stat.S_IFDIR | 0o700) @unittest.skipIf(sys.version_info < (3, 0), "TemporaryDirectory showed up in 3") def testTemporaryDirectory(self): with tempfile.TemporaryDirectory() as tmpdir: self.assertTrue(tmpdir) - self.assertTrue(self.fs.Exists(tmpdir)) - self.assertEqual(self.fs.GetObject(tmpdir).st_mode, + self.assertTrue(self.fs.exists(tmpdir)) + self.assertEqual(self.fs.get_object(tmpdir).st_mode, stat.S_IFDIR | 0o700) diff --git a/pyfakefs/deprecator.py b/pyfakefs/deprecator.py new file mode 100644 index 00000000..557af81f --- /dev/null +++ b/pyfakefs/deprecator.py @@ -0,0 +1,69 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Utilities for handling deprecated functions.""" + +import functools +import warnings + + +class Deprecator(object): + """Decorator class for adding deprecated functions. + + Warnings are switched off by default. + To enable deprecation warnings, use: + + >>> from pyfakefs.deprecator import Deprecator + >>> + >>> Deprecator.show_warning = True + """ + + show_warning = False + + def __init__(self, use_instead=None, func_name=None): + self.use_instead = use_instead + self.func_name = func_name + + def __call__(self, func): + """Decorator to mark functions as deprecated. Emit warning + when the function is used.""" + + @functools.wraps(func) + def _new_func(*args, **kwargs): + if self.show_warning: + warnings.simplefilter('always', DeprecationWarning) + message = '' + if self.use_instead is not None: + message = 'Use {} instead.'.format(self.use_instead) + warnings.warn('Call to deprecated function {}. {}'.format( + self.func_name or func.__name__, message), + category=DeprecationWarning, stacklevel=2) + warnings.simplefilter('default', DeprecationWarning) + return func(*args, **kwargs) + + return _new_func + + @staticmethod + def add(klass, func, deprecated_name): + """Add the deprecated version of a member function to the given class. + Gives a deprecation warning on usage. + + Args: + klass: the class where the deprecated function is to be added + func: the actual function that is called by the deprecated version + deprecated_name: the deprecated name of the function + """ + + @Deprecator(func.__name__, deprecated_name) + def _old_function(*args, **kwargs): + return func(*args, **kwargs) + + setattr(klass, deprecated_name, _old_function) diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py index ce3c020b..28807f4f 100644 --- a/pyfakefs/fake_filesystem.py +++ b/pyfakefs/fake_filesystem.py @@ -34,27 +34,27 @@ >>> os_module.path.exists(pathname) False ->>> new_file = filesystem.CreateFile(pathname) +>>> new_file = filesystem.create_file(pathname) File objects can't be overwritten: >>> os_module.path.exists(pathname) True >>> try: -... filesystem.CreateFile(pathname) +... filesystem.create_file(pathname) ... except IOError as e: ... assert e.errno == errno.EEXIST, 'unexpected errno: %d' % e.errno ... assert e.strerror == 'File already exists in fake filesystem' Remove a file object: ->>> filesystem.RemoveObject(pathname) +>>> filesystem.remove_object(pathname) >>> os_module.path.exists(pathname) False Create a new file object at the previous path: ->>> beatles_file = filesystem.CreateFile(pathname, +>>> beatles_file = filesystem.create_file(pathname, ... contents='Dear Prudence\\nWon\\'t you come out to play?\\n') >>> os_module.path.exists(pathname) True @@ -98,11 +98,11 @@ import sys import time import warnings - from collections import namedtuple +from stat import S_IFREG, S_IFDIR, S_ISLNK, S_IFMT, S_ISDIR, S_IFLNK, S_ISREG -import stat from copy import copy +from pyfakefs.deprecator import Deprecator if sys.version_info < (3, 0): import StringIO # pylint: disable=import-error @@ -149,12 +149,14 @@ # on MacOS and Windows, the maximum recursion depth is 32 _MAX_LINK_DEPTH = 32 -FAKE_PATH_MODULE_DEPRECATION = ('Do not instantiate a FakePathModule directly; ' - 'let FakeOsModule instantiate it. See the ' - 'FakeOsModule docstring for details.') +FAKE_PATH_MODULE_DEPRECATION = ( + 'Do not instantiate a FakePathModule directly; ' + 'let FakeOsModule instantiate it. See the ' + 'FakeOsModule docstring for details.' +) if sys.platform == 'win32': - # On native Windows, raise WindowsError instead of OSError if available + # On native Windows, raise WindowsError instead of OSError OSError = WindowsError # pylint: disable=undefined-variable,redefined-builtin @@ -279,6 +281,8 @@ def st_mtime(self, val): self._st_mtime_ns = self.long_type(val * 1e9) def __getitem__(self, item): + import stat + """Implement item access to mimic `os.stat_result` behavior.""" if item == stat.ST_MODE: return self.st_mode @@ -341,7 +345,7 @@ class FakeFile(object): Attributes currently faked out: st_mode: user-specified, otherwise S_IFREG st_ctime: the time.time() timestamp of the file change time (updated - each time a file's attributes is modified). + each time a file's attributes is modified). st_atime: the time.time() timestamp when the file was last accessed. st_mtime: the time.time() timestamp when the file was last modified. st_size: the size of the file @@ -349,26 +353,26 @@ class FakeFile(object): st_ino: the inode number - a unique number identifying the file st_dev: a unique number identifying the (fake) file system device the file belongs to - Other attributes needed by os.stat are assigned default value of None - these include: st_uid, st_gid + Other attributes needed by os.stat are assigned a default value of None. + These include: st_uid, st_gid """ - def __init__(self, name, st_mode=stat.S_IFREG | PERM_DEF_FILE, + def __init__(self, name, st_mode=S_IFREG | PERM_DEF_FILE, contents=None, filesystem=None, encoding=None, errors=None): """init. Args: - name: name of the file/directory, without parent path information - st_mode: the stat.S_IF* constant representing the file type (i.e. - stat.S_IFREG, stat.S_IFDIR) - contents: the contents of the filesystem object; should be a string or byte object for - regular files, and a list of other FakeFile or FakeDirectory objects - for FakeDirectory objects - filesystem: the fake filesystem where the file is created. - New in pyfakefs 2.9. - encoding: if contents is a unicode string, the encoding used for serialization - errors: the error mode used for encoding/decoding errors - New in pyfakefs 3.2. + name: name of the file/directory, without parent path information + st_mode: the stat.S_IF* constant representing the file type (i.e. + stat.S_IFREG, stat.S_IFDIR) + contents: the contents of the filesystem object; should be a string + or byte object for regular files, and a list of other FakeFile + or FakeDirectory objects for FakeDirectory objects + filesystem: the fake filesystem where the file is created. + New in pyfakefs 2.9. + encoding: if contents is a unicode string, the encoding used for serialization + errors: the error mode used for encoding/decoding errors + New in pyfakefs 3.2. """ self.name = name self.stat_result = _FakeStatResult(time.time()) @@ -398,7 +402,40 @@ def contents(self): errors=self.errors) return self.byte_contents - def SetLargeFileSize(self, st_size): + @property + def st_ctime(self): + """Return the creation time of the fake file.""" + return (self._st_ctime if FakeOsModule.stat_float_times() + else int(self._st_ctime)) + + @property + def st_atime(self): + """Return the access time of the fake file.""" + return (self._st_atime if FakeOsModule.stat_float_times() + else int(self._st_atime)) + + @property + def st_mtime(self): + """Return the modification time of the fake file.""" + return (self._st_mtime if FakeOsModule.stat_float_times() + else int(self._st_mtime)) + + @st_ctime.setter + def st_ctime(self, val): + """Set the creation time of the fake file.""" + self._st_ctime = val + + @st_atime.setter + def st_atime(self, val): + """Set the access time of the fake file.""" + self._st_atime = val + + @st_mtime.setter + def st_mtime(self, val): + """Set the modification time of the fake file.""" + self._st_mtime = val + + def set_large_file_size(self, st_size): """Sets the self.st_size attribute and replaces self.content with None. Provided specifically to simulate very large files without regards @@ -420,12 +457,13 @@ def SetLargeFileSize(self, st_size): 'size=%r fake file' % st_size, self.name) if self.st_size: - self.SetSize(0) - self.filesystem.ChangeDiskUsage(st_size, self.name, self.st_dev) + self.size = 0 + if self.filesystem: + self.filesystem.change_disk_usage(st_size, self.name, self.st_dev) self.st_size = st_size self._byte_contents = None - def IsLargeFile(self): + def is_large_file(self): """Return True if this file was initialized with size but no contents.""" return self._byte_contents is None @@ -451,14 +489,14 @@ def _set_initial_contents(self, contents): st_size = len(contents) if self._byte_contents: - self.SetSize(0) + self.size = 0 current_size = self.st_size or 0 - self.filesystem.ChangeDiskUsage(st_size - current_size, self.name, self.st_dev) + self.filesystem.change_disk_usage(st_size - current_size, self.name, self.st_dev) self._byte_contents = contents self.st_size = st_size self.epoch += 1 - def SetContents(self, contents, encoding=None): + def set_contents(self, contents, encoding=None): """Sets the file contents and size and increases the modification time. Args: @@ -478,7 +516,8 @@ def SetContents(self, contents, encoding=None): self.st_ctime = current_time self.st_mtime = current_time - def GetSize(self): + @property + def size(self): """Returns the size in bytes of the file contents. New in pyfakefs 2.9. """ @@ -492,9 +531,14 @@ def GetPath(self): names.insert(0, obj.name) obj = obj.parent_dir sep = self.filesystem._path_separator(self.name) - return self.filesystem.NormalizePath(sep.join(names[1:])) + return self.filesystem.absnormpath(sep.join(names[1:])) + + @Deprecator('property size') + def GetSize(self): + return self.size - def SetSize(self, st_size): + @size.setter + def size(self, st_size): """Resizes file content, padding with nulls if new size exceeds the old. Args: @@ -512,7 +556,7 @@ def SetSize(self, st_size): self.name) current_size = self.st_size or 0 - self.filesystem.ChangeDiskUsage(st_size - current_size, self.name, self.st_dev) + self.filesystem.change_disk_usage(st_size - current_size, self.name, self.st_dev) if self._byte_contents: if st_size < current_size: self._byte_contents = self._byte_contents[:st_size] @@ -525,6 +569,11 @@ def SetSize(self, st_size): self.st_size = st_size self.epoch += 1 + @Deprecator('property size') + def SetSize(self, value): + self.size = value + + @Deprecator('property st_atime') def SetATime(self, st_atime): """Set the self.st_atime attribute. @@ -533,6 +582,7 @@ def SetATime(self, st_atime): """ self.st_atime = st_atime + @Deprecator('property st_mtime') def SetMTime(self, st_mtime): """Set the self.st_mtime attribute. @@ -541,6 +591,7 @@ def SetMTime(self, st_mtime): """ self.st_mtime = st_mtime + @Deprecator('property st_ctime') def SetCTime(self, st_ctime): """Set the self.st_ctime attribute. New in pyfakefs 3.0. @@ -565,6 +616,7 @@ def __setattr__(self, key, value): def __str__(self): return '%s(%o)' % (self.name, self.st_mode) + @Deprecator('st_ino') def SetIno(self, st_ino): """Set the self.st_ino attribute. Note that a unique inode is assigned automatically to a new fake file. @@ -576,9 +628,14 @@ def SetIno(self, st_ino): self.st_ino = st_ino +Deprecator.add(FakeFile, FakeFile.set_large_file_size, 'SetLargeFileSize') +Deprecator.add(FakeFile, FakeFile.set_contents, 'SetContents') +Deprecator.add(FakeFile, FakeFile.is_large_file, 'IsLargeFile') + + class FakeFileFromRealFile(FakeFile): """Represents a fake file copied from the real file system. - + The contents of the file are read on demand only. New in pyfakefs 3.2. """ @@ -589,8 +646,9 @@ def __init__(self, file_path, filesystem, read_only=True): Args: file_path: path to the existing file. filesystem: the fake filesystem where the file is created. - read_only: if set, the file is treated as read-only, e.g. a write access raises an exception; - otherwise, writing to the file changes the fake file only as usually. + read_only: if set, the file is treated as read-only, e.g. + a write access raises an exception; otherwise, writing + to the file changes the fake file only as usually. Raises: OSError: if the file does not exist in the real file system. @@ -615,7 +673,7 @@ def byte_contents(self): self.st_atime = os.stat(self.file_path).st_atime return self._byte_contents - def IsLargeFile(self): + def is_large_file(self): """The contents are never faked.""" return False @@ -631,11 +689,11 @@ def __init__(self, name, perm_bits=PERM_DEF, filesystem=None): perm_bits: permission bits. defaults to 0o777. filesystem: if set, the fake filesystem where the directory is created """ - FakeFile.__init__(self, name, stat.S_IFDIR | perm_bits, {}, filesystem=filesystem) + FakeFile.__init__(self, name, S_IFDIR | perm_bits, {}, filesystem=filesystem) # directories have the link count of contained entries, inclusing '.' and '..' self.st_nlink += 1 - def SetContents(self, contents, encoding=None): + def set_contents(self, contents, encoding=None): error_class = OSError if self.filesystem.is_windows_fs else IOError raise error_class(errno.EISDIR, 'Trying to write to directory') @@ -650,7 +708,7 @@ def ordered_dirs(self): return [item[0] for item in sorted( self.byte_contents.items(), key=lambda entry: entry[1].st_ino)] - def AddEntry(self, path_object): + def add_entry(self, path_object): """Adds a child FakeFile to this directory. Args: @@ -674,9 +732,9 @@ def AddEntry(self, path_object): path_object.st_nlink += 1 path_object.st_dev = self.st_dev if path_object.st_nlink == 1: - self.filesystem.ChangeDiskUsage(path_object.GetSize(), path_object.name, self.st_dev) + self.filesystem.change_disk_usage(path_object.size, path_object.name, self.st_dev) - def GetEntry(self, pathname_name): + def get_entry(self, pathname_name): """Retrieves the specified child file or directory entry. Args: @@ -690,7 +748,7 @@ def GetEntry(self, pathname_name): """ return self.contents[pathname_name] - def RemoveEntry(self, pathname_name, recursive=True): + def remove_entry(self, pathname_name, recursive=True): """Removes the specified child file or directory. Args: @@ -707,13 +765,13 @@ def RemoveEntry(self, pathname_name, recursive=True): if entry.st_mode & PERM_WRITE == 0: raise OSError(errno.EACCES, 'Trying to remove object without write permission', pathname_name) - if self.filesystem.is_windows_fs and self.filesystem.HasOpenFile(entry): + if self.filesystem.is_windows_fs and self.filesystem.has_open_file(entry): raise OSError(errno.EACCES, 'Trying to remove an open file', pathname_name) if recursive and isinstance(entry, FakeDirectory): while entry.contents: - entry.RemoveEntry(list(entry.contents)[0]) + entry.remove_entry(list(entry.contents)[0]) elif entry.st_nlink == 1: - self.filesystem.ChangeDiskUsage(-entry.GetSize(), pathname_name, entry.st_dev) + self.filesystem.change_disk_usage(-entry.size, pathname_name, entry.st_dev) self.st_nlink -= 1 entry.st_nlink -= 1 @@ -721,11 +779,16 @@ def RemoveEntry(self, pathname_name, recursive=True): del self.contents[pathname_name] - def GetSize(self): + @property + def size(self): """Return the total size of all files contained in this directory tree. New in pyfakefs 2.9. """ - return sum([item[1].GetSize() for item in self.contents.items()]) + return sum([item[1].size for item in self.contents.items()]) + + @Deprecator('property size') + def GetSize(self): + return self.size def HasParentObject(self, dir_object): """Return `True` if dir_object is a direct or indirect parent directory, @@ -747,9 +810,15 @@ def __str__(self): return description +Deprecator.add(FakeDirectory, FakeDirectory.add_entry, 'AddEntry') +Deprecator.add(FakeDirectory, FakeDirectory.get_entry, 'GetEntry') +Deprecator.add(FakeDirectory, FakeDirectory.set_contents, 'SetContents') +Deprecator.add(FakeDirectory, FakeDirectory.remove_entry, 'RemoveEntry') + + class FakeDirectoryFromRealDirectory(FakeDirectory): """Represents a fake directory copied from the real file system. - + The contents of the directory are read on demand only. New in pyfakefs 3.2. """ @@ -763,7 +832,7 @@ def __init__(self, dir_path, filesystem, read_only): read_only: if set, all files under the directory are treated as read-only, e.g. a write access raises an exception; otherwise, writing to the files changes the fake files only as usually. - + Raises: OSError if the directory does not exist in the real file system """ @@ -792,11 +861,12 @@ def contents(self): read_only=self.read_only) return self.byte_contents - def GetSize(self): + @property + def size(self): # we cannot get the size until the contents are loaded if not self.contents_read: return 0 - return super(FakeDirectoryFromRealDirectory, self).GetSize() + return super(FakeDirectoryFromRealDirectory, self).size class FakeFilesystem(object): @@ -841,7 +911,7 @@ def __init__(self, path_separator=os.path.sep, total_size=None): self.last_ino = 0 self.last_dev = 0 self.mount_points = {} - self.AddMountPoint(self.root.name, total_size) + self.add_mount_point(self.root.name, total_size) @staticmethod def _matching_string(matched, string): @@ -869,14 +939,15 @@ def _alternative_path_separator(self, path): """Return the alternative path separator as the same type as path""" return self._matching_string(path, self.alternative_path_separator) - def _IsLinkSupported(self): + def _is_link_supported(self): # Python 3.2 supports links in Windows return not self.is_windows_fs or sys.version_info >= (3, 2) - def AddMountPoint(self, path, total_size=None): + def add_mount_point(self, path, total_size=None): """Add a new mount point for a filesystem device. The mount point gets a new unique device number. New in pyfakefs 2.9. + Name changed from `AddMountPoint` in pyfakefs 3.3. Args: path: The root path for the new mount path. @@ -890,7 +961,7 @@ def AddMountPoint(self, path, total_size=None): Raises: OSError: if trying to mount an existing mount point again. """ - path = self.NormalizePath(path) + path = self.absnormpath(path) if path in self.mount_points: raise OSError(errno.EEXIST, 'Mount point cannot be added twice', path) self.last_dev += 1 @@ -898,17 +969,17 @@ def AddMountPoint(self, path, total_size=None): 'idev': self.last_dev, 'total_size': total_size, 'used_size': 0 } # special handling for root path: has been created before - root_dir = self.root if path == self.root.name else self.CreateDirectory(path) + root_dir = self.root if path == self.root.name else self.create_dir(path) root_dir.st_dev = self.last_dev return self.mount_points[path] - def _AutoMountDriveIfNeeded(self, path, force=False): - if self.is_windows_fs and (force or not self._MountPointForPath(path)): - drive = self.SplitDrive(path)[0] + def _auto_mount_drive_if_needed(self, path, force=False): + if self.is_windows_fs and (force or not self._mount_point_for_path(path)): + drive = self.splitdrive(path)[0] if drive: - return self.AddMountPoint(path=drive) + return self.add_mount_point(path=drive) - def _MountPointForPath(self, path): + def _mount_point_for_path(self, path): def to_str(string): """Convert the str, unicode or byte object to a str using the default encoding.""" if string is None or isinstance(string, str): @@ -918,11 +989,11 @@ def to_str(string): else: return string.decode(locale.getpreferredencoding(False)) - path = self.NormalizePath(self.NormalizeCase(path)) + path = self.absnormpath(self._original_path(path)) if path in self.mount_points: return self.mount_points[path] mount_path = self._matching_string(path, '') - drive = self.SplitDrive(path)[:1] + drive = self.splitdrive(path)[:1] for root_path in self.mount_points: root_path = self._matching_string(path, root_path) if drive and not root_path.startswith(drive): @@ -931,20 +1002,21 @@ def to_str(string): mount_path = root_path if mount_path: return self.mount_points[to_str(mount_path)] - mount_point = self._AutoMountDriveIfNeeded(path, force=True) + mount_point = self._auto_mount_drive_if_needed(path, force=True) assert mount_point return mount_point - def _MountPointForDevice(self, idev): + def _mount_point_for_device(self, idev): for mount_point in self.mount_points.values(): if mount_point['idev'] == idev: return mount_point - def GetDiskUsage(self, path=None): + def get_disk_usage(self, path=None): """Return the total, used and free disk space in bytes as named tuple, or placeholder values simulating unlimited space if not set. Note: This matches the return value of shutil.disk_usage(). New in pyfakefs 2.9. + Name changed from `GetDiskUsage` in pyfakefs 3.3. Args: path: The disk space is returned for the file system device where path resides. @@ -954,16 +1026,17 @@ def GetDiskUsage(self, path=None): if path is None: mount_point = self.mount_points[self.root.name] else: - mount_point = self._MountPointForPath(path) + mount_point = self._mount_point_for_path(path) if mount_point and mount_point['total_size'] is not None: return DiskUsage(mount_point['total_size'], mount_point['used_size'], mount_point['total_size'] - mount_point['used_size']) return DiskUsage(1024 * 1024 * 1024 * 1024, 0, 1024 * 1024 * 1024 * 1024) - def SetDiskUsage(self, total_size, path=None): + def set_disk_usage(self, total_size, path=None): """Changes the total size of the file system, preserving the used space. Example usage: set the size of an auto-mounted Windows drive. New in pyfakefs 2.9. + Name changed from `SetDiskUsage` in pyfakefs 3.3. Args: total_size: the new total size of the filesystem in bytes @@ -976,16 +1049,17 @@ def SetDiskUsage(self, total_size, path=None): """ if path is None: path = self.root.name - mount_point = self._MountPointForPath(path) + mount_point = self._mount_point_for_path(path) if mount_point['total_size'] is not None and mount_point['used_size'] > total_size: raise IOError(errno.ENOSPC, 'Fake file system: cannot change size to %r bytes - ' 'used space is larger' % total_size, path) mount_point['total_size'] = total_size - def ChangeDiskUsage(self, usage_change, file_path, st_dev): + def change_disk_usage(self, usage_change, file_path, st_dev): """Change the used disk space by the given amount. New in pyfakefs 2.9. + Name changed from `ChangeDiskUsage` in pyfakefs 3.3. Args: usage_change: number of bytes added to the used space. @@ -998,7 +1072,7 @@ def ChangeDiskUsage(self, usage_change, file_path, st_dev): Raises: IOError: if usage_change exceeds the free file system space """ - mount_point = self._MountPointForDevice(st_dev) + mount_point = self._mount_point_for_device(st_dev) if mount_point: if mount_point['total_size'] is not None: if mount_point['total_size'] - mount_point['used_size'] < usage_change: @@ -1007,9 +1081,10 @@ def ChangeDiskUsage(self, usage_change, file_path, st_dev): % usage_change, file_path) mount_point['used_size'] += usage_change - def GetStat(self, entry_path, follow_symlinks=True): + def stat(self, entry_path, follow_symlinks=True): """Return the os.stat-like tuple for the FakeFile object of entry_path. New in pyfakefs 3.0. + Name changed from `GetStat` in pyfakefs 3.3. Args: entry_path: path to filesystem object to retrieve. @@ -1024,14 +1099,15 @@ def GetStat(self, entry_path, follow_symlinks=True): """ # stat should return the tuple representing return value of os.stat try: - file_object = self.ResolveObject(entry_path, follow_symlinks, allow_fd=True) + file_object = self.resolve(entry_path, follow_symlinks, allow_fd=True) return file_object.stat_result.copy() except IOError as io_error: raise OSError(io_error.errno, io_error.strerror, entry_path) - def ChangeMode(self, path, mode, follow_symlinks=True): + def chmod(self, path, mode, follow_symlinks=True): """Change the permissions of a file as encoded in integer mode. New in pyfakefs 3.0. + Name changed from `ChangeMode` in pyfakefs 3.3. Args: path: (str) Path to the file. @@ -1040,7 +1116,7 @@ def ChangeMode(self, path, mode, follow_symlinks=True): instead of the linked object. """ try: - file_object = self.ResolveObject(path, follow_symlinks, allow_fd=True) + file_object = self.resolve(path, follow_symlinks, allow_fd=True) except IOError as io_error: if io_error.errno == errno.ENOENT: raise OSError(errno.ENOENT, @@ -1051,9 +1127,10 @@ def ChangeMode(self, path, mode, follow_symlinks=True): (mode & PERM_ALL)) file_object.st_ctime = time.time() - def UpdateTime(self, path, times=None, ns=None, follow_symlinks=True): + def utime(self, path, times=None, ns=None, follow_symlinks=True): """Change the access and modified times of a file. New in pyfakefs 3.0. + Name changed from `UpdateTime` in pyfakefs 3.3. Args: path: (str) Path to the file. @@ -1082,7 +1159,7 @@ def UpdateTime(self, path, times=None, ns=None, follow_symlinks=True): raise TypeError("utime: 'ns' must be a tuple of two ints") try: - file_object = self.ResolveObject(path, follow_symlinks, allow_fd=True) + file_object = self.resolve(path, follow_symlinks, allow_fd=True) except IOError as io_error: if io_error.errno == errno.ENOENT: raise OSError(errno.ENOENT, @@ -1108,21 +1185,26 @@ def UpdateTime(self, path, times=None, ns=None, follow_symlinks=True): file_object.st_atime = current_time file_object.st_mtime = current_time + + @Deprecator def SetIno(self, path, st_ino): """Set the self.st_ino attribute of file at 'path'. Note that a unique inode is assigned automatically to a new fake file. - Using this function does not guarantee uniqueness and should used with caution. + Using this function does not guarantee uniqueness and should be used with caution. + Deprecated in pyfakefs 3.3 - use st_ino instead. Args: path: Path to file. st_ino: The desired inode. """ - self.GetObject(path).SetIno(st_ino) + self.get_object(path).st_ino = st_ino - def AddOpenFile(self, file_obj): + def _add_open_file(self, file_obj): """Add file_obj to the list of open files on the filesystem. + Used internally to manage open files. The position in the self.open_files array is the file descriptor number. + Name changed from `AddOpenFile` in pyfakefs 3.3. Args: file_obj: file object to be added to open files list. @@ -1138,8 +1220,10 @@ def AddOpenFile(self, file_obj): self.open_files.append(file_obj) return len(self.open_files) - 1 - def CloseOpenFile(self, file_des): + def _close_open_file(self, file_des): """Remove file object with given descriptor from the list of open files. + Used internally to manage open files. + Name changed from `CloseOpenFile` in pyfakefs 3.3. Sets the entry in open_files to None. @@ -1149,8 +1233,9 @@ def CloseOpenFile(self, file_des): self.open_files[file_des] = None heapq.heappush(self.free_fd_heap, file_des) - def GetOpenFile(self, file_des): + def _get_open_file(self, file_des): """Return an open file. + Name changed from `GetOpenFile` in pyfakefs 3.3. Args: file_des: file descriptor of the open file. @@ -1164,12 +1249,11 @@ def GetOpenFile(self, file_des): """ if not isinstance(file_des, int): raise TypeError('an integer is required') - if (file_des >= len(self.open_files) or - self.open_files[file_des] is None): + if (file_des >= len(self.open_files) or self.open_files[file_des] is None): raise OSError(errno.EBADF, 'Bad file descriptor', file_des) return self.open_files[file_des] - def HasOpenFile(self, file_object): + def has_open_file(self, file_object): """Return True if the given file object is in the list of open files. New in pyfakefs 2.9. @@ -1179,9 +1263,9 @@ def HasOpenFile(self, file_object): Returns: True if the file is open. """ - return file_object in [wrapper.GetObject() for wrapper in self.open_files if wrapper] + return file_object in [wrapper.get_object() for wrapper in self.open_files if wrapper] - def NormalizePathSeparator(self, path): + def normcase(self, path): """Replace all appearances of alternative path separator with path separator. Do nothing if no alternative separator is set. New in pyfakefs 2.9. @@ -1198,12 +1282,12 @@ def NormalizePathSeparator(self, path): return path return path.replace(self._alternative_path_separator(path), self._path_separator(path)) - def CollapsePath(self, path): + def normpath(self, path): """Mimic os.path.normpath using the specified path_separator. Mimics os.path.normpath using the path_separator that was specified for this FakeFilesystem. Normalizes the path, but unlike the method - NormalizePath, does not make it absolute. Eliminates dot components + absnormpath, does not make it absolute. Eliminates dot components (. and ..) and combines repeated path separators (//). Initial .. components are left in place for relative paths. If the result is an empty path, '.' is returned instead. @@ -1218,8 +1302,8 @@ def CollapsePath(self, path): Returns: (str) A copy of path with empty components and dot components removed. """ - path = self.NormalizePathSeparator(path) - drive, path = self.SplitDrive(path) + path = self.normcase(path) + drive, path = self.splitdrive(path) sep = self._path_separator(path) is_absolute_path = path.startswith(sep) path_components = path.split(sep) @@ -1244,9 +1328,10 @@ def CollapsePath(self, path): collapsed_path = sep + collapsed_path return drive + collapsed_path or dot - def NormalizeCase(self, path): - """Return a normalized case version of the given path for case-insensitive - file systems. For case-sensitive file systems, return path unchanged. + def _original_path(self, path): + """Return the given path with the case originally given to the path. + For case-sensitive file systems, this returns the path unchanged, + for case-insensitive file systems it ensures case-preserving. New in pyfakefs 2.9. Args: @@ -1266,13 +1351,13 @@ def components_to_path(): if self.is_case_sensitive or not path: return path - path_components = self.GetPathComponents(path) + path_components = self._path_components(path) normalized_components = [] current_dir = self.root for component in path_components: if not isinstance(current_dir, FakeDirectory): return components_to_path() - dir_name, current_dir = self._DirectoryContent(current_dir, component) + dir_name, current_dir = self._directory_content(current_dir, component) if current_dir is None or ( isinstance(current_dir, FakeDirectory) and current_dir._byte_contents is None and @@ -1281,7 +1366,7 @@ def components_to_path(): normalized_components.append(dir_name) return components_to_path() - def NormalizePath(self, path): + def absnormpath(self, path): """Absolutize and minimalize the given path. Forces all relative paths to be absolute, and normalizes the path to @@ -1294,10 +1379,10 @@ def NormalizePath(self, path): The normalized path relative to the current working directory, or the root directory if path is empty. """ - path = self.NormalizePathSeparator(path) + path = self.normcase(path) if not path: path = self.path_separator - elif not self._StartsWithRootPath(path): + elif not self._starts_with_root_path(path): # Prefix relative paths with cwd, if cwd is not root. root_name = self._matching_string(path, self.root.name) empty = self._matching_string(path, '') @@ -1305,23 +1390,23 @@ def NormalizePath(self, path): (self.cwd != root_name and self.cwd or empty, path)) if path == self._matching_string(path, '.'): path = self.cwd - return self.CollapsePath(path) + return self.normpath(path) - def SplitPath(self, path): - """Mimic os.path.split using the specified path_separator. + def splitpath(self, path): + """Mimic os.path.splitpath using the specified path_separator. - Mimics os.path.split using the path_separator that was specified + Mimics os.path.splitpath using the path_separator that was specified for this FakeFilesystem. Args: - path: (str) The path to split. + path: (str) The path to splitpath. Returns: (str) A duple (pathname, basename) for which pathname does not end with a slash, and basename does not contain a slash. """ - drive, path = self.SplitDrive(path) - path = self.NormalizePathSeparator(path) + drive, path = self.splitdrive(path) + path = self.normcase(path) sep = self._path_separator(path) path_components = path.split(sep) if not path_components: @@ -1339,14 +1424,14 @@ def SplitPath(self, path): # Root path. Collapse all leading separators. return (drive or sep, basename) - def SplitDrive(self, path): + def splitdrive(self, path): """Splits the path into the drive part and the rest of the path. New in pyfakefs 2.9. Taken from Windows specific implementation in Python 3.5 and slightly adapted. Args: - path: the full path to be split. + path: the full path to be splitpath. Returns: a tuple of the drive part and the rest of the path, or of an empty string and the full path if drive letters are not supported or no drive is present. @@ -1355,7 +1440,7 @@ def SplitDrive(self, path): path = os.fspath(path) if self.is_windows_fs: if len(path) >= 2: - path = self.NormalizePathSeparator(path) + path = self.normcase(path) sep = self._path_separator(path) # UNC path handling is here since Python 2.7.8, back-ported from Python 3 if sys.version_info >= (2, 7, 8): @@ -1375,15 +1460,15 @@ def SplitDrive(self, path): return path[:2], path[2:] return path[:0], path - def _JoinPathsWithDriveSupport(self, *all_paths): + def _join_paths_with_drive_support(self, *all_paths): """Taken from Python 3.5 os.path.join() code in ntpath.py and slightly adapted""" base_path = all_paths[0] paths_to_add = all_paths[1:] sep = self._path_separator(base_path) seps = [sep, self._alternative_path_separator(base_path)] - result_drive, result_path = self.SplitDrive(base_path) + result_drive, result_path = self.splitdrive(base_path) for path in paths_to_add: - drive_part, path_part = self.SplitDrive(path) + drive_part, path_part = self.splitdrive(path) if path_part and path_part[:1] in seps: # Second path is absolute if drive_part or not result_drive: @@ -1409,7 +1494,7 @@ def _JoinPathsWithDriveSupport(self, *all_paths): return result_drive + sep + result_path return result_drive + result_path - def JoinPaths(self, *paths): + def joinpaths(self, *paths): """Mimic os.path.join using the specified path_separator. Args: @@ -1424,11 +1509,11 @@ def JoinPaths(self, *paths): if len(paths) == 1: return paths[0] if self.is_windows_fs: - return self._JoinPathsWithDriveSupport(*paths) + return self._join_paths_with_drive_support(*paths) joined_path_segments = [] sep = self._path_separator(paths[0]) for path_segment in paths: - if self._StartsWithRootPath(path_segment): + if self._starts_with_root_path(path_segment): # An absolute path joined_path_segments = [path_segment] else: @@ -1439,31 +1524,31 @@ def JoinPaths(self, *paths): joined_path_segments.append(path_segment) return self._matching_string(paths[0], '').join(joined_path_segments) - def GetPathComponents(self, path): + def _path_components(self, path): """Breaks the path into a list of component names. Does not include the root directory as a component, as all paths are considered relative to the root directory for the FakeFilesystem. Callers should basically follow this pattern: - >>> file_path = self.NormalizePath(file_path) - >>> path_components = self.GetPathComponents(file_path) + >>> file_path = self.absnormpath(file_path) + >>> path_components = self._path_components(file_path) >>> current_dir = self.root >>> for component in path_components: >>> if component not in current_dir.contents: >>> raise IOError >>> DoStuffWithComponent(current_dir, component) - >>> current_dir = current_dir.GetEntry(component) + >>> current_dir = current_dir.get_entry(component) Args: path: path to tokenize Returns: - The list of names split from path + The list of names splitpath from path """ if not path or path == self._path_separator(path): return [] - drive, path = self.SplitDrive(path) + drive, path = self.splitdrive(path) path_components = path.split(self._path_separator(path)) assert drive or path_components if not path_components[0]: @@ -1473,7 +1558,7 @@ def GetPathComponents(self, path): path_components.insert(0, drive) return path_components - def StartsWithDriveLetter(self, file_path): + def _starts_with_drive_letter(self, file_path): """Return True if file_path starts with a drive letter. New in pyfakefs 2.9. @@ -1488,25 +1573,25 @@ def StartsWithDriveLetter(self, file_path): return (self.is_windows_fs and len(file_path) >= 2 and file_path[:1].isalpha and (file_path[1:2]) == colon) - def _StartsWithRootPath(self, file_path): + def _starts_with_root_path(self, file_path): root_name = self._matching_string(file_path, self.root.name) return (file_path.startswith(root_name) or not self.is_case_sensitive and file_path.lower().startswith( root_name.lower()) or - self.StartsWithDriveLetter(file_path)) + self._starts_with_drive_letter(file_path)) - def _IsRootPath(self, file_path): + def _is_root_path(self, file_path): root_name = self._matching_string(file_path, self.root.name) return (file_path == root_name or not self.is_case_sensitive and file_path.lower() == root_name.lower() or - len(file_path) == 2 and self.StartsWithDriveLetter(file_path)) + len(file_path) == 2 and self._starts_with_drive_letter(file_path)) - def _EndsWithPathSeparator(self, file_path): + def _ends_with_path_separator(self, file_path): return file_path and (file_path.endswith(self._path_separator(file_path)) or self.alternative_path_separator is not None and file_path.endswith(self._alternative_path_separator(file_path))) - def _DirectoryContent(self, directory, component): + def _directory_content(self, directory, component): if not isinstance(directory, FakeDirectory): return None, None if component in directory.contents: @@ -1520,7 +1605,7 @@ def _DirectoryContent(self, directory, component): return None, None - def Exists(self, file_path): + def exists(self, file_path): """Return true if a path points to an existing file system object. Args: @@ -1539,23 +1624,23 @@ def Exists(self, file_path): if not file_path: return False try: - file_path = self.ResolvePath(file_path) + file_path = self.resolve_path(file_path) except (IOError, OSError): return False if file_path == self.root.name: return True - path_components = self.GetPathComponents(file_path) + path_components = self._path_components(file_path) current_dir = self.root for component in path_components: - current_dir = self._DirectoryContent(current_dir, component)[1] + current_dir = self._directory_content(current_dir, component)[1] if not current_dir: return False return True - def ResolvePath(self, file_path, allow_fd=False, raw_io=True): + def resolve_path(self, file_path, allow_fd=False, raw_io=True): """Follow a path, resolving symlinks. - ResolvePath traverses the filesystem along the specified file path, + resolve_path traverses the filesystem along the specified file path, resolving file names and symbolic links until all elements of the path are exhausted, or we reach a file which does not exist. If all the elements are not consumed, they just get appended to the path resolved so far. @@ -1590,23 +1675,23 @@ def ResolvePath(self, file_path, allow_fd=False, raw_io=True): IOError: if file_path is '' or a part of the path doesn't exist. """ - def _ComponentsToPath(component_folders): + def _components_to_path(component_folders): sep = self._path_separator( component_folders[0]) if component_folders else self.path_separator path = sep.join(component_folders) - if not self._StartsWithRootPath(path): + if not self._starts_with_root_path(path): path = sep + path return path - def _ValidRelativePath(file_path): + def _valid_relative_path(file_path): slash_dotdot = self._matching_string(file_path, '/..') while file_path and slash_dotdot in file_path: file_path = file_path[:file_path.rfind(slash_dotdot)] - if not self.Exists(self.NormalizePath(file_path)): + if not self.exists(self.absnormpath(file_path)): return False return True - def _FollowLink(link_path_components, link): + def _follow_link(link_path_components, link): """Follow a link w.r.t. a path resolved so far. The component is either a real file, which is a no-op, or a symlink. @@ -1642,35 +1727,35 @@ def _FollowLink(link_path_components, link): components = link_path_components[:-1] components.append(link_path) link_path = sep.join(components) - # Don't call self.NormalizePath(), as we don't want to prepend self.cwd. - return self.CollapsePath(link_path) + # Don't call self.absnormpath(), as we don't want to prepend self.cwd. + return self.normpath(link_path) if allow_fd and sys.version_info >= (3, 3) and isinstance(file_path, int): - return self.GetOpenFile(file_path).GetObject().GetPath() + return self._get_open_file(file_path).get_object().GetPath() if sys.version_info >= (3, 6): file_path = os.fspath(file_path) if file_path is None: # file.open(None) raises TypeError, so mimic that. raise TypeError('Expected file system path string, received None') - if not file_path or not _ValidRelativePath(file_path): + if not file_path or not _valid_relative_path(file_path): # file.open('') raises IOError, so mimic that, and validate that all # parts of a relative path exist. raise IOError(errno.ENOENT, 'No such file or directory: \'%s\'' % file_path) - file_path = self.NormalizePath(self.NormalizeCase(file_path)) - if self._IsRootPath(file_path): + file_path = self.absnormpath(self._original_path(file_path)) + if self._is_root_path(file_path): return file_path current_dir = self.root - path_components = self.GetPathComponents(file_path) + path_components = self._path_components(file_path) resolved_components = [] link_depth = 0 while path_components: component = path_components.pop(0) resolved_components.append(component) - current_dir = self._DirectoryContent(current_dir, component)[1] + current_dir = self._directory_content(current_dir, component)[1] if current_dir is None: # The component of the path at this point does not actually exist in # the folder. We can't resolve the path any more. It is legal to link @@ -1681,7 +1766,7 @@ def _FollowLink(link_path_components, link): break # Resolve any possible symlinks in the current path component. - if stat.S_ISLNK(current_dir.st_mode): + if S_ISLNK(current_dir.st_mode): # This link_depth check is not really meant to be an accurate # check. It is just a quick hack to prevent us from looping # forever on cycles. @@ -1690,19 +1775,19 @@ def _FollowLink(link_path_components, link): raise error_class( errno.ELOOP, 'Too many levels of symbolic links: \'%s\'' % - _ComponentsToPath(resolved_components)) - link_path = _FollowLink(resolved_components, current_dir) + _components_to_path(resolved_components)) + link_path = _follow_link(resolved_components, current_dir) # Following the link might result in the complete replacement # of the current_dir, so we evaluate the entire resulting path. - target_components = self.GetPathComponents(link_path) + target_components = self._path_components(link_path) path_components = target_components + path_components resolved_components = [] current_dir = self.root link_depth += 1 - return _ComponentsToPath(resolved_components) + return _components_to_path(resolved_components) - def GetObjectFromNormalizedPath(self, file_path): + def get_object_from_normpath(self, file_path): """Search for the specified filesystem object within the fake filesystem. Args: @@ -1719,13 +1804,13 @@ def GetObjectFromNormalizedPath(self, file_path): file_path = os.fspath(file_path) if file_path == self.root.name: return self.root - path_components = self.GetPathComponents(file_path) + path_components = self._path_components(file_path) target_object = self.root try: for component in path_components: - if stat.S_ISLNK(target_object.st_mode): - target_object = self.ResolveObject(target_object.contents) - if not stat.S_ISDIR(target_object.st_mode): + if S_ISLNK(target_object.st_mode): + target_object = self.resolve(target_object.contents) + if not S_ISDIR(target_object.st_mode): if not self.is_windows_fs: raise IOError(errno.ENOTDIR, 'Not a directory in fake filesystem', @@ -1733,14 +1818,14 @@ def GetObjectFromNormalizedPath(self, file_path): raise IOError(errno.ENOENT, 'No such file or directory in fake filesystem', file_path) - target_object = target_object.GetEntry(component) + target_object = target_object.get_entry(component) except KeyError: raise IOError(errno.ENOENT, 'No such file or directory in fake filesystem', file_path) return target_object - def GetObject(self, file_path): + def get_object(self, file_path): """Search for the specified filesystem object within the fake filesystem. Args: @@ -1754,10 +1839,10 @@ def GetObject(self, file_path): """ if sys.version_info >= (3, 6): file_path = os.fspath(file_path) - file_path = self.NormalizePath(self.NormalizeCase(file_path)) - return self.GetObjectFromNormalizedPath(file_path) + file_path = self.absnormpath(self._original_path(file_path)) + return self.get_object_from_normpath(file_path) - def ResolveObject(self, file_path, follow_symlinks=True, allow_fd=False): + def resolve(self, file_path, follow_symlinks=True, allow_fd=False): """Search for the specified filesystem object, resolving all links. Args: @@ -1773,15 +1858,15 @@ def ResolveObject(self, file_path, follow_symlinks=True, allow_fd=False): IOError: if the object is not found. """ if allow_fd and sys.version_info >= (3, 3) and isinstance(file_path, int): - return self.GetOpenFile(file_path).GetObject() + return self._get_open_file(file_path).get_object() if follow_symlinks: if sys.version_info >= (3, 6): file_path = os.fspath(file_path) - return self.GetObjectFromNormalizedPath(self.ResolvePath(file_path)) - return self.LResolveObject(file_path) + return self.get_object_from_normpath(self.resolve_path(file_path)) + return self.lresolve(file_path) - def LResolveObject(self, path): + def lresolve(self, path): """Search for the specified object, resolving only parent links. This is analogous to the stat/lstat difference. This resolves links *to* @@ -1808,11 +1893,11 @@ def LResolveObject(self, path): if path.endswith(sep) or (alt_sep and path.endswith(alt_sep)): path = path[:-1] - parent_directory, child_name = self.SplitPath(path) + parent_directory, child_name = self.splitpath(path) if not parent_directory: parent_directory = self.cwd try: - parent_obj = self.ResolveObject(parent_directory) + parent_obj = self.resolve(parent_directory) assert parent_obj if not isinstance(parent_obj, FakeDirectory): if not self.is_windows_fs and isinstance(parent_obj, FakeFile): @@ -1821,13 +1906,13 @@ def LResolveObject(self, path): raise IOError(errno.ENOENT, 'No such file or directory in fake filesystem', path) - return parent_obj.GetEntry(child_name) + return parent_obj.get_entry(child_name) except KeyError: raise IOError(errno.ENOENT, 'No such file or directory in the fake filesystem', path) - def AddObject(self, file_path, file_object): + def add_object(self, file_path, file_object): """Add a fake file or directory into the filesystem at file_path. Args: @@ -1840,14 +1925,14 @@ def AddObject(self, file_path, file_object): if not file_path: target_directory = self.root else: - target_directory = self.ResolveObject(file_path) - if not stat.S_ISDIR(target_directory.st_mode): + target_directory = self.resolve(file_path) + if not S_ISDIR(target_directory.st_mode): raise OSError(errno.ENOTDIR, 'Not a directory in the fake filesystem', file_path) - target_directory.AddEntry(file_object) + target_directory.add_entry(file_object) - def RenameObject(self, old_file_path, new_file_path, force_replace=False): + def rename(self, old_file_path, new_file_path, force_replace=False): """Renames a FakeFile object at old_file_path to new_file_path, preserving all properties. Args: @@ -1869,31 +1954,31 @@ def RenameObject(self, old_file_path, new_file_path, force_replace=False): OSError: if dirname(new_file_path) does not exist. OSError: if the file would be moved to another filesystem (e.g. mount point). """ - old_file_path = self.NormalizePath(old_file_path) - new_file_path = self.NormalizePath(new_file_path) - if not self.Exists(old_file_path) and not self.IsLink(old_file_path): + old_file_path = self.absnormpath(old_file_path) + new_file_path = self.absnormpath(new_file_path) + if not self.exists(old_file_path) and not self.islink(old_file_path): raise OSError(errno.ENOENT, 'Fake filesystem object: can not rename nonexistent file', old_file_path) - old_object = self.LResolveObject(old_file_path) + old_object = self.lresolve(old_file_path) if not self.is_windows_fs: - if (self.IsDir(old_file_path, follow_symlinks=False) and - self.IsLink(new_file_path)): + if (self.isdir(old_file_path, follow_symlinks=False) and + self.islink(new_file_path)): raise OSError(errno.ENOTDIR, 'Cannot rename directory to symlink', new_file_path) - if (self.IsDir(new_file_path, follow_symlinks=False) and - self.IsLink(old_file_path)): + if (self.isdir(new_file_path, follow_symlinks=False) and + self.islink(old_file_path)): raise OSError(errno.ENOTDIR, 'Cannot rename symlink to directory', new_file_path) - if self.Exists(new_file_path) or self.IsLink(new_file_path): + if self.exists(new_file_path) or self.islink(new_file_path): if old_file_path == new_file_path: return # Nothing to do here. - new_object = self.GetObject(new_file_path) + new_object = self.get_object(new_file_path) if old_object == new_object: if old_file_path.lower() == new_file_path.lower(): # only case is changed in case-insensitive file system - do the rename @@ -1902,7 +1987,7 @@ def RenameObject(self, old_file_path, new_file_path, force_replace=False): # hard links to the same file - nothing to do return - elif stat.S_ISDIR(new_object.st_mode) or stat.S_ISLNK(new_object.st_mode): + elif S_ISDIR(new_object.st_mode) or S_ISLNK(new_object.st_mode): if self.is_windows_fs: if force_replace: raise OSError(errno.EACCES, @@ -1912,16 +1997,16 @@ def RenameObject(self, old_file_path, new_file_path, force_replace=False): raise OSError(errno.EEXIST, 'Fake filesystem object: can not rename to existing directory', new_file_path) - if not stat.S_ISLNK(new_object.st_mode): + if not S_ISLNK(new_object.st_mode): if new_object.contents: raise OSError(errno.ENOTEMPTY, 'Fake filesystem object: can not rename to non-empty directory', new_file_path) - if stat.S_ISREG(old_object.st_mode): + if S_ISREG(old_object.st_mode): raise OSError(errno.EISDIR, 'Fake filesystem object: cannot rename file to directory', new_file_path) - elif stat.S_ISDIR(old_object.st_mode): + elif S_ISDIR(old_object.st_mode): raise OSError(errno.ENOTDIR, 'Fake filesystem object: cannot rename directory to file', new_file_path) @@ -1931,21 +2016,21 @@ def RenameObject(self, old_file_path, new_file_path, force_replace=False): new_file_path) else: try: - self.RemoveObject(new_file_path) + self.remove_object(new_file_path) except IOError as exc: raise OSError(exc.errno, exc.strerror, exc.filename) - old_dir, old_name = self.SplitPath(old_file_path) - new_dir, new_name = self.SplitPath(new_file_path) - if not self.Exists(new_dir): + old_dir, old_name = self.splitpath(old_file_path) + new_dir, new_name = self.splitpath(new_file_path) + if not self.exists(new_dir): raise OSError(errno.ENOENT, 'No such fake directory', new_dir) - old_dir_object = self.ResolveObject(old_dir) - new_dir_object = self.ResolveObject(new_dir) + old_dir_object = self.resolve(old_dir) + new_dir_object = self.resolve(new_dir) if old_dir_object.st_dev != new_dir_object.st_dev: raise OSError(errno.EXDEV, 'Fake filesystem object: cannot rename across file systems', old_file_path) - if not stat.S_ISDIR(new_dir_object.st_mode): + if not S_ISDIR(new_dir_object.st_mode): raise OSError(errno.EACCES if self.is_windows_fs else errno.ENOTDIR, 'Fake filesystem object: target parent is not a directory', new_file_path) @@ -1954,15 +2039,15 @@ def RenameObject(self, old_file_path, new_file_path, force_replace=False): 'Fake filesystem object: invalid target for rename', new_file_path) - object_to_rename = old_dir_object.GetEntry(old_name) - old_dir_object.RemoveEntry(old_name, recursive=False) + object_to_rename = old_dir_object.get_entry(old_name) + old_dir_object.remove_entry(old_name, recursive=False) object_to_rename.name = new_name if new_name in new_dir_object.contents: # in case of overwriting remove the old entry first - new_dir_object.RemoveEntry(new_name) - new_dir_object.AddEntry(object_to_rename) + new_dir_object.remove_entry(new_name) + new_dir_object.add_entry(object_to_rename) - def RemoveObject(self, file_path): + def remove_object(self, file_path): """Remove an existing file or directory. Args: @@ -1973,14 +2058,14 @@ def RemoveObject(self, file_path): of the path refers to something other than a directory. OSError: if the directory is in use (eg, if it is '/'). """ - file_path = self.NormalizePath(self.NormalizeCase(file_path)) - if self._IsRootPath(file_path): + file_path = self.absnormpath(self._original_path(file_path)) + if self._is_root_path(file_path): raise OSError(errno.EBUSY, 'Fake device or resource busy', file_path) try: - dirname, basename = self.SplitPath(file_path) - target_directory = self.ResolveObject(dirname) - target_directory.RemoveEntry(basename) + dirname, basename = self.splitpath(file_path) + target_directory = self.resolve(dirname) + target_directory.remove_entry(basename) except KeyError: raise IOError(errno.ENOENT, 'No such file or directory in the fake filesystem', @@ -1990,7 +2075,7 @@ def RemoveObject(self, file_path): 'Not a directory in the fake filesystem', file_path) - def CreateDirectory(self, directory_path, perm_bits=PERM_DEF): + def create_dir(self, directory_path, perm_bits=PERM_DEF): """Create directory_path, and all the parent directories. Helper method to set up your test faster. @@ -2005,42 +2090,42 @@ def CreateDirectory(self, directory_path, perm_bits=PERM_DEF): Raises: OSError: if the directory already exists. """ - directory_path = self.NormalizePath(directory_path) - self._AutoMountDriveIfNeeded(directory_path) - if self.Exists(directory_path): + directory_path = self.absnormpath(directory_path) + self._auto_mount_drive_if_needed(directory_path) + if self.exists(directory_path): raise OSError(errno.EEXIST, 'Directory exists in fake filesystem', directory_path) - path_components = self.GetPathComponents(directory_path) + path_components = self._path_components(directory_path) current_dir = self.root new_dirs = [] for component in path_components: - directory = self._DirectoryContent(current_dir, component)[1] + directory = self._directory_content(current_dir, component)[1] if not directory: new_dir = FakeDirectory(component, filesystem=self) new_dirs.append(new_dir) - current_dir.AddEntry(new_dir) + current_dir.add_entry(new_dir) current_dir = new_dir else: - if stat.S_ISLNK(directory.st_mode): - directory = self.ResolveObject(directory.contents) + if S_ISLNK(directory.st_mode): + directory = self.resolve(directory.contents) current_dir = directory - if directory.st_mode & stat.S_IFDIR != stat.S_IFDIR: + if directory.st_mode & S_IFDIR != S_IFDIR: raise OSError(errno.ENOTDIR, 'Not a directory', current_dir.GetPath()) # set the permission after creating the directories # to allow directory creation inside a read-only directory for new_dir in new_dirs: - new_dir.st_mode = stat.S_IFDIR | perm_bits + new_dir.st_mode = S_IFDIR | perm_bits self.last_ino += 1 - current_dir.SetIno(self.last_ino) + current_dir.st_ino = self.last_ino return current_dir - def CreateFile(self, file_path, st_mode=stat.S_IFREG | PERM_DEF_FILE, - contents='', st_size=None, create_missing_dirs=True, - apply_umask=False, encoding=None, errors=None, raw_io=False): + def create_file(self, file_path, st_mode=S_IFREG | PERM_DEF_FILE, + contents='', st_size=None, create_missing_dirs=True, + apply_umask=False, encoding=None, errors=None, raw_io=False): """Create file_path, including all the parent directories along the way. This helper method can be used to set up tests more easily. @@ -2065,7 +2150,7 @@ def CreateFile(self, file_path, st_mode=stat.S_IFREG | PERM_DEF_FILE, IOError: if the file already exists. IOError: if the containing directory is required and missing. """ - return self._CreateFile( + return self._create_file( file_path, st_mode, contents, st_size, create_missing_dirs, apply_umask, encoding, errors, raw_io=raw_io) @@ -2095,9 +2180,9 @@ def add_real_file(self, file_path, read_only=True): Further, Windows offers the option to enable atime, and older \ versions of Linux may also modify atime. """ - return self._CreateFile(file_path, - read_from_real_fs=True, - read_only=read_only) + return self._create_file(file_path, + read_from_real_fs=True, + read_only=read_only) def add_real_directory(self, dir_path, read_only=True, lazy_read=True): """Create a fake directory corresponding to the real directory at the specified @@ -2127,16 +2212,16 @@ def add_real_directory(self, dir_path, read_only=True, lazy_read=True): raise IOError(errno.ENOENT, 'No such directory', dir_path) if lazy_read: parent_path = os.path.split(dir_path)[0] - if self.Exists(parent_path): - parent_dir = self.GetObject(parent_path) + if self.exists(parent_path): + parent_dir = self.get_object(parent_path) else: - parent_dir = self.CreateDirectory(parent_path) + parent_dir = self.create_dir(parent_path) new_dir = FakeDirectoryFromRealDirectory(dir_path, filesystem=self, read_only=read_only) - parent_dir.AddEntry(new_dir) + parent_dir.add_entry(new_dir) self.last_ino += 1 - new_dir.SetIno(self.last_ino) + new_dir.st_ino = self.last_ino else: - new_dir = self.CreateDirectory(dir_path) + new_dir = self.create_dir(dir_path) for base, _, files in os.walk(dir_path): for fileEntry in files: self.add_real_file(os.path.join(base, fileEntry), read_only) @@ -2150,15 +2235,17 @@ def add_real_paths(self, path_list, read_only=True, lazy_dir_read=True): Args: path_list: list of file and directory paths in the real file system. - read_only: if set, all files and files under under the directories are treated as read-only, - e.g. a write access raises an exception; + read_only: if set, all files and files under under the directories + are treated as read-only, e.g. a write access raises an exception; otherwise, writing to the files changes the fake files only as usually. lazy_dir_read: uses lazy reading of directory contents if set (see `add_real_directory`) Raises: - OSError: if any of the files and directories in the list does not exist in the real file system. - OSError: if any of the files and directories in the list already exists in the fake file system. + OSError: if any of the files and directories in the list + does not exist in the real file system. + OSError: if any of the files and directories in the list + already exists in the fake file system. """ for path in path_list: if os.path.isdir(path): @@ -2166,10 +2253,10 @@ def add_real_paths(self, path_list, read_only=True, lazy_dir_read=True): else: self.add_real_file(path, read_only) - def _CreateFile(self, file_path, st_mode=stat.S_IFREG | PERM_DEF_FILE, - contents='', st_size=None, create_missing_dirs=True, - apply_umask=False, encoding=None, errors=None, - read_from_real_fs=False, read_only=True, raw_io=False): + def _create_file(self, file_path, st_mode=S_IFREG | PERM_DEF_FILE, + contents='', st_size=None, create_missing_dirs=True, + apply_umask=False, encoding=None, errors=None, + read_from_real_fs=False, read_only=True, raw_io=False): """Internal fake file creator that supports both normal fake files and fake files based on real files. @@ -2188,48 +2275,49 @@ def _CreateFile(self, file_path, st_mode=stat.S_IFREG | PERM_DEF_FILE, raw_io: `True` if called from low-level API (`os.open`) """ error_class = OSError if raw_io else IOError - file_path = self.NormalizePath(file_path) + file_path = self.absnormpath(file_path) # also consider broken links - if self.Exists(file_path) or self.IsLink(file_path): + if self.exists(file_path) or self.islink(file_path): raise OSError(errno.EEXIST, 'File already exists in fake filesystem', file_path) - parent_directory, new_file = self.SplitPath(file_path) + parent_directory, new_file = self.splitpath(file_path) if not parent_directory: parent_directory = self.cwd - self._AutoMountDriveIfNeeded(parent_directory) - if not self.Exists(parent_directory): + self._auto_mount_drive_if_needed(parent_directory) + if not self.exists(parent_directory): if not create_missing_dirs: raise error_class(errno.ENOENT, 'No such fake directory', parent_directory) - self.CreateDirectory(parent_directory) + self.create_dir(parent_directory) else: - parent_directory = self.NormalizeCase(parent_directory) + parent_directory = self._original_path(parent_directory) if apply_umask: st_mode &= ~self.umask if read_from_real_fs: file_object = FakeFileFromRealFile(file_path, filesystem=self, read_only=read_only) else: - file_object = FakeFile(new_file, st_mode, filesystem=self, encoding=encoding, errors=errors) + file_object = FakeFile(new_file, st_mode, filesystem=self, encoding=encoding, + errors=errors) self.last_ino += 1 - file_object.SetIno(self.last_ino) - self.AddObject(parent_directory, file_object) + file_object.st_ino = self.last_ino + self.add_object(parent_directory, file_object) if not read_from_real_fs and (contents is not None or st_size is not None): try: if st_size is not None: - file_object.SetLargeFileSize(st_size) + file_object.set_large_file_size(st_size) else: file_object._set_initial_contents(contents) except IOError: - self.RemoveObject(file_path) + self.remove_object(file_path) raise return file_object # pylint: disable=unused-argument - def CreateLink(self, file_path, link_target, create_missing_dirs=True): + def symlink(self, file_path, link_target, create_missing_dirs=True): """Create the specified symlink, pointed at the specified link target. Args: @@ -2242,21 +2330,21 @@ def CreateLink(self, file_path, link_target, create_missing_dirs=True): the newly created FakeFile object. Raises: - OSError: if the symlink could not be created (see `CreateFile`). + OSError: if the symlink could not be created (see `create_file`). OSError: if on Windows before Python 3.2. """ - if not self._IsLinkSupported(): + if not self._is_link_supported(): raise OSError("Symbolic links are not supported on Windows before Python 3.2") # resolve the link path only if it is not a link itself - if not self.IsLink(file_path): - file_path = self.ResolvePath(file_path) + if not self.islink(file_path): + file_path = self.resolve_path(file_path) if sys.version_info >= (3, 6): link_target = os.fspath(link_target) - return self.CreateFile(file_path, st_mode=stat.S_IFLNK | PERM_DEF, - contents=link_target, create_missing_dirs=create_missing_dirs, - raw_io=True) + return self.create_file(file_path, st_mode=S_IFLNK | PERM_DEF, + contents=link_target, create_missing_dirs=create_missing_dirs, + raw_io=True) - def CreateHardLink(self, old_path, new_path): + def link(self, old_path, new_path): """Create a hard link at new_path, pointing at old_path. New in pyfakefs 2.9. @@ -2273,41 +2361,41 @@ def CreateHardLink(self, old_path, new_path): OSError: if the parent directory doesn't exist. OSError: if on Windows before Python 3.2. """ - if not self._IsLinkSupported(): + if not self._is_link_supported(): raise OSError("Links are not supported on Windows before Python 3.2") - new_path_normalized = self.NormalizePath(new_path) - if self.Exists(new_path_normalized): + new_path_normalized = self.absnormpath(new_path) + if self.exists(new_path_normalized): raise OSError(errno.EEXIST, 'File already exists in fake filesystem', new_path) - new_parent_directory, new_basename = self.SplitPath(new_path_normalized) + new_parent_directory, new_basename = self.splitpath(new_path_normalized) if not new_parent_directory: new_parent_directory = self.cwd - if not self.Exists(new_parent_directory): + if not self.exists(new_parent_directory): raise OSError(errno.ENOENT, 'No such fake directory', new_parent_directory) # Retrieve the target file try: - old_file = self.ResolveObject(old_path) + old_file = self.resolve(old_path) except: raise OSError(errno.ENOENT, 'No such file or directory in fake filesystem', old_path) - if old_file.st_mode & stat.S_IFDIR: + if old_file.st_mode & S_IFDIR: raise OSError(errno.EACCES if self.is_windows_fs else errno.EPERM, 'Cannot create hard link to directory', old_path) # abuse the name field to control the filename of the newly created link old_file.name = new_basename - self.AddObject(new_parent_directory, old_file) + self.add_object(new_parent_directory, old_file) return old_file - def ReadLink(self, path): + def readlink(self, path): """Read the target of a symlink. New in pyfakefs 3.0. @@ -2325,14 +2413,14 @@ def ReadLink(self, path): if path is None: raise TypeError try: - link_obj = self.LResolveObject(path) + link_obj = self.lresolve(path) except IOError as exc: raise OSError(exc.errno, 'Fake path does not exist', path) - if stat.S_IFMT(link_obj.st_mode) != stat.S_IFLNK: + if S_IFMT(link_obj.st_mode) != S_IFLNK: raise OSError(errno.EINVAL, 'Fake filesystem: not a symlink', path) return link_obj.contents - def MakeDirectory(self, dir_name, mode=PERM_DEF): + def makedir(self, dir_name, mode=PERM_DEF): """Create a leaf Fake directory. New in pyfakefs 3.0. @@ -2344,33 +2432,33 @@ def MakeDirectory(self, dir_name, mode=PERM_DEF): Raises: OSError: if the directory name is invalid or parent directory is read only - or as per `FakeFilesystem.AddObject()`. + or as per `FakeFilesystem.add_object()`. """ if sys.version_info >= (3, 6): dir_name = os.fspath(dir_name) - if self._EndsWithPathSeparator(dir_name): + if self._ends_with_path_separator(dir_name): dir_name = dir_name[:-1] if not dir_name: raise OSError(errno.ENOENT, 'Empty directory name') - parent_dir, _ = self.SplitPath(dir_name) + parent_dir, _ = self.splitpath(dir_name) if parent_dir: - base_dir = self.CollapsePath(parent_dir) + base_dir = self.normpath(parent_dir) ellipsis = self._matching_string(parent_dir, self.path_separator + '..') if parent_dir.endswith(ellipsis): base_dir, dummy_dotdot, _ = parent_dir.partition(ellipsis) - if not self.Exists(base_dir): + if not self.exists(base_dir): raise OSError(errno.ENOENT, 'No such fake directory', base_dir) - dir_name = self.NormalizePath(dir_name) - if self.Exists(dir_name): + dir_name = self.absnormpath(dir_name) + if self.exists(dir_name): raise OSError(errno.EEXIST, 'Fake object already exists', dir_name) - head, tail = self.SplitPath(dir_name) + head, tail = self.splitpath(dir_name) - self.AddObject( + self.add_object( head, FakeDirectory(tail, mode & ~self.umask, filesystem=self)) - def MakeDirectories(self, dir_name, mode=PERM_DEF, exist_ok=False): + def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=False): """Create a leaf Fake directory and create any non-existent parent dirs. New in pyfakefs 3.0. @@ -2384,10 +2472,10 @@ def MakeDirectories(self, dir_name, mode=PERM_DEF, exist_ok=False): Raises: OSError: if the directory already exists and exist_ok=False, or as per - `FakeFilesystem.CreateDirectory()`. + `FakeFilesystem.create_dir()`. """ - dir_name = self.NormalizePath(dir_name) - path_components = self.GetPathComponents(dir_name) + dir_name = self.absnormpath(dir_name) + path_components = self._path_components(dir_name) # Raise a permission denied error if the first existing directory is not # writeable. @@ -2399,15 +2487,15 @@ def MakeDirectories(self, dir_name, mode=PERM_DEF, exist_ok=False): else: current_dir = current_dir.contents[component] try: - self.CreateDirectory(dir_name, mode & ~self.umask) + self.create_dir(dir_name, mode & ~self.umask) except (IOError, OSError) as e: if (not exist_ok or - not isinstance(self.ResolveObject(dir_name), FakeDirectory)): + not isinstance(self.resolve(dir_name), FakeDirectory)): if isinstance(e, OSError): raise raise OSError(e.errno, e.strerror, e.filename) - def _IsType(self, path, st_flag, follow_symlinks=True): + def _istype(self, path, st_flag, follow_symlinks=True): """Helper function to implement isdir(), islink(), etc. See the stat(2) man page for valid stat.S_I* flag values @@ -2427,14 +2515,14 @@ def _IsType(self, path, st_flag, follow_symlinks=True): if path is None: raise TypeError try: - obj = self.ResolveObject(path, follow_symlinks) + obj = self.resolve(path, follow_symlinks) if obj: - return stat.S_IFMT(obj.st_mode) == st_flag + return S_IFMT(obj.st_mode) == st_flag except (IOError, OSError): return False return False - def IsDir(self, path, follow_symlinks=True): + def isdir(self, path, follow_symlinks=True): """Determine if path identifies a directory. New in pyfakefs 3.0. @@ -2447,9 +2535,9 @@ def IsDir(self, path, follow_symlinks=True): Raises: TypeError: if path is None. """ - return self._IsType(path, stat.S_IFDIR, follow_symlinks) + return self._istype(path, S_IFDIR, follow_symlinks) - def IsFile(self, path, follow_symlinks=True): + def isfile(self, path, follow_symlinks=True): """Determine if path identifies a regular file. New in pyfakefs 3.0. @@ -2462,9 +2550,9 @@ def IsFile(self, path, follow_symlinks=True): Raises: TypeError: if path is None. """ - return self._IsType(path, stat.S_IFREG, follow_symlinks) + return self._istype(path, S_IFREG, follow_symlinks) - def IsLink(self, path): + def islink(self, path): """Determine if path identifies a symbolic link. New in pyfakefs 3.0. @@ -2477,9 +2565,9 @@ def IsLink(self, path): Raises: TypeError: if path is None. """ - return self._IsType(path, stat.S_IFLNK, follow_symlinks=False) + return self._istype(path, S_IFLNK, follow_symlinks=False) - def ConfirmDir(self, target_directory): + def confirmdir(self, target_directory): """Test that the target is actually a directory, raising OSError if not. New in pyfakefs 3.0. @@ -2493,16 +2581,16 @@ def ConfirmDir(self, target_directory): OSError: if the target is not a directory. """ try: - directory = self.ResolveObject(target_directory) + directory = self.resolve(target_directory) except IOError as exc: raise OSError(exc.errno, exc.strerror, target_directory) - if not directory.st_mode & stat.S_IFDIR: + if not directory.st_mode & S_IFDIR: raise OSError(errno.ENOTDIR, 'Fake os module: not a directory', target_directory) return directory - def RemoveFile(self, path): + def remove(self, path): """Remove the FakeFile object at the specified file path. New in pyfakefs 3.0. @@ -2514,20 +2602,20 @@ def RemoveFile(self, path): OSError: if path does not exist. OSError: if removal failed. """ - path = self.NormalizePath(path) - if self.Exists(path): - obj = self.ResolveObject(path) - if stat.S_IFMT(obj.st_mode) == stat.S_IFDIR: - link_obj = self.LResolveObject(path) - if stat.S_IFMT(link_obj.st_mode) != stat.S_IFLNK: + path = self.absnormpath(path) + if self.exists(path): + obj = self.resolve(path) + if S_IFMT(obj.st_mode) == S_IFDIR: + link_obj = self.lresolve(path) + if S_IFMT(link_obj.st_mode) != S_IFLNK: raise OSError(errno.EISDIR, "Is a directory: '%s'" % path) try: - self.RemoveObject(path) + self.remove_object(path) except IOError as exc: raise OSError(exc.errno, exc.strerror, exc.filename) - def RemoveDirectory(self, target_directory, allow_symlink=False): + def rmdir(self, target_directory, allow_symlink=False): """Remove a leaf Fake directory. New in pyfakefs 3.0. @@ -2539,27 +2627,27 @@ def RemoveDirectory(self, target_directory, allow_symlink=False): Raises: OSError: if target_directory does not exist. OSError: if target_directory does not point to a directory. - OSError: if removal failed per FakeFilesystem.RemoveObject. Cannot remove '.'. + OSError: if removal failed per FakeFilesystem.remove_object. Cannot remove '.'. """ if target_directory in (b'.', u'.'): raise OSError(errno.EINVAL, 'Invalid argument: \'.\'') - target_directory = self.NormalizePath(target_directory) - if self.ConfirmDir(target_directory): - if not self.is_windows_fs and self.IsLink(target_directory): + target_directory = self.absnormpath(target_directory) + if self.confirmdir(target_directory): + if not self.is_windows_fs and self.islink(target_directory): if allow_symlink: return raise OSError(errno.ENOTDIR, 'Cannot remove symlink', target_directory) - dir_object = self.ResolveObject(target_directory) + dir_object = self.resolve(target_directory) if dir_object.contents: raise OSError(errno.ENOTEMPTY, 'Fake Directory not empty', target_directory) try: - self.RemoveObject(target_directory) + self.remove_object(target_directory) except IOError as exc: raise OSError(exc.errno, exc.strerror, exc.filename) - def ListDir(self, target_directory): + def listdir(self, target_directory): """Return a list of file names in target_directory. New in pyfakefs 3.0. @@ -2572,8 +2660,8 @@ def ListDir(self, target_directory): Raises: OSError: if the target is not a directory. """ - target_directory = self.ResolvePath(target_directory, allow_fd=True) - directory = self.ConfirmDir(target_directory) + target_directory = self.resolve_path(target_directory, allow_fd=True) + directory = self.confirmdir(target_directory) directory_contents = directory.contents return list(directory_contents.keys()) @@ -2641,7 +2729,7 @@ def stat(self, follow_symlinks=True): """ if follow_symlinks: if self._statresult_symlink is None: - file_object = self._filesystem.ResolveObject(self.path) + file_object = self._filesystem.resolve(self.path) if self._filesystem.is_windows_fs: # under Windows, some properties are 0 # probably due to performance reasons @@ -2652,7 +2740,7 @@ def stat(self, follow_symlinks=True): return self._statresult_symlink if self._statresult is None: - file_object = self._filesystem.LResolveObject(self.path) + file_object = self._filesystem.lresolve(self.path) self._inode = file_object.st_ino if self._filesystem.is_windows_fs: file_object.st_ino = 0 @@ -2668,10 +2756,10 @@ class ScanDirIter: def __init__(self, filesystem, path): self.filesystem = filesystem - self.path = self.filesystem.ResolvePath(path) + self.path = self.filesystem.resolve_path(path) contents = {} try: - contents = self.filesystem.ConfirmDir(path).contents + contents = self.filesystem.confirmdir(path).contents except OSError: pass self.contents_iter = iter(contents) @@ -2683,9 +2771,9 @@ def __next__(self): entry = self.contents_iter.__next__() dir_entry = self.filesystem.DirEntry(self.filesystem) dir_entry.name = entry - dir_entry.path = self.filesystem.JoinPaths(self.path, dir_entry.name) - dir_entry._isdir = self.filesystem.IsDir(dir_entry.path) - dir_entry._islink = self.filesystem.IsLink(dir_entry.path) + dir_entry.path = self.filesystem.joinpaths(self.path, dir_entry.name) + dir_entry._isdir = self.filesystem.isdir(dir_entry.path) + dir_entry._islink = self.filesystem.islink(dir_entry.path) return dir_entry if sys.version_info >= (3, 6): @@ -2718,6 +2806,51 @@ def __str__(self): return str(self.root) +Deprecator.add(FakeFilesystem, FakeFilesystem.get_disk_usage, 'GetDiskUsage') +Deprecator.add(FakeFilesystem, FakeFilesystem.set_disk_usage, 'SetDiskUsage') +Deprecator.add(FakeFilesystem, FakeFilesystem.change_disk_usage, 'ChangeDiskUsage') +Deprecator.add(FakeFilesystem, FakeFilesystem.add_mount_point, 'AddMountPoint') +Deprecator.add(FakeFilesystem, FakeFilesystem.stat, 'GetStat') +Deprecator.add(FakeFilesystem, FakeFilesystem.chmod, 'ChangeMode') +Deprecator.add(FakeFilesystem, FakeFilesystem.utime, 'UpdateTime') +Deprecator.add(FakeFilesystem, FakeFilesystem._add_open_file, 'AddOpenFile') +Deprecator.add(FakeFilesystem, FakeFilesystem._close_open_file, 'CloseOpenFile') +Deprecator.add(FakeFilesystem, FakeFilesystem.has_open_file, 'HasOpenFile') +Deprecator.add(FakeFilesystem, FakeFilesystem._get_open_file, 'GetOpenFile') +Deprecator.add(FakeFilesystem, FakeFilesystem.normcase, 'NormalizePathSeparator') +Deprecator.add(FakeFilesystem, FakeFilesystem.normpath, 'CollapsePath') +Deprecator.add(FakeFilesystem, FakeFilesystem._original_path, 'NormalizeCase') +Deprecator.add(FakeFilesystem, FakeFilesystem.absnormpath, 'NormalizePath') +Deprecator.add(FakeFilesystem, FakeFilesystem.splitpath, 'SplitPath') +Deprecator.add(FakeFilesystem, FakeFilesystem.splitdrive, 'SplitDrive') +Deprecator.add(FakeFilesystem, FakeFilesystem.joinpaths, 'JoinPaths') +Deprecator.add(FakeFilesystem, FakeFilesystem._path_components, 'GetPathComponents') +Deprecator.add(FakeFilesystem, FakeFilesystem._starts_with_drive_letter, 'StartsWithDriveLetter') +Deprecator.add(FakeFilesystem, FakeFilesystem.exists, 'Exists') +Deprecator.add(FakeFilesystem, FakeFilesystem.resolve_path, 'ResolvePath') +Deprecator.add(FakeFilesystem, FakeFilesystem.get_object_from_normpath, 'GetObjectFromNormalizedPath') +Deprecator.add(FakeFilesystem, FakeFilesystem.get_object, 'GetObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.resolve, 'ResolveObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.lresolve, 'LResolveObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.add_object, 'AddObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.remove_object, 'RemoveObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.rename, 'RenameObject') +Deprecator.add(FakeFilesystem, FakeFilesystem.create_dir, 'CreateDirectory') +Deprecator.add(FakeFilesystem, FakeFilesystem.create_file, 'CreateFile') +Deprecator.add(FakeFilesystem, FakeFilesystem.symlink, 'CreateLink') +Deprecator.add(FakeFilesystem, FakeFilesystem.link, 'CreateHardLink') +Deprecator.add(FakeFilesystem, FakeFilesystem.readlink, 'ReadLink') +Deprecator.add(FakeFilesystem, FakeFilesystem.makedir, 'MakeDirectory') +Deprecator.add(FakeFilesystem, FakeFilesystem.makedirs, 'MakeDirectories') +Deprecator.add(FakeFilesystem, FakeFilesystem.isdir, 'IsDir') +Deprecator.add(FakeFilesystem, FakeFilesystem.isfile, 'IsFile') +Deprecator.add(FakeFilesystem, FakeFilesystem.islink, 'IsLink') +Deprecator.add(FakeFilesystem, FakeFilesystem.confirmdir, 'ConfirmDir') +Deprecator.add(FakeFilesystem, FakeFilesystem.remove, 'RemoveFile') +Deprecator.add(FakeFilesystem, FakeFilesystem.rmdir, 'RemoveDirectory') +Deprecator.add(FakeFilesystem, FakeFilesystem.listdir, 'ListDir') + + class FakePathModule(object): """Faked os.path module replacement. @@ -2751,7 +2884,7 @@ def exists(self, path): Returns: bool (if file exists). """ - return self.filesystem.Exists(path) + return self.filesystem.exists(path) def lexists(self, path): """Test whether a path exists. Returns True for broken symbolic links. @@ -2774,7 +2907,7 @@ def getsize(self, path): file size in bytes. """ try: - file_obj = self.filesystem.ResolveObject(path) + file_obj = self.filesystem.resolve(path) return file_obj.st_size except IOError as exc: raise os.error(exc.errno, exc.strerror) @@ -2794,11 +2927,11 @@ def isabs(self, path): def isdir(self, path): """Determine if path identifies a directory.""" - return self.filesystem.IsDir(path) + return self.filesystem.isdir(path) def isfile(self, path): """Determine if path identifies a regular file.""" - return self.filesystem.IsFile(path) + return self.filesystem.isfile(path) def islink(self, path): """Determine if path identifies a symbolic link. @@ -2812,7 +2945,7 @@ def islink(self, path): Raises: TypeError: if path is None. """ - return self.filesystem.IsLink(path) + return self.filesystem.islink(path) def getmtime(self, path): """Returns the modification time of the fake file. @@ -2828,7 +2961,7 @@ def getmtime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.ResolveObject(path) + file_obj = self.filesystem.resolve(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_mtime @@ -2848,7 +2981,7 @@ def getatime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.ResolveObject(path) + file_obj = self.filesystem.resolve(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_atime @@ -2866,7 +2999,7 @@ def getctime(self, path): OSError: if the file does not exist. """ try: - file_obj = self.filesystem.ResolveObject(path) + file_obj = self.filesystem.resolve(path) except IOError as exc: raise OSError(errno.ENOENT, str(exc)) return file_obj.st_ctime @@ -2895,35 +3028,35 @@ def getcwd(): path.startswith(sep) or altsep is not None and path.startswith(altsep)): cwd = getcwd() - if self.filesystem.StartsWithDriveLetter(cwd): + if self.filesystem._starts_with_drive_letter(cwd): path = self.join(cwd[:2], path) return self.normpath(path) def join(self, *p): """Return the completed path with a separator of the parts.""" - return self.filesystem.JoinPaths(*p) + return self.filesystem.joinpaths(*p) def split(self, path): """Split the path into the directory and the filename of the path. New in pyfakefs 3.0. """ - return self.filesystem.SplitPath(path) + return self.filesystem.splitpath(path) def splitdrive(self, path): """Split the path into the drive part and the rest of the path, if supported. New in pyfakefs 2.9. """ - return self.filesystem.SplitDrive(path) + return self.filesystem.splitdrive(path) def normpath(self, path): """Normalize path, eliminating double slashes, etc.""" - return self.filesystem.CollapsePath(path) + return self.filesystem.normpath(path) def normcase(self, path): """Convert to lower case under windows, replaces additional path separator. New in pyfakefs 2.9. """ - path = self.filesystem.NormalizePathSeparator(path) + path = self.filesystem.normcase(path) if self.filesystem.is_windows_fs: path = path.lower() return path @@ -2971,8 +3104,8 @@ def samefile(self, path1, path2): Raises: OSError: if one of the paths does not point to an existing file system object. """ - stat1 = self.filesystem.GetStat(path1) - stat2 = self.filesystem.GetStat(path2) + stat1 = self.filesystem.stat(path1) + stat2 = self.filesystem.stat(path2) return stat1.st_ino == stat2.st_ino and stat1.st_dev == stat2.st_dev def _joinrealpath(self, path, rest, seen): @@ -2996,14 +3129,14 @@ def _joinrealpath(self, path, rest, seen): if name == pardir: # parent dir if path: - path, name = self.filesystem.SplitPath(path) + path, name = self.filesystem.splitpath(path) if name == pardir: - path = self.filesystem.JoinPaths(path, pardir, pardir) + path = self.filesystem.joinpaths(path, pardir, pardir) else: path = pardir continue - newpath = self.filesystem.JoinPaths(path, name) - if not self.filesystem.IsLink(newpath): + newpath = self.filesystem.joinpaths(path, name) + if not self.filesystem.islink(newpath): path = newpath continue # Resolve the symbolic link @@ -3015,11 +3148,11 @@ def _joinrealpath(self, path, rest, seen): continue # The symlink is not resolved, so we must have a symlink loop. # Return already resolved part + rest of the path unchanged. - return self.filesystem.JoinPaths(newpath, rest), False + return self.filesystem.joinpaths(newpath, rest), False seen[newpath] = None # not resolved symlink - path, ok = self._joinrealpath(path, self.filesystem.ReadLink(newpath), seen) + path, ok = self._joinrealpath(path, self.filesystem.readlink(newpath), seen) if not ok: - return self.filesystem.JoinPaths(path, rest), False + return self.filesystem.joinpaths(path, rest), False seen[newpath] = path # resolved symlink return path, True @@ -3050,7 +3183,7 @@ def ismount(self, path): path = os.fspath(path) if not path: return False - normed_path = self.filesystem.NormalizePath(path) + normed_path = self.filesystem.absnormpath(path) sep = self.filesystem._path_separator(path) if self.filesystem.is_windows_fs: if self.filesystem.alternative_path_separator is not None: @@ -3059,7 +3192,7 @@ def ismount(self, path): ) else: path_seps = (sep,) - drive, rest = self.filesystem.SplitDrive(normed_path) + drive, rest = self.filesystem.splitdrive(normed_path) if drive and drive[:1] in path_seps: return (not rest) or (rest in path_seps) if rest in path_seps: @@ -3080,21 +3213,21 @@ def walk(self, top, func, arg): arg: first argument to be called with func (apart from dirname and filenames). """ try: - names = self.filesystem.ListDir(top) + names = self.filesystem.listdir(top) except os.error: return func(arg, top, names) for name in names: - name = self.filesystem.JoinPaths(top, name) + name = self.filesystem.joinpaths(top, name) if self.filesystem.is_windows_fs: - if self.filesystem.IsDir(name): + if self.filesystem.isdir(name): self.walk(name, func, arg) else: try: - st = self.filesystem.GetStat(name, follow_symlinks=False) + st = self.filesystem.stat(name, follow_symlinks=False) except os.error: continue - if stat.S_ISDIR(st.st_mode): + if S_ISDIR(st.st_mode): self.walk(name, func, arg) def __getattr__(self, name): @@ -3176,7 +3309,7 @@ def _fdopen_ver2(self, file_des, mode='r', bufsize=None): # pylint: disable=unu raise TypeError('an integer is required') try: - return FakeFileOpen(self.filesystem).Call(file_des, mode=mode) + return FakeFileOpen(self.filesystem).call(file_des, mode=mode) except IOError as exc: raise OSError(exc) @@ -3237,12 +3370,12 @@ def open(self, file_path, flags, mode=None, dir_fd=None): if (not self.filesystem.is_windows_fs and not open_modes.can_write and - self.filesystem.Exists(file_path)): + self.filesystem.exists(file_path)): # handle opening directory - only allowed under Posix with read-only mode - obj = self.filesystem.ResolveObject(file_path) + obj = self.filesystem.resolve(file_path) if isinstance(obj, FakeDirectory): dir_wrapper = FakeDirWrapper(obj, file_path, self.filesystem) - file_des = self.filesystem.AddOpenFile(dir_wrapper) + file_des = self.filesystem._add_open_file(dir_wrapper) dir_wrapper.filedes = file_des return file_des @@ -3267,7 +3400,7 @@ def close(self, file_des): OSError: bad file descriptor. TypeError: if file descriptor is not an integer. """ - file_handle = self.filesystem.GetOpenFile(file_des) + file_handle = self.filesystem._get_open_file(file_des) file_handle.close() def read(self, file_des, num_bytes): @@ -3284,7 +3417,7 @@ def read(self, file_des, num_bytes): OSError: bad file descriptor. TypeError: if file descriptor is not an integer. """ - file_handle = self.filesystem.GetOpenFile(file_des) + file_handle = self.filesystem._get_open_file(file_des) file_handle.raw_io = True return file_handle.read(num_bytes) @@ -3302,7 +3435,7 @@ def write(self, file_des, contents): OSError: bad file descriptor. TypeError: if file descriptor is not an integer. """ - file_handle = self.filesystem.GetOpenFile(file_des) + file_handle = self.filesystem._get_open_file(file_des) file_handle.raw_io = True file_handle._sync_io() file_handle.write(contents) @@ -3338,7 +3471,7 @@ def fstat(self, file_des): OSError: if the filesystem object doesn't exist. """ # stat should return the tuple representing return value of os.stat - file_object = self.filesystem.GetOpenFile(file_des).GetObject() + file_object = self.filesystem._get_open_file(file_des).get_object() return file_object.stat_result.copy() def umask(self, new_mask): @@ -3369,9 +3502,9 @@ def chdir(self, target_directory): OSError: if user lacks permission to enter the argument directory or if the target is not a directory """ - target_directory = self.filesystem.ResolvePath(target_directory, allow_fd=True) - self.filesystem.ConfirmDir(target_directory) - directory = self.filesystem.ResolveObject(target_directory) + target_directory = self.filesystem.resolve_path(target_directory, allow_fd=True) + self.filesystem.confirmdir(target_directory) + directory = self.filesystem.resolve(target_directory) # A full implementation would check permissions all the way up the tree. if not directory.st_mode | PERM_EXE: raise OSError(errno.EACCES, 'Fake os module: permission denied', @@ -3405,7 +3538,7 @@ def listdir(self, target_directory): Raises: OSError: if the target is not a directory. """ - return self.filesystem.ListDir(target_directory) + return self.filesystem.listdir(target_directory) if sys.platform.startswith('linux') and sys.version_info >= (3, 3): def listxattr(self, path=None, follow_symlinks=True): @@ -3428,7 +3561,7 @@ def scandir(self, path=''): """ return self.filesystem.ScanDir(path) - def _ClassifyDirectoryContents(self, root): + def _classify_dir_contents(self, root): """Classify contents of a directory as files/directories. Args: @@ -3475,7 +3608,7 @@ def do_walk(top, topMost=False): if not topMost and not followlinks and self.path.islink(top): return try: - top_contents = self._ClassifyDirectoryContents(top) + top_contents = self._classify_dir_contents(top) except OSError as exc: top_contents = None if onerror is not None: @@ -3515,7 +3648,7 @@ def readlink(self, path, dir_fd=None): (with errno=EINVAL) if path is valid, but is not a symlink. """ path = self._path_with_dir_fd(path, self.readlink, dir_fd) - return self.filesystem.ReadLink(path) + return self.filesystem.readlink(path) def stat(self, entry_path, dir_fd=None, follow_symlinks=None): """Return the os.stat-like tuple for the FakeFile object of entry_path. @@ -3540,7 +3673,7 @@ def stat(self, entry_path, dir_fd=None, follow_symlinks=None): elif sys.version_info < (3, 3): raise TypeError("stat() got an unexpected keyword argument 'follow_symlinks'") entry_path = self._path_with_dir_fd(entry_path, self.stat, dir_fd) - return self.filesystem.GetStat(entry_path, follow_symlinks) + return self.filesystem.stat(entry_path, follow_symlinks) def lstat(self, entry_path, dir_fd=None): """Return the os.stat-like tuple for entry_path, not following symlinks. @@ -3559,7 +3692,7 @@ def lstat(self, entry_path, dir_fd=None): """ # stat should return the tuple representing return value of os.stat entry_path = self._path_with_dir_fd(entry_path, self.lstat, dir_fd) - return self.filesystem.GetStat(entry_path, follow_symlinks=False) + return self.filesystem.stat(entry_path, follow_symlinks=False) def remove(self, path, dir_fd=None): """Remove the FakeFile object at the specified file path. @@ -3576,7 +3709,7 @@ def remove(self, path, dir_fd=None): OSError: if removal failed. """ path = self._path_with_dir_fd(path, self.remove, dir_fd) - self.filesystem.RemoveFile(path) + self.filesystem.remove(path) def unlink(self, path, dir_fd=None): """Remove the FakeFile object at the specified file path. @@ -3593,7 +3726,7 @@ def unlink(self, path, dir_fd=None): OSError: if removal failed. """ path = self._path_with_dir_fd(path, self.unlink, dir_fd) - self.filesystem.RemoveFile(path) + self.filesystem.remove(path) def rename(self, old_file_path, new_file_path, dir_fd=None): """Rename a FakeFile object at old_file_path to new_file_path, @@ -3616,7 +3749,7 @@ def rename(self, old_file_path, new_file_path, dir_fd=None): OSError: if the file would be moved to another filesystem (e.g. mount point) """ old_file_path = self._path_with_dir_fd(old_file_path, self.rename, dir_fd) - self.filesystem.RenameObject(old_file_path, new_file_path) + self.filesystem.rename(old_file_path, new_file_path) if sys.version_info >= (3, 3): def replace(self, old_file_path, new_file_path): @@ -3636,7 +3769,7 @@ def replace(self, old_file_path, new_file_path): OSError: if `dirname(new_file)` does not exist OSError: if the file would be moved to another filesystem (e.g. mount point) """ - self.filesystem.RenameObject(old_file_path, new_file_path, force_replace=True) + self.filesystem.rename(old_file_path, new_file_path, force_replace=True) def rmdir(self, target_directory, dir_fd=None): """Remove a leaf Fake directory. @@ -3649,10 +3782,10 @@ def rmdir(self, target_directory, dir_fd=None): Raises: OSError: if target_directory does not exist or is not a directory, - or as per FakeFilesystem.RemoveObject. Cannot remove '.'. + or as per FakeFilesystem.remove_object. Cannot remove '.'. """ target_directory= self._path_with_dir_fd(target_directory, self.rmdir, dir_fd) - self.filesystem.RemoveDirectory(target_directory) + self.filesystem.rmdir(target_directory) def removedirs(self, target_directory): """Remove a leaf fake directory and all empty intermediate ones. @@ -3664,8 +3797,8 @@ def removedirs(self, target_directory): OSError: if target_directory does not exist or is not a directory. OSError: if target_directory is not empty. """ - target_directory = self.filesystem.NormalizePath(target_directory) - directory = self.filesystem.ConfirmDir(target_directory) + target_directory = self.filesystem.absnormpath(target_directory) + directory = self.filesystem.confirmdir(target_directory) if directory.contents: raise OSError(errno.ENOTEMPTY, 'Fake Directory not empty', self.path.basename(target_directory)) @@ -3675,11 +3808,11 @@ def removedirs(self, target_directory): if not tail: head, tail = self.path.split(head) while head and tail: - head_dir = self.filesystem.ConfirmDir(head) + head_dir = self.filesystem.confirmdir(head) if head_dir.contents: break # only the top-level dir may not be a symlink - self.filesystem.RemoveDirectory(head, allow_symlink=True) + self.filesystem.rmdir(head, allow_symlink=True) head, tail = self.path.split(head) def mkdir(self, dir_name, mode=PERM_DEF, dir_fd=None): @@ -3696,10 +3829,10 @@ def mkdir(self, dir_name, mode=PERM_DEF, dir_fd=None): Raises: OSError: if the directory name is invalid or parent directory is read only - or as per FakeFilesystem.AddObject. + or as per FakeFilesystem.add_object. """ dir_name = self._path_with_dir_fd(dir_name, self.mkdir, dir_fd) - self.filesystem.MakeDirectory(dir_name, mode) + self.filesystem.makedir(dir_name, mode) def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=None): """Create a leaf Fake directory + create any non-existent parent dirs. @@ -3715,13 +3848,13 @@ def makedirs(self, dir_name, mode=PERM_DEF, exist_ok=None): Raises: OSError: if the directory already exists and exist_ok=False, or as per - `FakeFilesystem.CreateDirectory()`. + `FakeFilesystem.create_dir()`. """ if exist_ok is None: exist_ok = False elif sys.version_info < (3, 2): raise TypeError("makedir() got an unexpected keyword argument 'exist_ok'") - self.filesystem.MakeDirectories(dir_name, mode, exist_ok) + self.filesystem.makedirs(dir_name, mode, exist_ok) def _path_with_dir_fd(self, path, fct, dir_fd): """Return the path considering dir_fd. Raise on nmvalid parameters.""" @@ -3738,7 +3871,7 @@ def _path_with_dir_fd(self, path, fct, dir_fd): "%s: Can't specify dir_fd without matching path" % fct.__name__) if not self.path.isabs(path): return self.path.join( - self.filesystem.GetOpenFile(dir_fd).GetObject().GetPath(), path) + self.filesystem._get_open_file(dir_fd).get_object().GetPath(), path) return path def access(self, path, mode, dir_fd=None, follow_symlinks=None): @@ -3787,7 +3920,7 @@ def chmod(self, path, mode, dir_fd=None, follow_symlinks=None): elif sys.version_info < (3, 3): raise TypeError("chmod() got an unexpected keyword argument 'follow_symlinks'") path = self._path_with_dir_fd(path, self.chmod, dir_fd) - self.filesystem.ChangeMode(path, mode, follow_symlinks) + self.filesystem.chmod(path, mode, follow_symlinks) def lchmod(self, path, mode): """Change the permissions of a file as encoded in integer mode. @@ -3799,7 +3932,7 @@ def lchmod(self, path, mode): """ if self.filesystem.is_windows_fs: raise (NameError, "name 'lchmod' is not defined") - self.filesystem.ChangeMode(path, mode, follow_symlinks=False) + self.filesystem.chmod(path, mode, follow_symlinks=False) def utime(self, path, times=None, ns=None, dir_fd=None, follow_symlinks=None): """Change the access and modified times of a file. @@ -3834,7 +3967,7 @@ def utime(self, path, times=None, ns=None, dir_fd=None, follow_symlinks=None): if ns is not None and sys.version_info < (3, 3): raise TypeError("utime() got an unexpected keyword argument 'ns'") - self.filesystem.UpdateTime(path, times, ns, follow_symlinks) + self.filesystem.utime(path, times, ns, follow_symlinks) def chown(self, path, uid, gid, dir_fd=None, follow_symlinks=None): """Set ownership of a faked file. @@ -3862,7 +3995,7 @@ def chown(self, path, uid, gid, dir_fd=None, follow_symlinks=None): raise TypeError("chown() got an unexpected keyword argument 'follow_symlinks'") path = self._path_with_dir_fd(path, self.chown, dir_fd) try: - file_object = self.filesystem.ResolveObject(path, follow_symlinks, allow_fd=True) + file_object = self.filesystem.resolve(path, follow_symlinks, allow_fd=True) except IOError as io_error: if io_error.errno == errno.ENOENT: raise OSError(errno.ENOENT, @@ -3899,8 +4032,8 @@ def mknod(self, filename, mode=None, device=None, dir_fd=None): created. """ if mode is None: - mode = stat.S_IFREG | PERM_DEF_FILE - if device or not mode & stat.S_IFREG: + mode = S_IFREG | PERM_DEF_FILE + if device or not mode & S_IFREG: raise OSError(errno.EINVAL, 'Fake os mknod implementation only supports ' 'regular files.') @@ -3908,18 +4041,18 @@ def mknod(self, filename, mode=None, device=None, dir_fd=None): filename = self._path_with_dir_fd(filename, self.mknod, dir_fd) head, tail = self.path.split(filename) if not tail: - if self.filesystem.Exists(head): + if self.filesystem.exists(head): raise OSError(errno.EEXIST, 'Fake filesystem: %s: %s' % ( os.strerror(errno.EEXIST), filename)) raise OSError(errno.ENOENT, 'Fake filesystem: %s: %s' % ( os.strerror(errno.ENOENT), filename)) - if tail in (b'.', u'.', b'..', u'..') or self.filesystem.Exists(filename): + if tail in (b'.', u'.', b'..', u'..') or self.filesystem.exists(filename): raise OSError(errno.EEXIST, 'Fake fileystem: %s: %s' % ( os.strerror(errno.EEXIST), filename)) try: - self.filesystem.AddObject(head, FakeFile(tail, - mode & ~self.filesystem.umask, - filesystem=self.filesystem)) + self.filesystem.add_object(head, FakeFile(tail, + mode & ~self.filesystem.umask, + filesystem=self.filesystem)) except IOError: raise OSError(errno.ENOTDIR, 'Fake filesystem: %s: %s' % ( os.strerror(errno.ENOTDIR), filename)) @@ -3938,7 +4071,7 @@ def symlink(self, link_target, path, dir_fd=None): OSError: if the file already exists. """ link_target = self._path_with_dir_fd(link_target, self.symlink, dir_fd) - self.filesystem.CreateLink(path, link_target, create_missing_dirs=False) + self.filesystem.symlink(path, link_target, create_missing_dirs=False) def link(self, oldpath, newpath, dir_fd=None): """Create a hard link at new_path, pointing at old_path. @@ -3960,7 +4093,7 @@ def link(self, oldpath, newpath, dir_fd=None): OSError: if on Windows before Python 3.2. """ oldpath = self._path_with_dir_fd(oldpath, self.link, dir_fd) - self.filesystem.CreateHardLink(oldpath, newpath) + self.filesystem.link(oldpath, newpath) def fsync(self, file_des): """Perform fsync for a fake file (in other words, do nothing). @@ -3974,7 +4107,7 @@ def fsync(self, file_des): TypeError: file_des is not an integer. """ # Throw an error if file_des isn't valid - self.filesystem.GetOpenFile(file_des) + self.filesystem._get_open_file(file_des) def fdatasync(self, file_des): """Perform fdatasync for a fake file (in other words, do nothing). @@ -3988,7 +4121,7 @@ def fdatasync(self, file_des): TypeError: file_des is not an integer. """ # Throw an error if file_des isn't valid - self.filesystem.GetOpenFile(file_des) + self.filesystem._get_open_file(file_des) def __getattr__(self, name): """Forwards any unfaked calls to the standard os module.""" @@ -4017,7 +4150,7 @@ def __init__(self, filesystem): def open(self, file_path, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None): """Redirect the call to FakeFileOpen. - See FakeFileOpen.Call() for description. + See FakeFileOpen.call() for description. """ if opener is not None and sys.version_info < (3, 3): raise TypeError("open() got an unexpected keyword argument 'opener'") @@ -4114,7 +4247,7 @@ def _raise(self, message): raise IOError(message) raise io.UnsupportedOperation(message) - def GetObject(self): + def get_object(self): """Return the FakeFile object that is wrapped by the current instance.""" return self._file_object @@ -4126,16 +4259,16 @@ def close(self): """Close the file.""" # for raw io, all writes are flushed immediately if self.allow_update and not self.raw_io: - self._file_object.SetContents(self._io.getvalue(), self._encoding) + self._file_object.set_contents(self._io.getvalue(), self._encoding) if self._closefd: - self._filesystem.CloseOpenFile(self.filedes) + self._filesystem._close_open_file(self.filedes) if self.delete_on_close: - self._filesystem.RemoveObject(self.GetObject().GetPath()) + self._filesystem.remove_object(self.get_object().GetPath()) def flush(self): """Flush file contents to 'disk'.""" if self.allow_update: - self._file_object.SetContents(self._io.getvalue(), self._encoding) + self._file_object.set_contents(self._io.getvalue(), self._encoding) self._file_epoch = self._file_object.epoch def seek(self, offset, whence=0): @@ -4190,7 +4323,7 @@ def _sync_io(self): self._io.stream.allow_update = False self._file_epoch = self._file_object.epoch - def _ReadWrappers(self, name): + def _read_wrappers(self, name): """Wrap a StringIO attribute in a read wrapper. Returns a read_wrapper which tracks our own read pointer since the @@ -4226,7 +4359,7 @@ def read_wrapper(*args, **kwargs): return read_wrapper - def _OtherWrapper(self, name): + def _other_wrapper(self, name): """Wrap a StringIO attribute in an other_wrapper. Args: @@ -4259,12 +4392,12 @@ def other_wrapper(*args, **kwargs): return other_wrapper - def Size(self): + def size(self): """Return the content size in bytes of the wrapped file.""" return self._file_object.st_size def __getattr__(self, name): - if self._file_object.IsLargeFile(): + if self._file_object.is_large_file(): raise FakeLargeFileIoException(self._file_path) reading = name.startswith('read') or name == 'next' @@ -4295,9 +4428,9 @@ def write_error(*args, **kwargs): self._sync_io() if self._append: if reading: - return self._ReadWrappers(name) + return self._read_wrappers(name) else: - return self._OtherWrapper(name) + return self._other_wrapper(name) return getattr(self._io, name) def _check_open_file(self): @@ -4319,7 +4452,7 @@ def __init__(self, file_object, file_path, filesystem): self._filesystem = filesystem self.filedes = None - def GetObject(self): + def get_object(self): """Return the FakeFile object that is wrapped by the current instance.""" return self._file_object @@ -4329,7 +4462,10 @@ def fileno(self): def close(self): """Close the directory.""" - self._filesystem.CloseOpenFile(self.filedes) + self._filesystem._close_open_file(self.filedes) + +Deprecator.add(FakeFileWrapper, FakeFileWrapper.get_object, 'GetObject') +Deprecator.add(FakeFileWrapper, FakeFileWrapper.size, 'Size') class FakeFileOpen(object): @@ -4357,7 +4493,7 @@ def __init__(self, filesystem, delete_on_close=False, use_io=False, raw_io=False def __call__(self, *args, **kwargs): """Redirects calls to file() or open() to appropriate method.""" if self._use_io: - return self.Call(*args, **kwargs) + return self.call(*args, **kwargs) else: return self._call_ver2(*args, **kwargs) @@ -4365,9 +4501,9 @@ def _call_ver2(self, file_path, mode='r', buffering=-1, flags=None, open_modes=N """Limits args of open() or file() for Python 2.x versions.""" # Backwards compatibility, mode arg used to be named flags mode = flags or mode - return self.Call(file_path, mode, buffering, open_modes=open_modes) + return self.call(file_path, mode, buffering, open_modes=open_modes) - def Call(self, file_, mode='r', buffering=-1, encoding=None, + def call(self, file_, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None, open_modes=None): """Return a file-like object with the contents of the target file object. @@ -4411,19 +4547,19 @@ def Call(self, file_, mode='r', buffering=-1, encoding=None, # opening a file descriptor if isinstance(file_, int): filedes = file_ - wrapper = self.filesystem.GetOpenFile(filedes) + wrapper = self.filesystem._get_open_file(filedes) self._delete_on_close = wrapper.delete_on_close - file_object = self.filesystem.GetOpenFile(filedes).GetObject() + file_object = self.filesystem._get_open_file(filedes).get_object() file_path = file_object.name else: file_path = file_ - real_path = self.filesystem.ResolvePath(file_path, raw_io=self.raw_io) - if self.filesystem.Exists(file_path): - file_object = self.filesystem.GetObjectFromNormalizedPath(real_path) + real_path = self.filesystem.resolve_path(file_path, raw_io=self.raw_io) + if self.filesystem.exists(file_path): + file_object = self.filesystem.get_object_from_normpath(real_path) closefd = True error_class = OSError if self.raw_io else IOError - if open_modes.must_not_exist and (file_object or self.filesystem.IsLink(file_path)): + if open_modes.must_not_exist and (file_object or self.filesystem.islink(file_path)): raise error_class(errno.EEXIST, 'File exists', file_path) if file_object: if ((open_modes.can_read and not file_object.st_mode & PERM_READ) or @@ -4431,14 +4567,14 @@ def Call(self, file_, mode='r', buffering=-1, encoding=None, raise error_class(errno.EACCES, 'Permission denied', file_path) if open_modes.can_write: if open_modes.truncate: - file_object.SetContents('') + file_object.set_contents('') else: if open_modes.must_exist: raise error_class(errno.ENOENT, 'No such file or directory', file_path) - file_object = self.filesystem.CreateFile( + file_object = self.filesystem.create_file( real_path, create_missing_dirs=False, apply_umask=True, raw_io=self.raw_io) - if stat.S_ISDIR(file_object.st_mode): + if S_ISDIR(file_object.st_mode): if self.filesystem.is_windows_fs: raise OSError(errno.EPERM, 'Fake file object: is a directory', file_path) else: @@ -4466,7 +4602,7 @@ def Call(self, file_, mode='r', buffering=-1, encoding=None, # replace the file wrapper self.filesystem.open_files[filedes] = fakefile else: - fakefile.filedes = self.filesystem.AddOpenFile(fakefile) + fakefile.filedes = self.filesystem._add_open_file(fakefile) return fakefile diff --git a/pyfakefs/fake_filesystem_shutil.py b/pyfakefs/fake_filesystem_shutil.py index d85bf048..7cc04f16 100755 --- a/pyfakefs/fake_filesystem_shutil.py +++ b/pyfakefs/fake_filesystem_shutil.py @@ -52,7 +52,7 @@ def disk_usage(self, path): Args: path: defines the filesystem device which is queried """ - return self.filesystem.GetDiskUsage(path) + return self.filesystem.get_disk_usage(path) def __getattr__(self, name): """Forwards any non-faked calls to the standard shutil module.""" diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index 06d4ed93..5a470856 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -421,7 +421,7 @@ def setUp(self, doctester=None): # the temp directory is assumed to exist at least in `tempfile1, # so we create it here for convenience - self.fs.CreateDirectory(temp_dir) + self.fs.create_dir(temp_dir) def replaceGlobs(self, globs_): diff --git a/pyfakefs/fake_pathlib.py b/pyfakefs/fake_pathlib.py index 7b0d1cc3..ee478d84 100644 --- a/pyfakefs/fake_pathlib.py +++ b/pyfakefs/fake_pathlib.py @@ -77,43 +77,43 @@ def _wrapped(pathobj1, pathobj2, *args): class _FakeAccessor(pathlib._Accessor): # pylint: disable=protected-access """Accessor which forwards some of the functions to FakeFilesystem methods.""" - stat = _wrap_strfunc(FakeFilesystem.GetStat) + stat = _wrap_strfunc(FakeFilesystem.stat) - lstat = _wrap_strfunc(lambda fs, path: FakeFilesystem.GetStat(fs, path, follow_symlinks=False)) + lstat = _wrap_strfunc(lambda fs, path: FakeFilesystem.stat(fs, path, follow_symlinks=False)) - listdir = _wrap_strfunc(FakeFilesystem.ListDir) + listdir = _wrap_strfunc(FakeFilesystem.listdir) - chmod = _wrap_strfunc(FakeFilesystem.ChangeMode) + chmod = _wrap_strfunc(FakeFilesystem.chmod) if sys.version_info >= (3, 6): scandir = _wrap_strfunc(FakeFilesystem.ScanDir) if hasattr(os, "lchmod"): - lchmod = _wrap_strfunc(lambda fs, path, mode: FakeFilesystem.ChangeMode( + lchmod = _wrap_strfunc(lambda fs, path, mode: FakeFilesystem.chmod( fs, path, mode, follow_symlinks=False)) else: def lchmod(self, pathobj, mode): """Raises not implemented for Windows systems.""" raise NotImplementedError("lchmod() not available on this system") - mkdir = _wrap_strfunc(FakeFilesystem.MakeDirectory) + mkdir = _wrap_strfunc(FakeFilesystem.makedir) - unlink = _wrap_strfunc(FakeFilesystem.RemoveFile) + unlink = _wrap_strfunc(FakeFilesystem.remove) - rmdir = _wrap_strfunc(FakeFilesystem.RemoveDirectory) + rmdir = _wrap_strfunc(FakeFilesystem.rmdir) - rename = _wrap_binary_strfunc(FakeFilesystem.RenameObject) + rename = _wrap_binary_strfunc(FakeFilesystem.rename) replace = _wrap_binary_strfunc(lambda fs, old_path, new_path: - FakeFilesystem.RenameObject( + FakeFilesystem.rename( fs, old_path, new_path, force_replace=True)) symlink = _wrap_binary_strfunc_reverse( lambda fs, file_path, link_target, target_is_directory: - FakeFilesystem.CreateLink(fs, file_path, link_target, - create_missing_dirs=False)) + FakeFilesystem.symlink(fs, file_path, link_target, + create_missing_dirs=False)) - utime = _wrap_strfunc(FakeFilesystem.UpdateTime) + utime = _wrap_strfunc(FakeFilesystem.utime) _fake_accessor = _FakeAccessor() @@ -250,7 +250,7 @@ def _resolve(path, rest): raise RuntimeError("Symlink loop from %r" % newpath) # Resolve the symbolic link try: - target = self.filesystem.ReadLink(newpath) + target = self.filesystem.readlink(newpath) except OSError as e: if e.errno != errno.EINVAL: if strict: @@ -277,21 +277,21 @@ def _resolve_windows(self, path, strict): return os.getcwd() previous_s = None if strict: - if not self.filesystem.Exists(s): + if not self.filesystem.exists(s): raise FileNotFoundError(s) - return self.filesystem.ResolvePath(s) + return self.filesystem.resolve_path(s) else: while True: try: - s = self.filesystem.ResolvePath(s) + s = self.filesystem.resolve_path(s) except FileNotFoundError: previous_s = s - s = self.filesystem.SplitPath(s)[0] + s = self.filesystem.splitpath(s)[0] else: if previous_s is None: return s else: - return self.filesystem.JoinPaths(s, os.path.basename(previous_s)) + return self.filesystem.joinpaths(s, os.path.basename(previous_s)) def resolve(self, path, strict): """Make the path absolute, resolving any symlinks.""" @@ -476,7 +476,7 @@ def resolve(self, strict=None): if path is None: self.stat() path = str(self.absolute()) - path = self.filesystem.NormalizePath(path) + path = self.filesystem.absnormpath(path) return FakePath(path) def open(self, mode='r', buffering=-1, encoding=None, @@ -566,7 +566,7 @@ def samefile(self, other_path): try: other_st = other_path.stat() except AttributeError: - other_st = self.filesystem.GetStat(other_path) + other_st = self.filesystem.stat(other_path) return st.st_ino == other_st.st_ino and st.st_dev == other_st.st_dev def expanduser(self): @@ -591,7 +591,7 @@ def touch(self, mode=0o666, exist_ok=True): self._raise_closed() if self.exists(): if exist_ok: - self.filesystem.UpdateTime(self._path(), None) + self.filesystem.utime(self._path(), None) else: raise FileExistsError else: diff --git a/pyfakefs/pytest_plugin.py b/pyfakefs/pytest_plugin.py index 7c0b2cc1..5b62f1d2 100644 --- a/pyfakefs/pytest_plugin.py +++ b/pyfakefs/pytest_plugin.py @@ -5,7 +5,7 @@ :Usage: def my_fakefs_test(fs): - fs.CreateFile('/var/data/xx1.txt') + fs.create_file('/var/data/xx1.txt') assert os.path.exists('/var/data/xx1.txt') """ import py diff --git a/pytest_plugin_test.py b/pytest_plugin_test.py index 649cbc6b..d722ce7d 100644 --- a/pytest_plugin_test.py +++ b/pytest_plugin_test.py @@ -3,5 +3,5 @@ def test_fs_fixture(fs): - fs.CreateFile('/var/data/xx1.txt') + fs.create_file('/var/data/xx1.txt') assert os.path.exists('/var/data/xx1.txt')