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

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, 8 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/posixpath.py ('K') | « Lib/posixpath.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/']),
storchaka 2012/11/06 15:45:05 Test without trailing '/' will be more interesting
546 '/usr')
547
548 self.assertEqual(posixpath.commonpath(['spam']), 'spam')
549 self.assertEqual(posixpath.commonpath(['spam', 'spam']), 'spam')
550 self.assertEqual(posixpath.commonpath(['spam', 'alot']), '')
551 self.assertEqual(posixpath.commonpath(['and/jam', 'and/spam']), 'and')
552 self.assertEqual(
553 posixpath.commonpath(['and/jam', 'and/spam', 'alot']), '')
554 self.assertEqual(
555 posixpath.commonpath(['and/jam', 'and/spam', 'and']), 'and')
556
557 self.assertRaises(TypeError, posixpath.commonpath,
558 [b'/usr/lib/', '/usr/lib/python3'])
525 559
storchaka 2012/11/06 15:45:05 Tests with empty path ('') needed.
526 560
527 class PosixCommonTest(test_genericpath.CommonTest): 561 class PosixCommonTest(test_genericpath.CommonTest):
528 pathmodule = posixpath 562 pathmodule = posixpath
529 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat'] 563 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
530 564
531 565
532 def test_main(): 566 def test_main():
533 support.run_unittest(PosixPathTest, PosixCommonTest) 567 support.run_unittest(PosixPathTest, PosixCommonTest)
534 568
535 569
536 if __name__=="__main__": 570 if __name__=="__main__":
537 test_main() 571 test_main()
OLDNEW
« Lib/posixpath.py ('K') | « Lib/posixpath.py ('k') | no next file » | no next file with comments »

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