Kaydet (Commit) d4f7f609 authored tarafından Tim Peters's avatar Tim Peters

Add some test cases for ntpath.join().

üst 3b5e4d1e
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): ...@@ -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"])', ...@@ -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."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment