Lines Matching full:path

53         self.path = None
59 self.path = self.pathlib.Path
65 path = self.path('/test')
67 self.assertTrue(isinstance(path, self.pathlib.WindowsPath))
68 self.assertTrue(isinstance(path, self.pathlib.PureWindowsPath))
72 self.assertTrue(isinstance(path, self.pathlib.PosixPath))
73 self.assertTrue(isinstance(path, self.pathlib.PurePosixPath))
79 """Basic initialization tests - taken from pathlib.Path documentation
81 self.assertEqual(self.path('/', 'foo', 'bar', 'baz'),
82 self.path('/foo/bar/baz'))
83 self.assertEqual(self.path(), self.path('.'))
84 self.assertEqual(self.path(self.path('foo'), self.path('bar')),
85 self.path('foo/bar'))
86 self.assertEqual(self.path('/etc') / 'init.d' / 'reboot',
87 self.path('/etc/init.d/reboot'))
90 """Tests for collapsing path during initialization.
93 self.assertEqual(self.path('foo//bar'), self.path('foo/bar'))
94 self.assertEqual(self.path('foo/./bar'), self.path('foo/bar'))
95 self.assertNotEqual(self.path('foo/../bar'), self.path('foo/bar'))
96 self.assertEqual(self.path('/etc', '/usr', 'lib64'),
97 self.path('/usr/lib64'))
100 sep = self.os.path.sep
101 path = self.path(sep + self.os.path.join('foo', 'bar', 'setup.py'))
102 self.assertEqual(path.parts, (sep, 'foo', 'bar', 'setup.py'))
103 self.assertEqual(path.drive, '')
104 self.assertEqual(path.root, sep)
105 self.assertEqual(path.anchor, sep)
106 self.assertEqual(path.name, 'setup.py')
107 self.assertEqual(path.stem, 'setup')
108 self.assertEqual(path.suffix, '.py')
109 self.assertEqual(path.parent,
110 self.path(sep + self.os.path.join('foo', 'bar')))
111 self.assertEqual(path.parents[0],
112 self.path(sep + self.os.path.join('foo', 'bar')))
113 self.assertEqual(path.parents[1], self.path(sep + 'foo'))
114 self.assertEqual(path.parents[2], self.path(sep))
118 self.assertTrue(self.path('/a/b').is_absolute())
119 self.assertFalse(self.path('a/b').is_absolute())
120 self.assertFalse(self.path('d:/b').is_absolute())
124 self.assertFalse(self.path('/a/b').is_absolute())
125 self.assertFalse(self.path('a/b').is_absolute())
126 self.assertTrue(self.path('d:/b').is_absolute())
137 """Basic initialization tests - taken from pathlib.Path
139 self.assertEqual(self.path('c:/', 'foo', 'bar', 'baz'),
140 self.path('c:/foo/bar/baz'))
141 self.assertEqual(self.path(), self.path('.'))
142 self.assertEqual(self.path(self.path('foo'), self.path('bar')),
143 self.path('foo/bar'))
144 self.assertEqual(self.path('c:/Users') / 'john' / 'data',
145 self.path('c:/Users/john/data'))
148 """Tests for collapsing path during initialization.
151 self.assertEqual(self.path('c:/Windows', 'd:bar'),
152 self.path('d:bar'))
153 self.assertEqual(self.path('c:/Windows', '/Program Files'),
154 self.path('c:/Program Files'))
157 path = self.path(
158 self.os.path.join('d:', 'python scripts', 'setup.py'))
159 self.assertEqual(path.parts, ('d:', 'python scripts', 'setup.py'))
160 self.assertEqual(path.drive, 'd:')
161 self.assertEqual(path.root, '')
162 self.assertEqual(path.anchor, 'd:')
163 self.assertEqual(path.name, 'setup.py')
164 self.assertEqual(path.stem, 'setup')
165 self.assertEqual(path.suffix, '.py')
166 self.assertEqual(path.parent,
167 self.path(
168 self.os.path.join('d:', 'python scripts')))
169 self.assertEqual(path.parents[0],
170 self.path(
171 self.os.path.join('d:', 'python scripts')))
172 self.assertEqual(path.parents[1], self.path('d:'))
176 self.assertTrue(self.path('c:/a/b').is_absolute())
177 self.assertFalse(self.path('/a/b').is_absolute())
178 self.assertFalse(self.path('c:').is_absolute())
179 self.assertTrue(self.path('//some/share').is_absolute())
193 self.assertFalse(self.path('/dev').is_reserved())
194 self.assertFalse(self.path('/').is_reserved())
195 self.assertFalse(self.path('COM1').is_reserved())
196 self.assertFalse(self.path('nul.txt').is_reserved())
201 self.assertFalse(self.path('/dev').is_reserved())
202 self.assertFalse(self.path('/').is_reserved())
203 self.assertTrue(self.path('COM1').is_reserved())
204 self.assertTrue(self.path('nul.txt').is_reserved())
207 self.assertEqual(self.path('/etc').joinpath('passwd'),
208 self.path('/etc/passwd'))
209 self.assertEqual(self.path('/etc').joinpath(self.path('passwd')),
210 self.path('/etc/passwd'))
211 self.assertEqual(self.path('/foo').joinpath('bar', 'baz'),
212 self.path('/foo/bar/baz'))
216 self.assertEqual(self.path('c:').joinpath('/Program Files'),
217 self.path('c:/Program Files'))
220 self.assertTrue(self.path('a/b.py').match('*.py'))
221 self.assertTrue(self.path('/a/b/c.py').match('b/*.py'))
222 self.assertFalse(self.path('/a/b/c.py').match('a/*.py'))
223 self.assertTrue(self.path('/a.py').match('/*.py'))
224 self.assertFalse(self.path('a/b.py').match('/*.py'))
227 self.assertEqual(self.path('/etc/passwd').relative_to('/'),
228 self.path('etc/passwd'))
229 self.assertEqual(self.path('/etc/passwd').relative_to('/'),
230 self.path('etc/passwd'))
231 self.assertRaises(ValueError, self.path('passwd').relative_to,
237 self.path('c:/Downloads/pathlib.tar.gz').with_name('setup.py'),
238 self.path('c:/Downloads/setup.py'))
239 self.assertRaises(ValueError, self.path('c:/').with_name,
244 self.path('c:/Downloads/pathlib.tar.gz').with_suffix('.bz2'),
245 self.path('c:/Downloads/pathlib.tar.bz2'))
246 self.assertEqual(self.path('README').with_suffix('.txt'),
247 self.path('README.txt'))
276 self.assertTrue(self.path(self.file_path).exists())
277 self.assertTrue(self.path(
279 self.assertFalse(self.path(
281 self.assertTrue(self.path(
283 self.assertTrue(self.path(
285 self.assertFalse(self.path(
287 self.assertFalse(self.path(
292 self.assertFalse(self.path(
294 self.assertTrue(self.path(
296 self.assertTrue(self.path(
298 self.assertFalse(self.path(
300 self.assertFalse(self.path(
302 self.assertFalse(self.path(
307 self.assertTrue(self.path(
309 self.assertFalse(self.path(
311 self.assertFalse(self.path(
313 self.assertTrue(self.path(
315 self.assertFalse(self.path(
317 self.assertFalse(self.path(
322 self.assertFalse(self.path(
324 self.assertFalse(self.path(
326 self.assertTrue(self.path(
328 self.assertTrue(self.path(
330 self.assertTrue(self.path(
332 self.assertTrue(self.path(
339 stat_result = self.path(self.file_link_path).stat()
352 stat_result = self.path(self.file_link_path).lstat()
385 self.path(self.file_link_path).lchmod, 0o444)
387 self.path(self.file_link_path).lchmod(0o444)
396 # use real path to handle symlink /var to /private/var in MacOs
397 self.assertEqual(self.path().resolve(),
398 self.path(
399 self.os.path.realpath(
402 self.path(
403 self.os.path.join('docs', '..', 'setup.py')).resolve(),
404 self.path(
405 self.os.path.realpath(
410 path = self.path('/foo/bar')
411 self.assert_raises_os_error(errno.ENOENT, path.resolve)
416 file_path = self.os.path.join(dir_path, 'some_file')
421 errno.EACCES, self.path(file_path).stat)
423 self.assertEqual(0, self.path(file_path).stat().st_size)
428 file_path = self.os.path.join(dir_path, 'some_file')
431 iter = self.path(dir_path).iterdir()
435 path = str(list(iter)[0])
436 self.assertTrue(path.endswith('some_file'))
443 path = self.path(self.make_path('a_file', 'this can not exist'))
444 self.assert_raises_os_error(errno.ENOENT, path.resolve)
451 path = self.path(
453 self.assert_raises_os_error(errno.ENOTDIR, path.resolve)
457 path = self.path(
458 self.make_path('/path', 'to', 'file', 'this can not exist'))
459 self.assertEqual(path, path.resolve())
465 self.assertEqual(self.path.cwd(),
466 self.path(self.os.path.realpath(dir_path)))
470 self.assertEqual(self.path('~').expanduser(),
471 self.path(
475 self.assertEqual(self.path('~').expanduser(),
476 self.path(os.environ['HOME']))
480 self.assertEqual(self.path.home(),
481 self.path(
485 self.assertEqual(self.path.home(),
486 self.path(os.environ['HOME']))
507 self.path(self.make_path('home', 'jane', 'test.py')).exists())
508 self.assertTrue(self.path(self.make_path('home', 'jane')).exists())
509 self.assertTrue(self.path(self.make_path('john')).exists())
510 self.assertFalse(self.path(self.make_path('none')).exists())
512 self.path(self.make_path('home', 'jane', 'test')).exists())
517 self.path(self.make_path('foo', 'bar.txt')).open)
518 self.path(self.make_path('foo', 'bar.txt')).open('w').close()
520 self.os.path.exists(self.make_path('foo', 'bar.txt')))
524 file_path = self.path(self.make_path('text_file'))
530 file_path = self.path(self.make_path('text_file'))
536 file_path = self.path(path_name)
538 self.assertTrue(self.os.path.exists(path_name))
543 file_path = self.path(path_name)
545 self.assertTrue(self.os.path.exists(path_name))
551 file_path = self.path(path_name)
556 file_path = self.path(path_name)
558 self.assertTrue(self.os.path.exists(path_name))
565 self.path(file_name).rename(new_file_name)
566 self.assertFalse(self.os.path.exists(file_name))
573 self.path(self.make_path('bar', 'old.txt')).replace(
576 self.os.path.exists(self.make_path('bar', 'old.txt')))
582 self.assertTrue(self.os.path.exists(file_path))
583 self.path(file_path).unlink()
584 self.assertFalse(self.os.path.exists(file_path))
589 self.path(file_name).touch(mode=0o444)
597 file_path = self.path(file_name)
609 self.path(
612 path = self.path(file_name)
614 self.assertRaises(OSError, path.samefile, other_name)
615 self.assertRaises(OSError, path.samefile, self.path(other_name))
616 self.assertFalse(path.samefile(file_name2))
617 self.assertFalse(path.samefile(self.path(file_name2)))
619 path.samefile(self.make_path('foo', '..', 'foo', 'bar.txt')))
620 self.assertTrue(path.samefile(
621 self.path(self.make_path('foo', '..', 'foo', 'bar.txt'))))
628 path = self.path(link_name)
629 path.symlink_to(file_name)
630 self.assertTrue(self.os.path.exists(link_name))
635 self.assertTrue(path.is_symlink())
640 self.path(dir_name).mkdir)
641 self.path(dir_name).mkdir(parents=True)
642 self.assertTrue(self.os.path.exists(dir_name))
644 self.path(dir_name).mkdir)
649 self.path(dir_name).mkdir(exist_ok=True)
650 file_name = self.os.path.join(dir_name, 'baz')
653 self.path(file_name).mkdir,
659 self.path(dir_name).rmdir()
660 self.assertFalse(self.os.path.exists(dir_name))
661 self.assertTrue(self.os.path.exists(self.make_path('foo')))
663 self.assertRaises(OSError, self.path(self.make_path('foo')).rmdir)
664 self.assertTrue(self.os.path.exists(self.make_path('foo')))
670 path = self.path(self.make_path('foo', 'bar'))
671 contents = [entry for entry in path.iterdir()]
673 self.assertIn(self.path(self.make_path('foo', 'bar', 'file2')),
681 path = self.path(self.make_path('foo'))
682 self.assertEqual(sorted(path.glob('*.py')),
683 [self.path(self.make_path('foo', 'all_tests.py')),
684 self.path(self.make_path('foo', 'setup.py'))])
692 path = self.path(self.make_path('foo'))
693 self.assertEqual(sorted(path.glob('*.py')),
694 [self.path(self.make_path('foo', 'all_tests.PY')),
695 self.path(self.make_path('foo', 'example.Py')),
696 self.path(self.make_path('foo', 'setup.py'))])
705 path = self.path(self.make_path('foo'))
706 self.assertEqual(sorted(path.glob('*.py')),
707 [self.path(self.make_path('foo', 'setup.py'))])
716 'path-like objects new in Python 3.6')
718 """Test that many os / os.path functions accept a path-like object
720 elsewhere, we just check that they accept a fake path object as an
727 dir = self.os.path.join(dir1, dir2)
728 self.assertEqual(dir, self.os.path.join(self.path(dir1), dir2))
729 self.assertEqual(dir, self.os.path.join(dir1, self.path(dir2)))
731 self.os.path.join(self.path(dir1),
732 self.path(dir2)))
736 self.assertEqual(self.os.path.normcase(dir1),
737 self.os.path.normcase(self.path(dir1)))
741 self.assertEqual(self.os.path.normpath(dir1),
742 self.os.path.normpath(self.path(dir1)))
746 self.assertEqual(self.os.path.realpath(dir1),
747 self.os.path.realpath(self.path(dir1)))
750 path_foo = self.make_path('path', 'to', 'foo')
751 path_bar = self.make_path('path', 'to', 'bar')
752 rel_path = self.os.path.relpath(path_foo, path_bar)
754 self.os.path.relpath(self.path(path_foo),
757 self.os.path.relpath(path_foo,
758 self.path(path_bar)))
760 self.os.path.relpath(self.path(path_foo),
761 self.path(path_bar)))
765 self.assertEqual(self.os.path.split(dir1),
766 self.os.path.split(self.path(dir1)))
770 self.assertEqual(self.os.path.splitdrive(dir1),
771 self.os.path.splitdrive(self.path(dir1)))
775 self.assertEqual(self.os.path.abspath(dir1),
776 self.os.path.abspath(self.path(dir1)))
780 self.assertEqual(self.os.path.exists(dir1),
781 self.os.path.exists(self.path(dir1)))
785 self.assertEqual(self.os.path.lexists(dir1),
786 self.os.path.lexists(self.path(dir1)))
789 dir1 = self.os.path.join('~', 'foo')
790 self.assertEqual(self.os.path.expanduser(dir1),
791 self.os.path.expanduser(self.path(dir1)))
798 self.assertEqual(self.os.path.getmtime(dir1),
799 self.os.path.getmtime(self.path(dir1)))
806 self.assertEqual(self.os.path.getctime(dir1),
807 self.os.path.getctime(self.path(dir1)))
814 self.assertEqual(self.os.path.getatime(dir1),
815 self.os.path.getatime(self.path(dir1)))
818 path = self.make_path('foo', 'bar', 'baz')
819 self.create_file(path, contents='1234567')
820 self.assertEqual(self.os.path.getsize(path),
821 self.os.path.getsize(self.path(path)))
824 path = self.make_path('foo', 'bar', '..', 'baz')
825 self.assertEqual(self.os.path.isabs(path),
826 self.os.path.isabs(self.path(path)))
829 path = self.make_path('foo', 'bar', 'baz')
830 self.create_file(path)
831 self.assertEqual(self.os.path.isfile(path),
832 self.os.path.isfile(self.path(path)))
835 path = self.make_path('foo', 'bar', 'baz')
836 self.create_file(path)
837 self.assertEqual(self.os.path.islink(path),
838 self.os.path.islink(self.path(path)))
841 path = self.make_path('foo', 'bar', 'baz')
842 self.create_file(path)
843 self.assertEqual(self.os.path.isdir(path),
844 self.os.path.isdir(self.path(path)))
847 path = self.os.path.sep
848 self.assertEqual(self.os.path.ismount(path),
849 self.os.path.ismount(self.path(path)))
852 path = self.make_path('foo', 'bar', 'baz')
853 self.create_file(path, contents='1234567')
854 self.assertEqual(self.os.access(path, os.R_OK),
855 self.os.access(self.path(path), os.R_OK))
858 path = self.make_path('foo', 'bar', 'baz')
859 self.create_dir(path)
860 self.os.chdir(self.path(path))
861 # use real path to handle symlink /var to /private/var in MacOs
862 self.assertEqual(self.os.path.realpath(path), self.os.getcwd())
865 path = self.make_path('some_file')
866 self.create_file(path)
867 self.os.chmod(self.path(path), 0o444)
869 stat.S_IMODE(self.os.stat(path).st_mode))
870 self.os.chmod(self.path(path), 0o666)
877 self.os.link(self.path(file1_path), file2_path)
878 self.assertTrue(self.os.path.exists(file2_path))
880 self.os.link(self.path(file1_path), self.path(file2_path))
881 self.assertTrue(self.os.path.exists(file2_path))
883 self.os.link(file1_path, self.path(file2_path))
884 self.assertTrue(self.os.path.exists(file2_path))
887 path = self.make_path('foo', 'bar')
888 self.create_dir(path)
889 self.create_file(path + 'baz.txt')
890 self.assertEqual(self.os.listdir(path),
891 self.os.listdir(self.path(path)))
894 path = self.make_path('foo')
895 self.os.mkdir(self.path(path))
896 self.assertTrue(self.os.path.exists(path))
899 path = self.make_path('foo', 'bar')
900 self.os.makedirs(self.path(path))
901 self.assertTrue(self.os.path.exists(path))
904 'path-like objects under Windows')
909 self.assertEqual(self.os.readlink(self.path(link_path)), target)
912 path = self.make_path('test.txt')
913 self.create_file(path)
914 self.os.remove(self.path(path))
915 self.assertFalse(self.os.path.exists(path))
921 self.os.rename(self.path(path1), path2)
922 self.assertTrue(self.os.path.exists(path2))
923 self.os.rename(self.path(path2), self.path(path1))
924 self.assertTrue(self.os.path.exists(path1))
930 self.os.replace(self.path(path1), path2)
931 self.assertTrue(self.os.path.exists(path2))
932 self.os.replace(self.path(path2), self.path(path1))
933 self.assertTrue(self.os.path.exists(path1))
936 path = self.make_path('foo', 'bar')
937 self.create_dir(path)
938 self.os.rmdir(self.path(path))
939 self.assertFalse(self.os.path.exists(path))
944 self.create_file(self.os.path.join(directory, 'test.txt'))
946 self.os.scandir(self.path(directory))]
954 self.os.symlink(self.path(file_path), link_path)
955 self.assertTrue(self.os.path.exists(link_path))
957 self.os.symlink(self.path(file_path), self.path(link_path))
958 self.assertTrue(self.os.path.exists(link_path))
961 path = self.make_path('foo', 'bar', 'baz')
962 self.create_file(path, contents='1234567')
963 self.assertEqual(self.os.stat(path), self.os.stat(self.path(path)))
966 path = self.make_path('some_file')
967 self.create_file(path, contents='test')
968 self.os.utime(self.path(path), times=(1, 2))
969 st = self.os.stat(path)
980 'Path-like objects new in Python 3.6')
991 dir_path = self.pathlib.Path(dir_path_string)
993 self.assertTrue(self.os.path.exists(dir_path_string))
1000 file_path = self.pathlib.Path(file_path_string)
1002 self.assertTrue(self.os.path.exists(file_path_string))
1008 file_path = self.pathlib.Path('foo/bar/baz')
1010 link_path = self.pathlib.Path(link_path_string)
1012 self.assertTrue(self.os.path.lexists(link_path_string))
1018 real_file_path_string = os.path.abspath(__file__)
1019 real_file_path = self.pathlib.Path(real_file_path_string)
1023 self.assertTrue(self.os.path.exists(fake_filepath_string))
1028 real_dirpath_string = os.path.dirname(os.path.abspath(__file__))
1029 real_dir_path = self.pathlib.Path(real_dirpath_string)
1033 self.assertTrue(self.os.path.exists(fake_dirpath_string))