Skip to content

Commit

Permalink
Changed whitespace to conform to pep-8
Browse files Browse the repository at this point in the history
- auto-format done by PyCharm
  • Loading branch information
mrbean-bremen committed Oct 3, 2016
1 parent 0e6704e commit 851ef85
Show file tree
Hide file tree
Showing 15 changed files with 7,684 additions and 7,667 deletions.
36 changes: 19 additions & 17 deletions all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@


class AllTests(unittest.TestSuite):
"""A test suite that runs all tests for pyfakefs at once."""

def suite(self): # pylint: disable-msg=C6409
loader = unittest.defaultTestLoader
self.addTests([
loader.loadTestsFromModule(fake_filesystem_test),
loader.loadTestsFromModule(fake_filesystem_glob_test),
loader.loadTestsFromModule(fake_filesystem_shutil_test),
loader.loadTestsFromModule(fake_tempfile_test),
loader.loadTestsFromModule(fake_filesystem_vs_real_test),
loader.loadTestsFromModule(fake_filesystem_unittest_test),
loader.loadTestsFromModule(example_test),
])
return self
"""A test suite that runs all tests for pyfakefs at once."""

def suite(self): # pylint: disable-msg=C6409
loader = unittest.defaultTestLoader
self.addTests([
loader.loadTestsFromModule(fake_filesystem_test),
loader.loadTestsFromModule(fake_filesystem_glob_test),
loader.loadTestsFromModule(fake_filesystem_shutil_test),
loader.loadTestsFromModule(fake_tempfile_test),
loader.loadTestsFromModule(fake_filesystem_vs_real_test),
loader.loadTestsFromModule(fake_filesystem_unittest_test),
loader.loadTestsFromModule(example_test),
])
return self


if __name__ == '__main__':
import sys
result = unittest.TextTestRunner(verbosity=2).run(AllTests().suite())
sys.exit(int(not result.wasSuccessful()))
import sys

result = unittest.TextTestRunner(verbosity=2).run(AllTests().suite())
sys.exit(int(not result.wasSuccessful()))
23 changes: 14 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
import glob
import shutil


def create_file(path):
'''Create the specified file and add some content to it. Use the `open()`
"""Create the specified file and add some content to it. Use the `open()`
built in function.
For example, the following file operations occur in the fake file system.
Expand All @@ -60,13 +61,14 @@ def create_file(path):
>>> with open('/test/file.txt') as f:
... f.readlines()
["This is test file '/test/file.txt'.\\n", 'It was created using the open() function.\\n']
'''
"""
with open(path, 'w') as f:
f.write("This is test file '{0}'.\n".format(path))
f.write("It was created using the open() function.\n")


def delete_file(path):
'''Delete the specified file.
"""Delete the specified file.
For example:
Expand All @@ -79,11 +81,12 @@ def delete_file(path):
>>> delete_file('/test/file.txt')
>>> os.path.exists('/test/file.txt')
False
'''
"""
os.remove(path)


def path_exists(path):
'''Return True if the specified file exists.
"""Return True if the specified file exists.
For example:
Expand All @@ -98,11 +101,12 @@ def path_exists(path):
>>> create_file('/test/file.txt')
>>> path_exists('/test/file.txt')
True
'''
"""
return os.path.exists(path)


def get_glob(glob_path):
r'''Return the list of paths matching the specified glob expression.
r"""Return the list of paths matching the specified glob expression.
For example:
Expand All @@ -119,9 +123,10 @@ def get_glob(glob_path):
... # UNIX style path
... file_names == ['/test/file1.txt', '/test/file2.txt']
True
'''
"""
return glob.glob(glob_path)


def rm_tree(path):
'''Delete the specified file hierarchy.'''
"""Delete the specified file hierarchy."""
shutil.rmtree(path)
32 changes: 17 additions & 15 deletions example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import os
import sys

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
Expand All @@ -33,15 +34,15 @@


def load_tests(loader, tests, ignore):
'''Load the pyfakefs/example.py doctest tests into unittest.'''
"""Load the pyfakefs/example.py doctest tests into unittest."""
return fake_filesystem_unittest.load_doctests(loader, tests, ignore, example)


class TestExample(fake_filesystem_unittest.TestCase): # pylint: disable=R0904
'''Test the example module.'''
class TestExample(fake_filesystem_unittest.TestCase): # pylint: disable=R0904
"""Test the example module."""

def setUp(self):
'''Invoke the :py:class:`pyfakefs.fake_filesystem_unittest.TestCase`
"""Invoke the :py:class:`pyfakefs.fake_filesystem_unittest.TestCase`
`self.setUp()` method. This defines:
* Attribute `self.fs`, an instance of \
Expand All @@ -50,15 +51,15 @@ def setUp(self):
* Attribute `self.stubs`, an instance of \
:py:class:`mox.stubout.StubOutForTesting`. Use this if you need to
define additional stubs.
'''
"""
self.setUpPyfakefs()

def tearDown(self):
# No longer need self.tearDownPyfakefs()
pass

def test_create_file(self):
'''Test example.create_file()'''
"""Test example.create_file()"""
# The os module has been replaced with the fake os module so all of the
# following occurs in the fake filesystem.
self.assertFalse(os.path.isdir('/test'))
Expand All @@ -70,14 +71,14 @@ def test_create_file(self):
self.assertTrue(os.path.exists('/test/file.txt'))

def test_delete_file(self):
'''Test example.delete_file()
"""Test example.delete_file()
`self.fs.CreateFile()` is convenient because it automatically creates
directories in the fake file system and allows you to specify the file
contents.
You could also use `open()` or `file()`.
'''
"""
self.fs.CreateFile('/test/full.txt',
contents='First line\n'
'Second Line\n')
Expand All @@ -86,25 +87,25 @@ def test_delete_file(self):
self.assertFalse(os.path.exists('/test/full.txt'))

