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

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

Issue 4755: Common path prefix
Patch Set: Created 10 years, 11 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 ntpath 1 import ntpath
2 import os 2 import os
3 from test.support import verbose, TestFailed 3 from test.support import verbose, TestFailed
4 import test.support as support 4 import test.support as support
5 import unittest 5 import unittest
6 6
7 7
8 def tester(fn, wantResult): 8 def tester(fn, wantResult):
9 fn = fn.replace("\\", "\\\\") 9 fn = fn.replace("\\", "\\\\")
10 gotResult = eval(fn) 10 gotResult = eval(fn)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ('\\\\conky\\mountpoint', '')) 65 ('\\\\conky\\mountpoint', ''))
66 66
67 tester('ntpath.split("c:/")', ('c:/', '')) 67 tester('ntpath.split("c:/")', ('c:/', ''))
68 tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', '') ) 68 tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', '') )
69 69
70 def test_isabs(self): 70 def test_isabs(self):
71 tester('ntpath.isabs("c:\\")', 1) 71 tester('ntpath.isabs("c:\\")', 1)
72 tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1) 72 tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
73 tester('ntpath.isabs("\\foo")', 1) 73 tester('ntpath.isabs("\\foo")', 1)
74 tester('ntpath.isabs("\\foo\\bar")', 1) 74 tester('ntpath.isabs("\\foo\\bar")', 1)
75
76 def test_commonpathprefix(self):
77 self.assertEqual(ntpath.commonpathprefix([]), "")
78 self.assertEqual(ntpath.commonpathprefix(["/home/swenson/spam",
79 "/home/swen/spam"]),
80 "\\home")
81 self.assertEqual(ntpath.commonpathprefix(["\\home\\swenson\\spam",
82 "\\home\\swen\\spam"]),
83 "\\home")
84 self.assertEqual(
85 ntpath.commonpathprefix(["\\home\\swen\\spam",
86 "\\home\\swen\\eggs"]),
87 "\\home\\swen"
88 )
89 self.assertEqual(
90 ntpath.commonpathprefix(["\\home\\swen\\spam",
91 "\\home\\swen\\spam"]),
92 "\\home\\swen\\spam"
93 )
94 self.assertEqual(
95 ntpath.commonpathprefix(["\\home\\swen\\spam",
96 "swen\\spam"]),
97 ""
98 )
99 self.assertEqual(
100 ntpath.commonpathprefix(["swen\\eggs",
101 "swen\\spam"]),
102 "swen"
103 )
104 self.assertEqual(
105 ntpath.commonpathprefix(["\\export\\home\\swen",
106 "\\etc\\passwd"]),
107 ""
108 )
75 109
76 def test_commonprefix(self): 110 def test_commonprefix(self):
77 tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])', 111 tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
78 "/home/swen") 112 "/home/swen")
79 tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"] )', 113 tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"] )',
80 "\\home\\swen\\") 114 "\\home\\swen\\")
81 tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', 115 tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
82 "/home/swen/spam") 116 "/home/swen/spam")
83 117
84 def test_join(self): 118 def test_join(self):
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c") ', '..\\..\\a') 229 tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c") ', '..\\..\\a')
196 tester('ntpath.relpath("a", "a")', '.') 230 tester('ntpath.relpath("a", "a")', '.')
197 231
198 232
199 def test_main(): 233 def test_main():
200 support.run_unittest(TestNtpath) 234 support.run_unittest(TestNtpath)
201 235
202 236
203 if __name__ == "__main__": 237 if __name__ == "__main__":
204 unittest.main() 238 unittest.main()
OLDNEW

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