home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / TEST_STRING.PY < prev    next >
Encoding:
Python Source  |  2001-12-09  |  994 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.         f = name
  25.     if value != output:
  26.         if verbose:
  27.             print 'no'
  28.         print f, `input`, `output`, `value`
  29.     else:
  30.         if verbose:
  31.             print 'yes'
  32.  
  33. string_tests.run_module_tests(test)
  34. string_tests.run_method_tests(test)
  35.  
  36. string.whitespace
  37. string.lowercase
  38. string.uppercase
  39.