Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 1 | import posixpath |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 2 | |
| 3 | errors = 0 |
| 4 | |
| 5 | def tester(fn, wantResult): |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 6 | gotResult = eval(fn) |
| 7 | if wantResult != gotResult: |
| 8 | print "error!" |
| 9 | print "evaluated: " + str(fn) |
| 10 | print "should be: " + str(wantResult) |
| 11 | print " returned: " + str(gotResult) |
| 12 | print "" |
| 13 | global errors |
| 14 | errors = errors + 1 |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 15 | |
| 16 | tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar')) |
| 17 | |
| 18 | tester('posixpath.split("/foo/bar")', ('/foo', 'bar')) |
| 19 | tester('posixpath.split("/")', ('/', '')) |
| 20 | tester('posixpath.split("foo")', ('', 'foo')) |
| 21 | |
| 22 | tester('posixpath.splitext("foo.ext")', ('foo', '.ext')) |
| 23 | tester('posixpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext')) |
Martin v. Löwis | de33379 | 2002-12-12 20:30:20 +0000 | [diff] [blame^] | 24 | tester('posixpath.splitext(".ext")', ('', '.ext')) |
| 25 | tester('posixpath.splitext("/foo.ext/foo")', ('/foo.ext/foo', '')) |
| 26 | tester('posixpath.splitext("foo.ext/")', ('foo.ext/', '')) |
| 27 | tester('posixpath.splitext("")', ('', '')) |
| 28 | tester('posixpath.splitext("foo.bar.ext")', ('foo.bar', '.ext')) |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 29 | |
| 30 | tester('posixpath.isabs("/")', 1) |
| 31 | tester('posixpath.isabs("/foo")', 1) |
| 32 | tester('posixpath.isabs("/foo/bar")', 1) |
| 33 | tester('posixpath.isabs("foo/bar")', 0) |
| 34 | |
| 35 | tester('posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])', |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 36 | "/home/swen") |
Skip Montanaro | 533bc9a | 2000-08-23 16:51:56 +0000 | [diff] [blame] | 37 | tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"])', |
| 38 | "/home/swen/") |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 39 | tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', |
| 40 | "/home/swen/spam") |
| 41 | |
| 42 | if errors: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 43 | print str(errors) + " errors." |
Skip Montanaro | e809b00 | 2000-07-12 00:20:08 +0000 | [diff] [blame] | 44 | else: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 45 | print "No errors. Thank your lucky stars." |