home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_NTPATH.PY < prev    next >
Encoding:
Text File  |  2000-09-28  |  1.7 KB  |  52 lines

  1. import ntpath
  2. import string
  3. import os
  4.  
  5. errors = 0
  6.  
  7. def tester(fn, wantResult):
  8.     fn = string.replace(fn, "\\", "\\\\")
  9.     gotResult = eval(fn)
  10.     if wantResult != gotResult:
  11.         print "error!"
  12.         print "evaluated: " + str(fn)
  13.         print "should be: " + str(wantResult)
  14.         print " returned: " + str(gotResult)
  15.         print ""
  16.         global errors
  17.         errors = errors + 1
  18.  
  19. tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
  20. tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\foo\\bar'))
  21. tester('ntpath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar'))
  22. tester('ntpath.splitunc("//conky/mountpoint/foo/bar")', ('//conky/mountpoint', '/foo/bar'))
  23.  
  24. tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
  25. tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar'))
  26.  
  27. tester('ntpath.split("c:\\")', ('c:\\', ''))
  28. tester('ntpath.split("\\\\conky\\mountpoint\\")', ('\\\\conky\\mountpoint', ''))
  29.  
  30. tester('ntpath.split("c:/")', ('c:/', ''))
  31. tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
  32.  
  33. tester('ntpath.isabs("c:\\")', 1)
  34. tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
  35. tester('ntpath.isabs("\\foo")', 1)
  36. tester('ntpath.isabs("\\foo\\bar")', 1)
  37.  
  38. tester('ntpath.abspath("C:\\")', "C:\\")
  39.  
  40. tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
  41.        "/home/swen")
  42. tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
  43.        "\\home\\swen\\")
  44. tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
  45.        "/home/swen/spam")
  46.  
  47. if errors:
  48.     print str(errors) + " errors."
  49. else:
  50.     print "No errors.  Thank your lucky stars."
  51.  
  52.