Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31598)

Side by Side Diff: Lib/test/test_posixpath.py

Issue 10395: new os.path function to extract common prefix based on path components
Patch Set: Created 6 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« Lib/test/test_ntpath.py ('K') | « Lib/test/test_ntpath.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import itertools 1 import itertools
2 import os 2 import os
3 import posixpath 3 import posixpath
4 import sys 4 import sys
5 import unittest 5 import unittest
6 import warnings 6 import warnings
7 from posixpath import realpath, abspath, dirname, basename 7 from posixpath import realpath, abspath, dirname, basename
8 from test import support, test_genericpath 8 from test import support, test_genericpath
9 9
10 try: 10 try:
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 515
516 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str") 516 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
517 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes") 517 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")
518 finally: 518 finally:
519 os.getcwdb = real_getcwdb 519 os.getcwdb = real_getcwdb
520 520
521 def test_sameopenfile(self): 521 def test_sameopenfile(self):
522 fname = support.TESTFN + "1" 522 fname = support.TESTFN + "1"
523 with open(fname, "wb") as a, open(fname, "wb") as b: 523 with open(fname, "wb") as a, open(fname, "wb") as b:
524 self.assertTrue(posixpath.sameopenfile(a.fileno(), b.fileno())) 524 self.assertTrue(posixpath.sameopenfile(a.fileno(), b.fileno()))
525
526 def test_commonpath(self):
527
528 self.assertIsNone(posixpath.commonpath([]))
529 self.assertIsNone(posixpath.commonpath(['/usr', 'spam']))
530 self.assertEqual(posixpath.commonpath(['/usr/local']), '/usr/local')
531 self.assertEqual(posixpath.commonpath(['/usr/local', '/usr/local']),
532 '/usr/local')
533 self.assertEqual(posixpath.commonpath(['/usr/local/', '/usr/local']),
534 '/usr/local')
535 self.assertEqual(posixpath.commonpath(['/usr/local/', '/usr/local/']),
536 '/usr/local')
537 self.assertEqual(posixpath.commonpath(['/', '/dev']), '/')
538 self.assertEqual(posixpath.commonpath(['/usr', '/dev']), '/')
539 self.assertEqual(
540 posixpath.commonpath(['/usr/lib/', '/usr/lib/python3']),
541 '/usr/lib')
542 self.assertEqual(
543 posixpath.commonpath([b'/usr/lib/', b'/usr/lib/python3']),
544 b'/usr/lib')
545 self.assertEqual(posixpath.commonpath(['/usr/lib/', '/usr/lib64/']),
546 '/usr')
547
548 self.assertEqual(posixpath.commonpath(['/usr/lib', '/usr/lib64']),
549 '/usr')
550 self.assertEqual(posixpath.commonpath(['/usr/lib/', '/usr/lib64']),
551 '/usr')
552
553 self.assertEqual(posixpath.commonpath(['spam']), 'spam')
554 self.assertEqual(posixpath.commonpath(['spam', 'spam']), 'spam')
555 self.assertEqual(posixpath.commonpath(['spam', 'alot']), '')
556 self.assertEqual(posixpath.commonpath(['and/jam', 'and/spam']), 'and')
557 self.assertEqual(
558 posixpath.commonpath(['and/jam', 'and/spam', 'alot']), '')
559 self.assertEqual(
560 posixpath.commonpath(['and/jam', 'and/spam', 'and']), 'and')
561
562 self.assertEqual(posixpath.commonpath(['']), '')
563 self.assertEqual(posixpath.commonpath(['', 'spam/alot']), '')
564 self.assertIsNone(posixpath.commonpath(['', '/spam/alot']))
565
566 self.assertRaises(TypeError, posixpath.commonpath,
567 [b'/usr/lib/', '/usr/lib/python3'])
525 568
526 569
527 class PosixCommonTest(test_genericpath.CommonTest): 570 class PosixCommonTest(test_genericpath.CommonTest):
528 pathmodule = posixpath 571 pathmodule = posixpath
529 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat'] 572 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
530 573
531 574
532 def test_main(): 575 def test_main():
533 support.run_unittest(PosixPathTest, PosixCommonTest) 576 support.run_unittest(PosixPathTest, PosixCommonTest)
534 577
535 578
536 if __name__=="__main__": 579 if __name__=="__main__":
537 test_main() 580 test_main()
OLDNEW
« Lib/test/test_ntpath.py ('K') | « Lib/test/test_ntpath.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+