Lines Matching refs:self

27     def test_no_argument(self):
28 for attr in self.common_attributes + self.attributes:
29 with self.assertRaises(TypeError):
30 getattr(self.pathmodule, attr)()
31 raise self.fail("{}.{}() did not raise a TypeError"
32 .format(self.pathmodule.__name__, attr))
34 def test_commonprefix(self):
35 commonprefix = self.pathmodule.commonprefix
36 self.assertEqual(
40 self.assertEqual(
44 self.assertEqual(
48 self.assertEqual(
52 self.assertEqual(
56 self.assertEqual(
60 self.assertEqual(
65 self.assertEqual(
69 self.assertEqual(
73 self.assertEqual(
77 self.assertEqual(
81 self.assertEqual(
85 self.assertEqual(
95 self.assertTrue(s1.startswith(p))
96 self.assertTrue(s2.startswith(p))
99 self.assertNotEqual(s1[n:n+1], s2[n:n+1])
101 def test_getsize(self):
103 self.addCleanup(os_helper.unlink, filename)
106 self.assertEqual(self.pathmodule.getsize(filename), 5)
110 self.assertEqual(self.pathmodule.getsize(filename), 12)
112 def test_filetime(self):
114 self.addCleanup(os_helper.unlink, filename)
123 self.assertEqual(data, b"foobar")
125 self.assertLessEqual(
126 self.pathmodule.getctime(filename),
127 self.pathmodule.getmtime(filename)
130 def test_exists(self):
133 self.addCleanup(os_helper.unlink, filename)
135 self.assertIs(self.pathmodule.exists(filename), False)
136 self.assertIs(self.pathmodule.exists(bfilename), False)
140 self.assertIs(self.pathmodule.exists(filename), True)
141 self.assertIs(self.pathmodule.exists(bfilename), True)
143 self.assertIs(self.pathmodule.exists(filename + '\udfff'), False)
144 self.assertIs(self.pathmodule.exists(bfilename + b'\xff'), False)
145 self.assertIs(self.pathmodule.exists(filename + '\x00'), False)
146 self.assertIs(self.pathmodule.exists(bfilename + b'\x00'), False)
148 if self.pathmodule is not genericpath:
149 self.assertIs(self.pathmodule.lexists(filename), True)
150 self.assertIs(self.pathmodule.lexists(bfilename), True)
152 self.assertIs(self.pathmodule.lexists(filename + '\udfff'), False)
153 self.assertIs(self.pathmodule.lexists(bfilename + b'\xff'), False)
154 self.assertIs(self.pathmodule.lexists(filename + '\x00'), False)
155 self.assertIs(self.pathmodule.lexists(bfilename + b'\x00'), False)
159 def test_exists_fd(self):
162 self.assertTrue(self.pathmodule.exists(r))
166 self.assertFalse(self.pathmodule.exists(r))
168 def test_isdir(self):
171 self.assertIs(self.pathmodule.isdir(filename), False)
172 self.assertIs(self.pathmodule.isdir(bfilename), False)
174 self.assertIs(self.pathmodule.isdir(filename + '\udfff'), False)
175 self.assertIs(self.pathmodule.isdir(bfilename + b'\xff'), False)
176 self.assertIs(self.pathmodule.isdir(filename + '\x00'), False)
177 self.assertIs(self.pathmodule.isdir(bfilename + b'\x00'), False)
181 self.assertIs(self.pathmodule.isdir(filename), False)
182 self.assertIs(self.pathmodule.isdir(bfilename), False)
188 self.assertIs(self.pathmodule.isdir(filename), True)
189 self.assertIs(self.pathmodule.isdir(bfilename), True)
193 def test_isfile(self):
196 self.assertIs(self.pathmodule.isfile(filename), False)
197 self.assertIs(self.pathmodule.isfile(bfilename), False)
199 self.assertIs(self.pathmodule.isfile(filename + '\udfff'), False)
200 self.assertIs(self.pathmodule.isfile(bfilename + b'\xff'), False)
201 self.assertIs(self.pathmodule.isfile(filename + '\x00'), False)
202 self.assertIs(self.pathmodule.isfile(bfilename + b'\x00'), False)
206 self.assertIs(self.pathmodule.isfile(filename), True)
207 self.assertIs(self.pathmodule.isfile(bfilename), True)
213 self.assertIs(self.pathmodule.isfile(filename), False)
214 self.assertIs(self.pathmodule.isfile(bfilename), False)
218 def test_samefile(self):
221 self.addCleanup(os_helper.unlink, file1)
222 self.addCleanup(os_helper.unlink, file2)
225 self.assertTrue(self.pathmodule.samefile(file1, file1))
228 self.assertFalse(self.pathmodule.samefile(file1, file2))
230 self.assertRaises(TypeError, self.pathmodule.samefile)
232 def _test_samefile_on_link_func(self, func):
235 self.addCleanup(os_helper.unlink, test_fn1)
236 self.addCleanup(os_helper.unlink, test_fn2)
241 self.assertTrue(self.pathmodule.samefile(test_fn1, test_fn2))
245 self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2))
248 def test_samefile_on_symlink(self):
249 self._test_samefile_on_link_func(os.symlink)
252 def test_samefile_on_link(self):
254 self._test_samefile_on_link_func(os.link)
256 self.skipTest('os.link(): %s' % e)
258 def test_samestat(self):
261 self.addCleanup(os_helper.unlink, test_fn1)
262 self.addCleanup(os_helper.unlink, test_fn2)
266 self.assertTrue(self.pathmodule.samestat(stat1, os.stat(test_fn1)))
270 self.assertFalse(self.pathmodule.samestat(stat1, stat2))
272 self.assertRaises(TypeError, self.pathmodule.samestat)
274 def _test_samestat_on_link_func(self, func):
277 self.addCleanup(os_helper.unlink, test_fn1)
278 self.addCleanup(os_helper.unlink, test_fn2)
282 self.assertTrue(self.pathmodule.samestat(os.stat(test_fn1),
287 self.assertFalse(self.pathmodule.samestat(os.stat(test_fn1),
291 def test_samestat_on_symlink(self):
292 self._test_samestat_on_link_func(os.symlink)
295 def test_samestat_on_link(self):
297 self._test_samestat_on_link_func(os.link)
299 self.skipTest('os.link(): %s' % e)
301 def test_sameopenfile(self):
303 self.addCleanup(os_helper.unlink, filename)
310 self.assertTrue(self.pathmodule.sameopenfile(fd1, fd2))
319 def test_invalid_paths(self):
324 func = getattr(self.pathmodule, attr)
325 with self.subTest(attr=attr):
332 with self.assertRaises((OSError, UnicodeEncodeError)):
334 with self.assertRaises((OSError, UnicodeDecodeError)):
336 with self.assertRaisesRegex(ValueError, 'embedded null'):
338 with self.assertRaisesRegex(ValueError, 'embedded null'):
355 def test_normcase(self):
356 normcase = self.pathmodule.normcase
360 self.assertEqual(p, normcase(p))
362 self.assertEqual(normcase(''), '')
363 self.assertEqual(normcase(b''), b'')
367 self.assertRaises(TypeError, normcase, path)
369 def test_splitdrive(self):
371 splitdrive = self.pathmodule.splitdrive
372 self.assertEqual(splitdrive("/foo/bar"), ("", "/foo/bar"))
373 self.assertEqual(splitdrive("foo:bar"), ("", "foo:bar"))
374 self.assertEqual(splitdrive(":foo:bar"), ("", ":foo:bar"))
376 self.assertEqual(splitdrive(b"/foo/bar"), (b"", b"/foo/bar"))
377 self.assertEqual(splitdrive(b"foo:bar"), (b"", b"foo:bar"))
378 self.assertEqual(splitdrive(b":foo:bar"), (b"", b":foo:bar"))
380 def test_expandvars(self):
381 expandvars = self.pathmodule.expandvars
387 self.assertEqual(expandvars("foo"), "foo")
388 self.assertEqual(expandvars("$foo bar"), "bar bar")
389 self.assertEqual(expandvars("${foo}bar"), "barbar")
390 self.assertEqual(expandvars("$[foo]bar"), "$[foo]bar")
391 self.assertEqual(expandvars("$bar bar"), "$bar bar")
392 self.assertEqual(expandvars("$?bar"), "$?bar")
393 self.assertEqual(expandvars("$foo}bar"), "bar}bar")
394 self.assertEqual(expandvars("${foo"), "${foo")
395 self.assertEqual(expandvars("${{foo}}"), "baz1}")
396 self.assertEqual(expandvars("$foo$foo"), "barbar")
397 self.assertEqual(expandvars("$bar$bar"), "$bar$bar")
399 self.assertEqual(expandvars(b"foo"), b"foo")
400 self.assertEqual(expandvars(b"$foo bar"), b"bar bar")
401 self.assertEqual(expandvars(b"${foo}bar"), b"barbar")
402 self.assertEqual(expandvars(b"$[foo]bar"), b"$[foo]bar")
403 self.assertEqual(expandvars(b"$bar bar"), b"$bar bar")
404 self.assertEqual(expandvars(b"$?bar"), b"$?bar")
405 self.assertEqual(expandvars(b"$foo}bar"), b"bar}bar")
406 self.assertEqual(expandvars(b"${foo"), b"${foo")
407 self.assertEqual(expandvars(b"${{foo}}"), b"baz1}")
408 self.assertEqual(expandvars(b"$foo$foo"), b"barbar")
409 self.assertEqual(expandvars(b"$bar$bar"), b"$bar$bar")
412 def test_expandvars_nonascii(self):
413 expandvars = self.pathmodule.expandvars
415 self.assertEqual(expandvars(value), expected)
437 def test_abspath(self):
438 self.assertIn("foo", self.pathmodule.abspath("foo"))
441 self.assertIn(b"foo", self.pathmodule.abspath(b"foo"))
450 self.assertIsInstance(self.pathmodule.abspath(path), bytes)
452 def test_realpath(self):
453 self.assertIn("foo", self.pathmodule.realpath("foo"))
456 self.assertIn(b"foo", self.pathmodule.realpath(b"foo"))
458 def test_normpath_issue5827(self):
461 self.assertIsInstance(self.pathmodule.normpath(path), str)
463 def test_normpath_issue106242(self):
465 self.assertEqual(self.pathmodule.normpath(path), path)
467 def test_abspath_issue3426(self):
470 abspath = self.pathmodule.abspath
472 self.assertIsInstance(abspath(path), str)
483 self.assertIsInstance(abspath(path), str)
485 def test_nonascii_abspath(self):
496 self.skipTest("need os_helper.TESTFN_NONASCII")
501 self.test_abspath()
503 def test_join_errors(self):
507 with self.assertRaisesRegex(TypeError, errmsg):
508 self.pathmodule.join(b'bytes', 'str')
509 with self.assertRaisesRegex(TypeError, errmsg):
510 self.pathmodule.join('str', b'bytes')
512 with self.assertRaisesRegex(TypeError, 'int'):
513 self.pathmodule.join(42, 'str')
514 with self.assertRaisesRegex(TypeError, 'int'):
515 self.pathmodule.join('str', 42)
516 with self.assertRaisesRegex(TypeError, 'int'):
517 self.pathmodule.join(42)
518 with self.assertRaisesRegex(TypeError, 'list'):
519 self.pathmodule.join([])
520 with self.assertRaisesRegex(TypeError, 'bytearray'):
521 self.pathmodule.join(bytearray(b'foo'), bytearray(b'bar'))
523 def test_relpath_errors(self):
528 with self.assertRaisesRegex(TypeError, errmsg):
529 self.pathmodule.relpath(b'bytes', 'str')
530 with self.assertRaisesRegex(TypeError, errmsg):
531 self.pathmodule.relpath('str', b'bytes')
532 with self.assertRaisesRegex(TypeError, 'int'):
533 self.pathmodule.relpath(42, 'str')
534 with self.assertRaisesRegex(TypeError, 'int'):
535 self.pathmodule.relpath('str', 42)
536 with self.assertRaisesRegex(TypeError, 'bytearray'):
537 self.pathmodule.relpath(bytearray(b'foo'), bytearray(b'bar'))
539 def test_import(self):
540 assert_python_ok('-S', '-c', 'import ' + self.pathmodule.__name__)
545 def setUp(self):
546 self.file_name = os_helper.TESTFN
547 self.file_path = FakePath(os_helper.TESTFN)
548 self.addCleanup(os_helper.unlink, self.file_name)
549 create_file(self.file_name, b"test_genericpath.PathLikeTests")
551 def assertPathEqual(self, func):
552 self.assertEqual(func(self.file_path), func(self.file_name))
554 def test_path_exists(self):
555 self.assertPathEqual(os.path.exists)
557 def test_path_isfile(self):
558 self.assertPathEqual(os.path.isfile)
560 def test_path_isdir(self):
561 self.assertPathEqual(os.path.isdir)
563 def test_path_commonprefix(self):
564 self.assertEqual(os.path.commonprefix([self.file_path, self.file_name]),
565 self.file_name)
567 def test_path_getsize(self):
568 self.assertPathEqual(os.path.getsize)
570 def test_path_getmtime(self):
571 self.assertPathEqual(os.path.getatime)
573 def test_path_getctime(self):
574 self.assertPathEqual(os.path.getctime)
576 def test_path_samefile(self):
577 self.assertTrue(os.path.samefile(self.file_path, self.file_name))