annotate Lib/test/test_string.py @ 22360:c8a6ea00a9e1 legacy-trunk

restructure a bit to not rely on test case execution ordering add test case for bug #482460
author Skip Montanaro <skip@pobox.com>
date Sun, 17 Mar 2002 23:03:42 +0000
parents bb566f525f12
children 7121d7d572d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15966
e59b835ad89a a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents: 15957
diff changeset
1 from test_support import verbose, TestSkipped
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13353
diff changeset
2 import string_tests
10969
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
3 import string, sys
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
4
10987
e39a9f129163 Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents: 10981
diff changeset
5 # XXX: kludge... short circuit if strings don't have methods
e39a9f129163 Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents: 10981
diff changeset
6 try:
e39a9f129163 Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents: 10981
diff changeset
7 ''.join
e39a9f129163 Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents: 10981
diff changeset
8 except AttributeError:
13858
99f0413ef795 Raise 'TestSkipped' (from the test_support) module rather than 'ImportError'
Thomas Wouters <thomas@python.org>
parents: 13517
diff changeset
9 raise TestSkipped
10987
e39a9f129163 Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents: 10981
diff changeset
10
10969
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
11 def test(name, input, output, *args):
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
12 if verbose:
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
13 print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
14 try:
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents: 10987
diff changeset
15 # Prefer string methods over string module functions
10974
51969fd73c4a Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents: 10969
diff changeset
16 try:
11992
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents: 10987
diff changeset
17 f = getattr(input, name)
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents: 10987
diff changeset
18 value = apply(f, args)
1789fae5f074 Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents: 10987
diff changeset
19 except AttributeError:
10974
51969fd73c4a Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents: 10969
diff changeset
20 f = getattr(string, name)
51969fd73c4a Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents: 10969
diff changeset
21 value = apply(f, (input,) + args)
10969
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
22 except:
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 13858
diff changeset
23 value = sys.exc_type
21318
bb566f525f12 test(): Avoid a UnboundLocalError when a method is missing from both the string
Finn Bock <bckfnn@worldonline.dk>
parents: 15966
diff changeset
24 f = name
10969
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
25 if value != output:
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
26 if verbose:
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
27 print 'no'
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
28 print f, `input`, `output`, `value`
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
29 else:
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
30 if verbose:
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
31 print 'yes'
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
32
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13353
diff changeset
33 string_tests.run_module_tests(test)
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13353
diff changeset
34 string_tests.run_method_tests(test)
10969
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
35
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
36 string.whitespace
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
37 string.lowercase
e1407d6320cb Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff changeset
38 string.uppercase