annotate Lib/test/test_strop.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 9eff7880e684
children 83147e02e80d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
1 from test_support import verbose
4366
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 import strop, sys
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
4630
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
4 def test(name, input, output, *args):
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
5 if verbose:
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
6 print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
4366
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 f = getattr(strop, name)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 try:
4630
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
9 value = apply(f, (input,) + args)
4366
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 except:
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 value = sys.exc_type
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 if value != output:
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
13 if verbose:
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
14 print 'no'
4366
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 print f, `input`, `output`, `value`
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
16 else:
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
17 if verbose:
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
18 print 'yes'
4366
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 test('atoi', " 1 ", 1)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 test('atoi', " 1x", ValueError)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 test('atoi', " x1 ", ValueError)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 test('atol', " 1 ", 1L)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 test('atol', " 1x ", ValueError)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 test('atol', " x1 ", ValueError)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 test('atof', " 1 ", 1.0)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 test('atof', " 1x ", ValueError)
3eb74df672a3 Simple test module for strop.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 test('atof', " x1 ", ValueError)
4630
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
29
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
30 test('capitalize', ' hello ', ' hello ')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
31 test('capitalize', 'hello ', 'Hello ')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
32 test('find', 'abcdefghiabc', 0, 'abc')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
33 test('find', 'abcdefghiabc', 9, 'abc', 1)
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
34 test('find', 'abcdefghiabc', -1, 'def', 4)
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
35 test('rfind', 'abcdefghiabc', 9, 'abc')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
36 test('lower', 'HeLLo', 'hello')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
37 test('upper', 'HeLLo', 'HELLO')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
38
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
39 transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
40
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
41 test('maketrans', 'abc', transtable, 'xyz')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
42 test('maketrans', 'abc', ValueError, 'xyzq')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
43
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
44 test('split', 'this is the split function',
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
45 ['this', 'is', 'the', 'split', 'function'])
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
46 test('split', 'a|b|c|d', ['a', 'b', 'c', 'd'], '|')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
47 test('split', 'a|b|c|d', ['a', 'b', 'c|d'], '|', 2)
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
48
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
49 # join now works with any sequence type
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
50 class Sequence:
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
51 def __init__(self): self.seq = 'wxyz'
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
52 def __len__(self): return len(self.seq)
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
53 def __getitem__(self, i): return self.seq[i]
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
54
4630
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
55 test('join', ['a', 'b', 'c', 'd'], 'a b c d')
4899
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
56 test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
57 test('join', Sequence(), 'w x y z')
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
58
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
59 # try a few long ones
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
60 print strop.join(['x' * 100] * 100, ':')
9eff7880e684 Added a couple of strop.join() tests for large lists and long items
Barry Warsaw <barry@python.org>
parents: 4630
diff changeset
61 print strop.join(('x' * 100,) * 100, ':')
4630
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
62
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
63 test('strip', ' hello ', 'hello')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
64 test('lstrip', ' hello ', 'hello ')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
65 test('rstrip', ' hello ', ' hello')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
66
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
67 test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
68 test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
69
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
70 strop.whitespace
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
71 strop.lowercase
045ed830c035 Added tests of all strop module functions, and touching of module
Barry Warsaw <barry@python.org>
parents: 4367
diff changeset
72 strop.uppercase