def test_file_exists(self):
'''Test example.path_exists()
"""Test example.path_exists()
`self.fs.CreateFile()` is convenient because it automatically creates
directories in the fake file system and allows you to specify the file
contents.
You could also use `open()` or `file()` if you wanted.
'''
"""
self.assertFalse(example.path_exists('/test/empty.txt'))
self.fs.CreateFile('/test/empty.txt')
self.assertTrue(example.path_exists('/test/empty.txt'))

def test_get_globs(self):
'''Test example.get_glob()
"""Test example.get_glob()
`self.fs.CreateDirectory()` creates directories. However, you might
prefer the familiar `os.makedirs()`, which also works fine on the fake
file system.
'''
"""
self.assertFalse(os.path.isdir('/test'))
self.fs.CreateDirectory('/test/dir1/dir2a')
self.assertTrue(os.path.isdir('/test/dir1/dir2a'))
Expand All @@ -113,7 +114,7 @@ def test_get_globs(self):
self.assertTrue(os.path.isdir('/test/dir1/dir2b'))

self.assertEqual(example.get_glob('/test/dir1/nonexistent*'),
[])
[])
is_windows = sys.platform.startswith('win')
matching_paths = example.get_glob('/test/dir1/dir*')
if is_windows:
Expand All @@ -122,12 +123,12 @@ def test_get_globs(self):
self.assertEqual(matching_paths, ['/test/dir1/dir2a', '/test/dir1/dir2b'])

def test_rm_tree(self):
'''Test example.rm_tree()
"""Test example.rm_tree()
`self.fs.CreateDirectory()` creates directories. However, you might
prefer the familiar `os.makedirs()`, which also works fine on the fake
file system.
'''
"""
self.fs.CreateDirectory('/test/dir1/dir2a')
# os.mkdirs() works, too.
os.makedirs('/test/dir1/dir2b')
Expand All @@ -137,5 +138,6 @@ def test_rm_tree(self):
example.rm_tree('/test/dir1')
self.assertFalse(os.path.exists('/test/dir1'))


if __name__ == "__main__":
unittest.main()
76 changes: 38 additions & 38 deletions fake_filesystem_glob_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import doctest
import sys

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
Expand All @@ -28,55 +29,54 @@


class FakeGlobUnitTest(unittest.TestCase):
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]')

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]')

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

def testGlobStar(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
self.glob.glob('/xyzzy/*'))
def testGlobStar(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
self.glob.glob('/xyzzy/*'))

def testGlobExact(self):
self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy'))
self.assertEqual(['/xyzzy/subfile'], self.glob.glob('/xyzzy/subfile'))
def testGlobExact(self):
self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy'))
self.assertEqual(['/xyzzy/subfile'], self.glob.glob('/xyzzy/subfile'))

def testGlobQuestion(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
self.glob.glob('/x?zz?/*'))
def testGlobQuestion(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
self.glob.glob('/x?zz?/*'))

def testGlobNoMagic(self):
self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy'))
self.assertEqual(['/xyzzy/subdir'], self.glob.glob('/xyzzy/subdir'))
def testGlobNoMagic(self):
self.assertEqual(['/xyzzy'], self.glob.glob('/xyzzy'))
self.assertEqual(['/xyzzy/subdir'], self.glob.glob('/xyzzy/subdir'))

def testNonExistentPath(self):
self.assertEqual([], self.glob.glob('nonexistent'))
def testNonExistentPath(self):
self.assertEqual([], self.glob.glob('nonexistent'))

def testDocTest(self):
self.assertFalse(doctest.testmod(fake_filesystem_glob)[0])
def testDocTest(self):
self.assertFalse(doctest.testmod(fake_filesystem_glob)[0])

def testMagicDir(self):
self.assertEqual(['/[Temp]'], self.glob.glob('/*emp*'))
def testMagicDir(self):
self.assertEqual(['/[Temp]'], self.glob.glob('/*emp*'))

def testRootGlob(self):
self.assertEqual(['[Temp]', 'xyzzy'], self.glob.glob('*'))
def testRootGlob(self):
self.assertEqual(['[Temp]', 'xyzzy'], self.glob.glob('*'))

def testGlob1(self):
self.assertEqual(['[Temp]'], self.glob.glob1('/', '*Tem*'))
def testGlob1(self):
self.assertEqual(['[Temp]'], self.glob.glob1('/', '*Tem*'))

def testHasMagic(self):
self.assertTrue(self.glob.has_magic('['))
self.assertFalse(self.glob.has_magic('a'))
def testHasMagic(self):
self.assertTrue(self.glob.has_magic('['))
self.assertFalse(self.glob.has_magic('a'))


if __name__ == '__main__':
unittest.main()
unittest.main()
Loading

0 comments on commit 851ef85

Please sign in to comment.