Skip to content

Commit

Permalink
Make pyfakefs API PEP-8 conform
Browse files Browse the repository at this point in the history
- changed methods names
- added old method names as depracated version
- added possibility to switch on deprecation warning
- see pytest-dev#186
  • Loading branch information
mrbean-bremen committed May 27, 2017
1 parent a3cf7be commit d8369c4
Show file tree
Hide file tree
Showing 18 changed files with 1,850 additions and 1,671 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```

Expand All @@ -56,8 +56,8 @@ import pyfakefs.fake_filesystem as fake_fs
fs = fake_fs.FakeFilesystem()

# Do some setup on the faked file system
fs.CreateFile('/var/data/xx1.txt')
fs.CreateFile('/var/data/xx2.txt')
fs.create_file('/var/data/xx1.txt')
fs.create_file('/var/data/xx2.txt')

# Replace some built-in file system related modules you use with faked ones

Expand Down
6 changes: 3 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 unittest.mock
Expand All @@ -40,8 +40,8 @@ If you are using other means of testing like `nose <http://nose2.readthedocs.io>
fs = fake_fs.FakeFilesystem()
# Do some setup on the faked file system
fs.CreateFile('/var/data/xx1.txt')
fs.CreateFile('/var/data/xx2.txt')
fs.create_file('/var/data/xx1.txt')
fs.create_file('/var/data/xx2.txt')
# Replace some built-in file system related modules you use with faked ones
Expand Down
22 changes: 11 additions & 11 deletions example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down Expand Up @@ -83,8 +83,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')
Expand All @@ -93,13 +93,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')
Expand All @@ -116,7 +116,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'))
Expand All @@ -132,10 +132,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))
Expand Down
10 changes: 5 additions & 5 deletions fake_filesystem_glob_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def setUp(self):
self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
self.glob = fake_filesystem_glob.FakeGlobModule(self.filesystem)
directory = './xyzzy'
self.filesystem.CreateDirectory(directory)
self.filesystem.CreateDirectory('%s/subdir' % directory)
self.filesystem.CreateDirectory('%s/subdir2' % directory)
self.filesystem.CreateFile('%s/subfile' % directory)
self.filesystem.CreateFile('[Temp]')
self.filesystem.create_dir(directory)
self.filesystem.create_dir('%s/subdir' % directory)
self.filesystem.create_dir('%s/subdir2' % directory)
self.filesystem.create_file('%s/subfile' % directory)
self.filesystem.create_file('[Temp]')

def testGlobEmpty(self):
self.assertEqual(self.glob.glob(''), [])
Expand Down
Loading

0 comments on commit d8369c4

Please sign in to comment.