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

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

Issue 4755: Common path prefix
Patch Set: Created 10 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
OLDNEW
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 import os 3 import os
4 import genericpath 4 import genericpath
5 5
6 class AllCommonTest(unittest.TestCase): 6 class AllCommonTest(unittest.TestCase):
7 7
8 def assertIs(self, a, b): 8 def assertIs(self, a, b):
9 self.assert_(a is b) 9 self.assert_(a is b)
10 10
11 def test_commonprefix(self): 11 def test_commonprefix(self):
12 self.assertEqual( 12 self.assertEqual(
13 genericpath.commonprefix([]), 13 genericpath.commonprefix([]),
14 "" 14 ""
15 ) 15 )
16 self.assertEqual( 16 self.assertEqual(
17 genericpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]), 17 genericpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
18 "/home/swen" 18 "/home/swen"
19 ) 19 )
20 self.assertEqual( 20 self.assertEqual(
21 genericpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]), 21 genericpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"]),
22 "/home/swen/" 22 "/home/swen/"
23 ) 23 )
24 self.assertEqual( 24 self.assertEqual(
25 genericpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]), 25 genericpath.commonprefix(["/home/swen/spam", "/home/swen/spam"]),
26 "/home/swen/spam" 26 "/home/swen/spam"
27 )
28 self.assertEqual(
29 genericpath.commonprefix(["/export/home/swen", "/etc/passwd"]),
30 "/e"
31 )
32
33 def test_commonpathprefix(self):
34 self.assertEqual(
35 genericpath.commonpathprefix([]),
36 ""
37 )
38 self.assertEqual(
39 genericpath.commonpathprefix(["/home/swenson/spam",
40 "/home/swen/spam"]),
41 "/home"
42 )
43 self.assertEqual(
44 genericpath.commonpathprefix(["/home/swenson/spam",
45 "/home/swen/spam"], ":"),
46 ""
47 )
48 self.assertEqual(
49 genericpath.commonpathprefix(["WhomeWswensonWspam",
50 "WhomeWswenWspam"], "W"),
51 "Whome"
52 )
53 self.assertEqual(
54 genericpath.commonpathprefix(["/home/swen/spam",
55 "/home/swen/eggs"]),
56 "/home/swen"
57 )
58 self.assertEqual(
59 genericpath.commonpathprefix(["/home/swen/spam",
60 "/home/swen/spam"]),
61 "/home/swen/spam"
62 )
63 self.assertEqual(
64 genericpath.commonpathprefix(["/home/swen/spam",
65 "swen/spam"]),
66 ""
67 )
68 self.assertEqual(
69 genericpath.commonpathprefix(["swen/eggs",
70 "swen/spam"]),
71 "swen"
72 )
73 self.assertEqual(
74 genericpath.commonpathprefix(["/export/home/swen", "/etc/passwd"]),
75 ""
27 ) 76 )
28 77
29 def test_getsize(self): 78 def test_getsize(self):
30 f = open(support.TESTFN, "wb") 79 f = open(support.TESTFN, "wb")
31 try: 80 try:
32 f.write(b"foo") 81 f.write(b"foo")
33 f.close() 82 f.close()
34 self.assertEqual(genericpath.getsize(support.TESTFN), 3) 83 self.assertEqual(genericpath.getsize(support.TESTFN), 3)
35 finally: 84 finally:
36 if not f.closed: 85 if not f.closed:
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 except os.error: 224 except os.error:
176 pass 225 pass
177 226
178 self.assertRaises(TypeError, genericpath.samefile) 227 self.assertRaises(TypeError, genericpath.samefile)
179 228
180 def test_main(): 229 def test_main():
181 support.run_unittest(AllCommonTest) 230 support.run_unittest(AllCommonTest)
182 231
183 if __name__=="__main__": 232 if __name__=="__main__":
184 test_main() 233 test_main()
OLDNEW
« Doc/library/os.path.rst ('K') | « Lib/os2emxpath.py ('k') | Lib/test/test_macpath.py » ('j') | no next file with comments »

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