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_STRING.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  979 b   |  39 lines

  1. from test_support import verbose, TestSkipped
  2. import string_tests
  3. import string, sys
  4.  
  5. # XXX: kludge... short circuit if strings don't have methods
  6. try:
  7.     ''.join
  8. except AttributeError:
  9.     raise TestSkipped
  10.  
  11. def test(name, input, output, *args):
  12.     if verbose:
  13.         print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
  14.     try:
  15.         # Prefer string methods over string module functions
  16.         try:
  17.             f = getattr(input, name)
  18.             value = apply(f, args)
  19.         except AttributeError:
  20.             f = getattr(string, name)
  21.             value = apply(f, (input,) + args)
  22.     except:
  23.          value = sys.exc_type
  24.     if value != output:
  25.         if verbose:
  26.             print 'no'
  27.         print f, `input`, `output`, `value`
  28.     else:
  29.         if verbose:
  30.             print 'yes'
  31.  
  32. string_tests.run_module_tests(test)
  33. string_tests.run_method_tests(test)
  34.  
  35. string.whitespace
  36. string.lowercase
  37. string.uppercase
  38.  
  39.