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_USERSTRING.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.2 KB  |  46 lines

  1. #!/usr/bin/env python
  2. import sys, string
  3. from test_support import verbose
  4. import string_tests
  5. # UserString is a wrapper around the native builtin string type.
  6. # UserString instances should behave similar to builtin string objects.
  7. # The test cases were in part derived from 'test_string.py'.
  8. from UserString import UserString
  9.  
  10. if __name__ == "__main__":
  11.     verbose = 0
  12.  
  13. tested_methods = {}
  14.  
  15. def test(methodname, input, *args):
  16.     global tested_methods
  17.     tested_methods[methodname] = 1
  18.     if verbose:
  19.         print '%s.%s(%s) ' % (input, methodname, args),
  20.     u = UserString(input)
  21.     objects = [input, u, UserString(u)]
  22.     res = [""] * 3
  23.     for i in range(3):
  24.         object = objects[i]
  25.         try:
  26.             f = getattr(object, methodname)
  27.             res[i] = apply(f, args)
  28.         except:
  29.             res[i] = sys.exc_type
  30.     if res[0] != res[1]:
  31.         if verbose:
  32.             print 'no'
  33.         print `input`, f, `res[0]`, "<>", `res[1]`
  34.     else:
  35.         if verbose:
  36.             print 'yes'
  37.     if res[1] != res[2]:
  38.         if verbose:
  39.             print 'no'
  40.         print `input`, f, `res[1]`, "<>", `res[2]`
  41.     else:
  42.         if verbose:
  43.             print 'yes'
  44.  
  45. string_tests.run_method_tests(test)
  46.