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

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, 9 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.assertEqual(posixpath.commonpath(['/usr/local']), '/usr/local')
530 self.assertEqual(posixpath.commonpath(['/usr/local', '/usr/local']),
531 '/usr/local')
532 self.assertEqual(posixpath.commonpath(['/usr/local/', '/usr/local']),
533 '/usr/local')
534 self.assertEqual(posixpath.commonpath(['/usr/local/', '/usr/local/']),
535 '/usr/local/')
536 self.assertEqual(posixpath.commonpath(['/', '/dev']), '/')
537 self.assertEqual(
538 posixpath.commonpath(['/usr/lib/', '/usr/lib/python3']),
539 '/usr/lib')
540 self.assertEqual(
541 posixpath.commonpath(['/usr/lib/', '/usr/lib/', '/dev/']), '/')
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 self.assertRaises(TypeError, posixpath.commonpath,
548 [b'/usr/lib/', '/usr/lib/python3'])
549 self.assertRaises(ValueError, posixpath.commonpath, ['spam', 'alot'])
525 550
526 551
527 class PosixCommonTest(test_genericpath.CommonTest): 552 class PosixCommonTest(test_genericpath.CommonTest):
528 pathmodule = posixpath 553 pathmodule = posixpath
529 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat'] 554 attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
530 555
531 556
532 def test_main(): 557 def test_main():
533 support.run_unittest(PosixPathTest, PosixCommonTest) 558 support.run_unittest(PosixPathTest, PosixCommonTest)
534 559
535 560
536 if __name__=="__main__": 561 if __name__=="__main__":
537 test_main() 562 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+