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 Aug 14, 2017
1 parent 0a5bb74 commit b710379
Show file tree
Hide file tree
Showing 18 changed files with 2,035 additions and 1,824 deletions.
4 changes: 2 additions & 2 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 @@ -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:
Expand Down
4 changes: 2 additions & 2 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 fake_filesystem_unittest.Patcher
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions dynamic_patch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)


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 @@ -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')
Expand All @@ -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')
Expand All @@ -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'))
Expand All @@ -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))
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 @@ 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(''), [])
Expand Down
Loading

0 comments on commit b710379

Please sign in to comment.