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

Side by Side Diff: Lib/test/test_posixpath.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
« Doc/library/os.path.rst ('K') | « 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 unittest 1 import unittest
2 from test import support 2 from test import support
3 3
4 import posixpath, os 4 import posixpath, os
5 from posixpath import realpath, abspath, join, dirname, basename, relpath 5 from posixpath import realpath, abspath, join, dirname, basename, relpath
6 6
7 # An absolute path to a temporary filename for testing. We can't rely on TESTFN 7 # An absolute path to a temporary filename for testing. We can't rely on TESTFN
8 # being an absolute path, so we need this. 8 # being an absolute path, so we need this.
9 9
10 ABSTFN = abspath(support.TESTFN) 10 ABSTFN = abspath(support.TESTFN)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 self.assertEqual(posixpath.dirname("////foo"), "////") 157 self.assertEqual(posixpath.dirname("////foo"), "////")
158 self.assertEqual(posixpath.dirname("//foo//bar"), "//foo") 158 self.assertEqual(posixpath.dirname("//foo//bar"), "//foo")
159 159
160 self.assertEqual(posixpath.dirname(b"/foo/bar"), b"/foo") 160 self.assertEqual(posixpath.dirname(b"/foo/bar"), b"/foo")
161 self.assertEqual(posixpath.dirname(b"/"), b"/") 161 self.assertEqual(posixpath.dirname(b"/"), b"/")
162 self.assertEqual(posixpath.dirname(b"foo"), b"") 162 self.assertEqual(posixpath.dirname(b"foo"), b"")
163 self.assertEqual(posixpath.dirname(b"////foo"), b"////") 163 self.assertEqual(posixpath.dirname(b"////foo"), b"////")
164 self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo") 164 self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo")
165 165
166 self.assertRaises(TypeError, posixpath.dirname) 166 self.assertRaises(TypeError, posixpath.dirname)
167
168 def test_commonpathprefix(self):
169 self.assertEqual(
170 genericpath.commonpathprefix([]),
171 ""
172 )
173 self.assertEqual(
174 genericpath.commonpathprefix(["/home/swenson/spam",
175 "/home/swen/spam"]),
176 "/home"
177 )
178 self.assertEqual(
179 genericpath.commonpathprefix(["/home/swen/spam",
180 "/home/swen/eggs"]),
181 "/home/swen"
182 )
183 self.assertEqual(
184 genericpath.commonpathprefix(["/home/swen/spam",
185 "/home/swen/spam"]),
186 "/home/swen/spam"
187 )
188 self.assertEqual(
189 genericpath.commonpathprefix(["/home/swen/spam",
190 "swen/spam"]),
191 ""
192 )
193 self.assertEqual(
194 genericpath.commonpathprefix(["swen/eggs",
195 "swen/spam"]),
196 "swen"
197 )
198 self.assertEqual(
199 genericpath.commonprefix(["/export/home/swen", "/etc/passwd"]),
200 ""
201 )
167 202
168 def test_commonprefix(self): 203 def test_commonprefix(self):
169 self.assertEqual( 204 self.assertEqual(
170 posixpath.commonprefix([]), 205 posixpath.commonprefix([]),
171 "" 206 ""
172 ) 207 )
173 self.assertEqual( 208 self.assertEqual(
174 posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]), 209 posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"]),
175 "/home/swen" 210 "/home/swen"
176 ) 211 )
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str") 660 self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
626 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes") 661 self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")
627 finally: 662 finally:
628 os.getcwdb = real_getcwdb 663 os.getcwdb = real_getcwdb
629 664
630 def test_main(): 665 def test_main():
631 support.run_unittest(PosixPathTest) 666 support.run_unittest(PosixPathTest)
632 667
633 if __name__=="__main__": 668 if __name__=="__main__":
634 test_main() 669 test_main()
OLDNEW
« Doc/library/os.path.rst ('K') | « Lib/test/test_ntpath.py ('k') | no next file » | no next file with comments »

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