mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Add some test cases for ntpath.join().
This commit is contained in:
parent
3b5e4d1e3c
commit
d4f7f609bf
1 changed files with 19 additions and 3 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
import ntpath
|
import ntpath
|
||||||
from test_support import verbose
|
from test_support import verbose, TestFailed
|
||||||
import os
|
import os
|
||||||
|
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
|
global errors
|
||||||
fn = fn.replace("\\", "\\\\")
|
fn = fn.replace("\\", "\\\\")
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
|
|
@ -13,7 +14,6 @@ def tester(fn, wantResult):
|
||||||
print "should be: " + str(wantResult)
|
print "should be: " + str(wantResult)
|
||||||
print " returned: " + str(gotResult)
|
print " returned: " + str(gotResult)
|
||||||
print ""
|
print ""
|
||||||
global errors
|
|
||||||
errors = errors + 1
|
errors = errors + 1
|
||||||
|
|
||||||
tester('ntpath.splitdrive("c:\\foo\\bar")',
|
tester('ntpath.splitdrive("c:\\foo\\bar")',
|
||||||
|
|
@ -50,7 +50,23 @@ tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
|
||||||
tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
|
tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
|
||||||
"/home/swen/spam")
|
"/home/swen/spam")
|
||||||
|
|
||||||
|
tester('ntpath.join("")', '')
|
||||||
|
tester('ntpath.join("", "", "")', '')
|
||||||
|
tester('ntpath.join("a")', 'a')
|
||||||
|
tester('ntpath.join("/a")', '/a')
|
||||||
|
tester('ntpath.join("\\a")', '\\a')
|
||||||
|
tester('ntpath.join("a:")', 'a:')
|
||||||
|
tester('ntpath.join("a:", "b")', 'a:b')
|
||||||
|
tester('ntpath.join("a:", "/b")', 'a:/b')
|
||||||
|
tester('ntpath.join("a:", "\\b")', 'a:\\b')
|
||||||
|
tester('ntpath.join("a", "/b")', '/b')
|
||||||
|
tester('ntpath.join("a", "\\b")', '\\b')
|
||||||
|
tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
|
||||||
|
tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
|
||||||
|
tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
|
||||||
|
tester('ntpath.join("a", "b", "\\c")', '\\c')
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
print str(errors) + " errors."
|
raise TestFailed(str(errors) + " errors.")
|
||||||
elif verbose:
|
elif verbose:
|
||||||
print "No errors. Thank your lucky stars."
|
print "No errors. Thank your lucky stars."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue