Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Lib / test / test_operator.py
blobb75c5ba78f72f55fc217fa77042885b3e9e38055
1 import operator
2 import sys
4 def test(name, input, output, *args):
5 print 'testing:', name
6 f = getattr(operator, name)
7 params = (input,) + args
8 try:
9 val = apply(f, params)
10 except:
11 val = sys.exc_type
12 if val != output:
13 print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
15 test('abs', -1, 1)
16 test('add', 3, 7, 4)
17 test('and_', 0xf, 0xa, 0xa)
18 test('concat', 'py', 'python', 'thon')
20 test('countOf', [1, 2, 1, 3, 1, 4], 1, 3)
22 a = [4, 3, 2, 1]
23 test('delitem', a, None, 1)
24 if a != [4, 2, 1]:
25 print 'delitem() failed'
27 a = range(10)
28 test('delslice', a, None, 2, 8)
29 if a != [0, 1, 8, 9]:
30 print 'delslice() failed'
32 a = range(10)
33 test('div', 5, 2, 2)
34 test('getitem', a, 2, 2)
35 test('getslice', a, [4, 5], 4, 6)
36 test('indexOf', [4, 3, 2, 1], 1, 3)
37 test('inv', 4, -5)
38 test('isCallable', 4, 0)
39 test('isCallable', operator.isCallable, 1)
40 test('isMappingType', operator.isMappingType, 0)
41 test('isMappingType', operator.__dict__, 1)
42 test('isNumberType', 8.3, 1)
43 test('isNumberType', dir(), 0)
44 test('isSequenceType', dir(), 1)
45 test('isSequenceType', 'yeahbuddy', 1)
46 test('isSequenceType', 3, 0)
47 test('lshift', 5, 10, 1)
48 test('mod', 5, 1, 2)
49 test('mul', 5, 10, 2)
50 test('neg', 5, -5)
51 test('or_', 0xa, 0xf, 0x5)
52 test('pos', -5, -5)
54 a = range(3)
55 test('repeat', a, a+a, 2)
56 test('rshift', 5, 2, 1)
58 test('sequenceIncludes', range(4), 1, 2)
59 test('sequenceIncludes', range(4), 0, 5)
61 test('setitem', a, None, 0, 2)
62 if a != [2, 1, 2]:
63 print 'setitem() failed'
65 a = range(4)
66 test('setslice', a, None, 1, 3, [2, 1])
67 if a != [0, 2, 1, 3]:
68 print 'setslice() failed:', a
70 test('sub', 5, 2, 3)
71 test('truth', 5, 1)
72 test('truth', [], 0)
73 test('xor', 0xb, 0x7, 0xc)
76 # some negative tests
77 test('indexOf', [4, 3, 2, 1], ValueError, 9)