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

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

Issue 10395: new os.path function to extract common prefix based on path components
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Lib/posixpath.py ('k') | Lib/test/test_posixpath.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import ntpath 1 import ntpath
2 import os 2 import os
3 import sys 3 import sys
4 import unittest 4 import unittest
5 import warnings 5 import warnings
6 from test.support import TestFailed 6 from test.support import TestFailed
7 from test import support, test_genericpath 7 from test import support, test_genericpath
8 from tempfile import TemporaryFile 8 from tempfile import TemporaryFile
9 9
10 10
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar \\bat') 235 tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar \\bat')
236 tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat') 236 tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat')
237 tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat') 237 tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat')
238 tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..') 238 tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..')
239 tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat') 239 tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat')
240 tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x') 240 tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x')
241 tester('ntpath.relpath("/", "/")', '.') 241 tester('ntpath.relpath("/", "/")', '.')
242 tester('ntpath.relpath("/a", "/a")', '.') 242 tester('ntpath.relpath("/a", "/a")', '.')
243 tester('ntpath.relpath("/a/b", "/a/b")', '.') 243 tester('ntpath.relpath("/a/b", "/a/b")', '.')
244 tester('ntpath.relpath("c:/foo", "C:/FOO")', '.') 244 tester('ntpath.relpath("c:/foo", "C:/FOO")', '.')
245
246 def test_commonpath(self):
247
248 tester('ntpath.commonpath([])', None)
249 tester('ntpath.commonpath(["C:\\Program Files", "Documents/"])', None)
250 tester('ntpath.commonpath(["C:\\Program Files"])', 'C:\\Program Files')
251 tester('ntpath.commonpath(["C:\\Program Files", "C:\\Program Files"])', 'C:\\Program Files')
252 tester('ntpath.commonpath(["C:\\Program Files\\", "C:\\Program Files"])' , 'C:\\Program Files')
253 tester('ntpath.commonpath(["C:\\Program Files\\", "C:\\Program Files\\"] )', 'C:\\Program Files')
254 tester('ntpath.commonpath(["C:\\", "C:\\bin"])', 'C:\\')
255 tester('ntpath.commonpath(["C:\\Program Files", "C:\\bin"])', 'C:\\')
256 tester('ntpath.commonpath(["C:\\Program Files", "C:\\Program Files\\Bar" ])', 'C:\\Program Files')
257 tester('ntpath.commonpath(["C:\\Program Files\\Foo", "C:\\Program Files\ \Bar"])', 'C:\\Program Files')
258 tester('ntpath.commonpath([b"C:\\Program Files\\Foo", b"C:\\Program File s\\Bar"])', b'C:\\Program Files')
259 tester('ntpath.commonpath(["C:\\Program Files", "C:\\Projects"])', 'C:\\ ')
260 tester('ntpath.commonpath(["C:\\Program Files\\", "C:\\Projects"])', 'C: \\')
261
262 tester('ntpath.commonpath(["C:\\Program Files\\Foo", "C:/Program Files/B ar"])', 'C:\\Program Files')
263 tester('ntpath.commonpath(["C:\\Program Files\\Foo", "c:/program files/b ar"])', 'C:\\Program Files')
264 tester('ntpath.commonpath(["c:/program files/bar", "C:\\Program Files\\F oo"])', 'c:\\program files')
265
266 tester('ntpath.commonpath(["C:\\Program Files\\Foo", "D:/Program Files/B ar"])', None)
267
268 # tester function won't work with the following tests
269 self.assertEquals(ntpath.commonpath(['spam']), 'spam')
storchaka 2012/11/13 10:24:46 self.assertEqual
270 self.assertEqual(ntpath.commonpath(['spam']), 'spam')
271 self.assertEqual(ntpath.commonpath(['spam', 'spam']), 'spam')
272 self.assertEqual(ntpath.commonpath(['spam', 'alot']), '')
273 self.assertEqual(ntpath.commonpath(['and\\jam', 'and\\spam']), 'and')
274 self.assertEqual(
275 ntpath.commonpath(['and\\jam', 'and\\spam', 'alot']), '')
276 self.assertEqual(
277 ntpath.commonpath(['and\\jam', 'and\\spam', 'and']), 'and')
278
279 self.assertEqual(ntpath.commonpath(['']), '')
280 self.assertEqual(ntpath.commonpath(['', 'spam\\alot']), '')
281 self.assertIsNone(ntpath.commonpath(['', '\\spam\\alot']))
282
283 self.assertRaises(TypeError, ntpath.commonpath,
284 [b'C:\\Program Files', 'C:\\Program Files\\Foo'])
245 285
246 def test_sameopenfile(self): 286 def test_sameopenfile(self):
247 with TemporaryFile() as tf1, TemporaryFile() as tf2: 287 with TemporaryFile() as tf1, TemporaryFile() as tf2:
248 # Make sure the same file is really the same 288 # Make sure the same file is really the same
249 self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno())) 289 self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno()))
250 # Make sure different files are really different 290 # Make sure different files are really different
251 self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno())) 291 self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno()))
252 # Make sure invalid values don't cause issues on win32 292 # Make sure invalid values don't cause issues on win32
253 if sys.platform == "win32": 293 if sys.platform == "win32":
254 with self.assertRaises(OSError): 294 with self.assertRaises(OSError):
255 # Invalid file descriptors shouldn't display assert 295 # Invalid file descriptors shouldn't display assert
256 # dialogs (#4804) 296 # dialogs (#4804)
257 ntpath.sameopenfile(-1, -1) 297 ntpath.sameopenfile(-1, -1)
258 298
259 299
260 class NtCommonTest(test_genericpath.CommonTest): 300 class NtCommonTest(test_genericpath.CommonTest):
261 pathmodule = ntpath 301 pathmodule = ntpath
262 attributes = ['relpath', 'splitunc'] 302 attributes = ['relpath', 'splitunc']
263 303
264 304
265 def test_main(): 305 def test_main():
266 support.run_unittest(TestNtpath, NtCommonTest) 306 support.run_unittest(TestNtpath, NtCommonTest)
267 307
268 308
269 if __name__ == "__main__": 309 if __name__ == "__main__":
270 unittest.main() 310 unittest.main()
OLDNEW
« no previous file with comments | « Lib/posixpath.py ('k') | Lib/test/test_posixpath.py » ('j') | no next file with comments »

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