Skip to content

Commit

Permalink
Removed fake_filesystem_glob.py, relying on patched os module
Browse files Browse the repository at this point in the history
- changed test to test the real glob with the fake filesystem
- see pytest-dev#189
  • Loading branch information
mrbean-bremen committed Jul 1, 2017
1 parent 1adfccb commit b9a9d72
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 321 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ The release versions are PyPi releases.
* Added nanosecond time members in `os.stat_result` (Python >= 3.3) ([#196](../../issues/196)).

#### Infrastructure
* Remove most of `fake_filesystem_shutil` implementation, relying on the patched `os` module instead ([#194](../../issues/194)).
* Removed most of `fake_filesystem_shutil` implementation, relying on the patched `os` module instead ([#194](../../issues/194)).
* Removed `fake_tempfile` and `fake_filesystem_glob`, relying on the patched `os` module instead ([#189](../../issues/191), [#189](../../issues/191)).

#### Fixes
* Incorrect `os.walk` behavior if top dir is a symlink ([#240](../../issues/240).
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ try:
except ImportError:
from mock import patch # Python 2

import pyfakefs.fake_filesystem_glob as fake_glob
import pyfakefs.fake_filesystem_shutil as fake_shutil

# Note that this fake module is based on the fake fs you just created
glob = fake_glob.FakeGlobModule(fs)
with patch('mymodule.glob', glob):
print(glob.glob('/var/data/xx*'))
shutil = fake_shutil.FakeShutilModule(fs)
with patch('mymodule.shutil', shutil):
print(shutil.disk_usage('/var/data/'))
```

## Installation
Expand Down
62 changes: 31 additions & 31 deletions fake_filesystem_glob_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,68 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test for fake_filesystem_glob."""
"""Test for glob using fake_filesystem."""

import doctest
import glob
import os
import sys

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from pyfakefs import fake_filesystem
from pyfakefs import fake_filesystem_glob
from pyfakefs import fake_filesystem_unittest


class FakeGlobUnitTest(unittest.TestCase):
class FakeGlobUnitTest(fake_filesystem_unittest.TestCase):
def setUp(self):
self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
self.glob = fake_filesystem_glob.FakeGlobModule(self.filesystem)
self.setUpPyfakefs()
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.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]')

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

def testGlobStar(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
sorted(self.glob.glob('/xyzzy/*')))
basedir = os.sep + 'xyzzy'
self.assertEqual([os.path.join(basedir, 'subdir'),
os.path.join(basedir, 'subdir2'),
os.path.join(basedir, 'subfile')],
sorted(glob.glob('/xyzzy/*')))

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

def testGlobQuestion(self):
self.assertEqual(['/xyzzy/subdir', '/xyzzy/subdir2', '/xyzzy/subfile'],
sorted(self.glob.glob('/x?zz?/*')))
basedir = os.sep + 'xyzzy'
self.assertEqual([os.path.join(basedir, 'subdir'),
os.path.join(basedir, 'subdir2'),
os.path.join(basedir, 'subfile')],
sorted(glob.glob('/x?zz?/*')))

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

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

def testDocTest(self):
self.assertFalse(doctest.testmod(fake_filesystem_glob)[0])
self.assertEqual([], glob.glob('nonexistent'))

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

def testRootGlob(self):
self.assertEqual(['[Temp]', 'xyzzy'], sorted(self.glob.glob('*')))
self.assertEqual([os.sep + '[Temp]'], glob.glob('/*emp*'))

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

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


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5368,7 +5368,7 @@ def testAddExistingRealPathsReadWrite(self):
self.checkFakeFileStat(fake_file, real_file_path)
self.checkWritableFile(fake_file, real_file_path)

real_file_path = os.path.join(real_dir_path, 'fake_filesystem_glob.py')
real_file_path = os.path.join(real_dir_path, 'fake_pathlib.py')
fake_file = self.filesystem.ResolveObject(real_file_path)
self.checkFakeFileStat(fake_file, real_file_path)
self.checkWritableFile(fake_file, real_file_path)
Expand Down
Loading

0 comments on commit b9a9d72

Please sign in to comment.