def setUp(self): """ Initialize a fake filesystem and dirtools. """ # First we create a fake filesystem in order to test dirtools fk = fake_filesystem.FakeFilesystem() fk.CreateDirectory('/test_dirtools') fk.CreateFile('/test_dirtools/file1', contents='contents1') fk.CreateFile('/test_dirtools/file2', contents='contents2') fk.CreateFile('/test_dirtools/file3.py', contents='print "ok"') fk.CreateFile('/test_dirtools/file3.pyc', contents='') fk.CreateFile('/test_dirtools/.exclude', contents='excluded_dir/\n*.pyc') fk.CreateDirectory('/test_dirtools/excluded_dir') fk.CreateFile('/test_dirtools/excluded_dir/excluded_file', contents='excluded') fk.CreateDirectory('/test_dirtools/dir1') fk.CreateDirectory('/test_dirtools/dir1/subdir1') fk.CreateFile('/test_dirtools/dir1/subdir1/file_subdir1', contents='inside subdir1') fk.CreateFile('/test_dirtools/dir1/subdir1/.project') fk.CreateDirectory('/test_dirtools/dir2') fk.CreateFile('/test_dirtools/dir2/file_dir2', contents='inside dir2') # Sort of "monkey patch" to make dirtools use the fake filesystem dirtools.os = fake_filesystem.FakeOsModule(fk) dirtools.open = fake_filesystem.FakeFileOpen(fk) # Dirtools initialization self.dir = dirtools.Dir('/test_dirtools') self.os = dirtools.os self.open = dirtools.open self.shutil = fake_filesystem_shutil.FakeShutilModule(fk) self.fk = fk
def _refresh(self): '''Renew the fake file system and set the _isStale flag to `False`.''' mock.patch.stopall() self.fs = fake_filesystem.FakeFilesystem() self.fake_os = fake_filesystem.FakeOsModule(self.fs) self.fake_glob = fake_filesystem_glob.FakeGlobModule(self.fs) self.fake_path = self.fake_os.path self.fake_shutil = fake_filesystem_shutil.FakeShutilModule(self.fs) self.fake_tempfile_ = fake_tempfile.FakeTempfileModule(self.fs) self.fake_open = fake_filesystem.FakeFileOpen(self.fs) self._isStale = False
def replaceGlobs(self, globs_): globs = globs_.copy() if self._isStale: self._refresh() if 'os' in globs: globs['os'] = fake_filesystem.FakeOsModule(self.fs) if 'glob' in globs: globs['glob'] = fake_filesystem_glob.FakeGlobModule(self.fs) if 'path' in globs: globs['path'] = fake_filesystem.FakePathModule(self.fs) if 'shutil' in globs: globs['shutil'] = fake_filesystem_shutil.FakeShutilModule(self.fs) if 'tempfile' in globs: globs['tempfile'] = fake_tempfile.FakeTempfileModule(self.fs) return globs
def _refresh(self): '''Renew the fake file system and set the _isStale flag to `False`.''' if self._stubs is not None: self._stubs.SmartUnsetAll() self._stubs = mox3.stubout.StubOutForTesting() self.fs = fake_filesystem.FakeFilesystem() self.fake_os = fake_filesystem.FakeOsModule(self.fs) self.fake_glob = fake_filesystem_glob.FakeGlobModule(self.fs) self.fake_path = self.fake_os.path self.fake_shutil = fake_filesystem_shutil.FakeShutilModule(self.fs) self.fake_tempfile_ = fake_tempfile.FakeTempfileModule(self.fs) self.fake_open = fake_filesystem.FakeFileOpen(self.fs) self._isStale = False
def setUp(self): self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/') self.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem)
def setUp(self): self.filesystem = fake_filesystem.FakeFilesystem() self.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem)
def __init__(self, filesystem=None): self.filesystem = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.filesystem) self._open = fake_filesystem.FakeFileOpen(self.filesystem) self.shutil = fake_filesystem_shutil.FakeShutilModule(self.filesystem)