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

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 5 years, 4 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
« no previous file with comments | « 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo /bar/bat') 530 self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo /bar/bat')
531 self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../ ../x') 531 self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../ ../x')
532 self.assertEqual(posixpath.relpath(b"/", b"/"), b'.') 532 self.assertEqual(posixpath.relpath(b"/", b"/"), b'.')
533 self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.') 533 self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.')
534 self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.') 534 self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.')
535 535
536 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str") 536 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
537 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes") 537 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")
538 finally: 538 finally:
539 os.getcwdb = real_getcwdb 539 os.getcwdb = real_getcwdb
540
541 def test_commonpath(self):
542 def check(paths, expected):
543 self.assertEqual(posixpath.commonpath(paths), expected)
544 self.assertEqual(posixpath.commonpath([os.fsencode(p) for p in paths ]),
545 os.fsencode(expected))
546 def check_error(exc, paths):
547 self.assertRaises(exc, posixpath.commonpath, paths)
548 self.assertRaises(exc, posixpath.commonpath,
549 [os.fsencode(p) for p in paths])
550
551 self.assertRaises(ValueError, posixpath.commonpath, [])
552 check_error(ValueError, ['/usr', 'usr'])
553 check_error(ValueError, ['usr', '/usr'])
554
555 check(['/usr/local'], '/usr/local')
556 check(['/usr/local', '/usr/local'], '/usr/local')
557 check(['/usr/local/', '/usr/local'], '/usr/local')
558 check(['/usr/local/', '/usr/local/'], '/usr/local')
559 check(['/usr//local', '//usr/local'], '/usr/local')
560 check(['/usr/./local', '/./usr/local'], '/usr/local')
561 check(['/', '/dev'], '/')
562 check(['/usr', '/dev'], '/')
563 check(['/usr/lib/', '/usr/lib/python3'], '/usr/lib')
564 check(['/usr/lib/', '/usr/lib64/'], '/usr')
565
566 check(['/usr/lib', '/usr/lib64'], '/usr')
567 check(['/usr/lib/', '/usr/lib64'], '/usr')
568
569 check(['spam'], 'spam')
570 check(['spam', 'spam'], 'spam')
571 check(['spam', 'alot'], '')
572 check(['and/jam', 'and/spam'], 'and')
573 check(['and//jam', 'and/spam//'], 'and')
574 check(['and/./jam', './and/spam'], 'and')
575 check(['and/jam', 'and/spam', 'alot'], '')
576 check(['and/jam', 'and/spam', 'and'], 'and')
577
578 check([''], '')
579 check(['', 'spam/alot'], '')
580 check_error(ValueError, ['', '/spam/alot'])
581
582 self.assertRaises(TypeError, posixpath.commonpath,
583 [b'/usr/lib/', '/usr/lib/python3'])
584 self.assertRaises(TypeError, posixpath.commonpath,
585 [b'/usr/lib/', 'usr/lib/python3'])
586 self.assertRaises(TypeError, posixpath.commonpath,
587 [b'usr/lib/', '/usr/lib/python3'])
588 self.assertRaises(TypeError, posixpath.commonpath,
589 ['/usr/lib/', b'/usr/lib/python3'])
590 self.assertRaises(TypeError, posixpath.commonpath,
591 ['/usr/lib/', b'usr/lib/python3'])
592 self.assertRaises(TypeError, posixpath.commonpath,
593 ['usr/lib/', b'/usr/lib/python3'])
540 594
541 595
542 class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase): 596 class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase):
543 pathmodule = posixpath 597 pathmodule = posixpath
544 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat'] 598 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
545 599
546 600
547 if __name__=="__main__": 601 if __name__=="__main__":
548 unittest.main() 602 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_ntpath.py ('k') | no next file » | no next file with comments »

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