home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Lib / Python2.0 / test / test_posixpath.py < prev    next >
Encoding:
Python Source  |  2000-10-29  |  2.0 KB  |  67 lines

  1. import posixpath
  2. import string
  3. import sys
  4.  
  5. errors = 0
  6.  
  7. def tester(fn, wantResult):
  8.     gotResult = eval(fn)
  9.     if wantResult != gotResult:
  10.         print "error!"
  11.         print "evaluated: " + str(fn)
  12.         print "should be: " + str(wantResult)
  13.         print " returned: " + str(gotResult)
  14.         print ""
  15.         global errors
  16.         errors = errors + 1
  17.  
  18. if sys.platform=='amiga':
  19.     tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar'))
  20.  
  21.     tester('posixpath.split("/foo/bar")', ('/foo', 'bar'))
  22.     tester('posixpath.split("/")', ('', ''))
  23.     tester('posixpath.split("foo")', ('', 'foo'))
  24.  
  25.     tester('posixpath.splitext("foo.ext")', ('foo', '.ext'))
  26.     tester('posixpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
  27.  
  28.     tester('posixpath.isabs(":")', 1)
  29.     tester('posixpath.isabs(":foo")', 1)
  30.     tester('posixpath.isabs(":foo/bar")', 1)
  31.     tester('posixpath.isabs("foo:bar")', 1)
  32.     tester('posixpath.isabs("foo/bar")', 0)
  33.  
  34.     tester('posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
  35.            "/home/swen")
  36.     tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"])',
  37.            "/home/swen/")
  38.     tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
  39.            "/home/swen/spam")
  40. else:
  41.     tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar'))
  42.  
  43.     tester('posixpath.split("/foo/bar")', ('/foo', 'bar'))
  44.     tester('posixpath.split("/")', ('/', ''))
  45.     tester('posixpath.split("foo")', ('', 'foo'))
  46.  
  47.     tester('posixpath.splitext("foo.ext")', ('foo', '.ext'))
  48.     tester('posixpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
  49.  
  50.     tester('posixpath.isabs("/")', 1)
  51.     tester('posixpath.isabs("/foo")', 1)
  52.     tester('posixpath.isabs("/foo/bar")', 1)
  53.     tester('posixpath.isabs("foo/bar")', 0)
  54.  
  55.     tester('posixpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
  56.            "/home/swen")
  57.     tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/eggs"])',
  58.            "/home/swen/")
  59.     tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
  60.            "/home/swen/spam")
  61.  
  62. if errors:
  63.     print str(errors) + " errors."
  64. else:
  65.     print "No errors.  Thank your lucky stars."
  66.  
  67.