def test_fakepathlib(self): with pathlib.Path('/fake_file.txt') as p: with p.open('w') as f: f.write('text') is_windows = sys.platform.startswith('win') if is_windows: self.assertTrue(self.fs.exists(r'\fake_file.txt')) else: self.assertTrue(self.fs.exists('/fake_file.txt'))
def test_pathlib_path_patch(self): file_path = 'test.txt' path = pathlib.Path(file_path) with path.open('w') as f: f.write('test') self.assertTrue(self.fs.exists(file_path)) file_object = self.fs.get_object(file_path) self.assertEqual('test', file_object.contents)
def test_cwd(self, fs): """Make sure fake file system is used for os in pathlib""" self.assertEqual(os.path.sep, str(pathlib.Path.cwd())) dot_abs = pathlib.Path(".").absolute() self.assertEqual(os.path.sep, str(dot_abs)) self.assertTrue(dot_abs.exists())