|
27 | 27 | import sys
|
28 | 28 | import unittest
|
29 | 29 |
|
30 |
| -from pyfakefs import fake_pathlib |
| 30 | +from pyfakefs import fake_pathlib, fake_filesystem |
31 | 31 | from pyfakefs.tests.test_utils import RealFsTestCase
|
32 | 32 |
|
33 | 33 | is_windows = sys.platform == 'win32'
|
@@ -910,5 +910,61 @@ def use_real_fs(self):
|
910 | 910 | return True
|
911 | 911 |
|
912 | 912 |
|
| 913 | +@unittest.skipIf(sys.version_info < (3, 6), |
| 914 | + 'Path-like objects new in Python 3.6') |
| 915 | +class FakeFilesystemPathLikeObjectTest(unittest.TestCase): |
| 916 | + |
| 917 | + def setUp(self): |
| 918 | + self.filesystem = fake_filesystem.FakeFilesystem(path_separator='/') |
| 919 | + self.pathlib = fake_pathlib.FakePathlibModule(self.filesystem) |
| 920 | + self.os = fake_filesystem.FakeOsModule(self.filesystem) |
| 921 | + |
| 922 | + def test_create_dir_with_pathlib_path(self): |
| 923 | + dir_path_string = 'foo/bar/baz' |
| 924 | + dir_path = self.pathlib.Path(dir_path_string) |
| 925 | + self.filesystem.create_dir(dir_path) |
| 926 | + self.assertTrue(self.os.path.exists(dir_path_string)) |
| 927 | + self.assertEqual(stat.S_IFDIR, |
| 928 | + self.os.stat(dir_path_string).st_mode & stat.S_IFDIR) |
| 929 | + |
| 930 | + def test_create_file_with_pathlib_path(self): |
| 931 | + file_path_string = 'foo/bar/baz' |
| 932 | + file_path = self.pathlib.Path(file_path_string) |
| 933 | + self.filesystem.create_file(file_path) |
| 934 | + self.assertTrue(self.os.path.exists(file_path_string)) |
| 935 | + self.assertEqual(stat.S_IFREG, |
| 936 | + self.os.stat(file_path_string).st_mode & stat.S_IFREG) |
| 937 | + |
| 938 | + def test_create_symlink_with_pathlib_path(self): |
| 939 | + file_path = self.pathlib.Path('foo/bar/baz') |
| 940 | + link_path_string = 'foo/link' |
| 941 | + link_path = self.pathlib.Path(link_path_string) |
| 942 | + self.filesystem.create_symlink(link_path, file_path) |
| 943 | + self.assertTrue(self.os.path.lexists(link_path_string)) |
| 944 | + self.assertEqual(stat.S_IFLNK, |
| 945 | + self.os.lstat(link_path_string).st_mode & |
| 946 | + stat.S_IFLNK) |
| 947 | + |
| 948 | + def test_add_existing_real_file_with_pathlib_path(self): |
| 949 | + real_file_path_string = os.path.abspath(__file__) |
| 950 | + real_file_path = self.pathlib.Path(real_file_path_string) |
| 951 | + self.filesystem.add_real_file(real_file_path) |
| 952 | + fake_filepath_string = real_file_path_string.replace( |
| 953 | + os.sep, self.os.sep) |
| 954 | + self.assertTrue(self.os.path.exists(fake_filepath_string)) |
| 955 | + self.assertEqual(stat.S_IFREG, self.os.stat( |
| 956 | + fake_filepath_string).st_mode & stat.S_IFREG) |
| 957 | + |
| 958 | + def test_add_existing_real_directory_with_pathlib_path(self): |
| 959 | + real_dirpath_string = os.path.dirname(os.path.abspath(__file__)) |
| 960 | + real_dir_path = self.pathlib.Path(real_dirpath_string) |
| 961 | + self.filesystem.add_real_directory(real_dir_path) |
| 962 | + fake_dirpath_string = real_dirpath_string.replace( |
| 963 | + os.sep, self.os.sep) |
| 964 | + self.assertTrue(self.os.path.exists(fake_dirpath_string)) |
| 965 | + self.assertEqual(stat.S_IFDIR, self.os.stat( |
| 966 | + fake_dirpath_string).st_mode & stat.S_IFDIR) |
| 967 | + |
| 968 | + |
913 | 969 | if __name__ == '__main__':
|
914 | 970 | unittest.main()
|
0 commit comments