Thomas Wouters | b9fa0a8 | 2000-08-04 13:34:43 +0000 | [diff] [blame] | 1 | from test_support import verbose, TestSkipped |
Jeremy Hylton | f82b04e | 2000-07-10 17:08:42 +0000 | [diff] [blame] | 2 | import string_tests |
Barry Warsaw | 50f0e16 | 1999-06-10 22:53:10 +0000 | [diff] [blame] | 3 | import string, sys |
| 4 | |
Barry Warsaw | 6e1d78a | 1999-06-15 16:49:11 +0000 | [diff] [blame] | 5 | # XXX: kludge... short circuit if strings don't have methods |
| 6 | try: |
| 7 | ''.join |
| 8 | except AttributeError: |
Thomas Wouters | b9fa0a8 | 2000-08-04 13:34:43 +0000 | [diff] [blame] | 9 | raise TestSkipped |
Barry Warsaw | 6e1d78a | 1999-06-15 16:49:11 +0000 | [diff] [blame] | 10 | |
Barry Warsaw | 50f0e16 | 1999-06-10 22:53:10 +0000 | [diff] [blame] | 11 | def test(name, input, output, *args): |
| 12 | if verbose: |
| 13 | print 'string.%s%s =? %s... ' % (name, (input,) + args, output), |
Barry Warsaw | 50f0e16 | 1999-06-10 22:53:10 +0000 | [diff] [blame] | 14 | try: |
Guido van Rossum | a831cac | 2000-03-10 23:23:21 +0000 | [diff] [blame] | 15 | # Prefer string methods over string module functions |
Barry Warsaw | 8a9514a | 1999-06-11 17:48:07 +0000 | [diff] [blame] | 16 | try: |
Barry Warsaw | 8a9514a | 1999-06-11 17:48:07 +0000 | [diff] [blame] | 17 | f = getattr(input, name) |
| 18 | value = apply(f, args) |
Guido van Rossum | a831cac | 2000-03-10 23:23:21 +0000 | [diff] [blame] | 19 | except AttributeError: |
| 20 | f = getattr(string, name) |
| 21 | value = apply(f, (input,) + args) |
Barry Warsaw | 50f0e16 | 1999-06-10 22:53:10 +0000 | [diff] [blame] | 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 | |
Jeremy Hylton | f82b04e | 2000-07-10 17:08:42 +0000 | [diff] [blame] | 32 | string_tests.run_module_tests(test) |
| 33 | string_tests.run_method_tests(test) |
Barry Warsaw | 50f0e16 | 1999-06-10 22:53:10 +0000 | [diff] [blame] | 34 | |
| 35 | string.whitespace |
| 36 | string.lowercase |
| 37 | string.uppercase |
Jeremy Hylton | f82b04e | 2000-07-10 17:08:42 +0000 | [diff] [blame] | 38 | |