4 def test(name
, input, output
, *args
):
6 f
= getattr(operator
, name
)
7 params
= (input,) + args
13 print '%s%s = %s: %s expected' % (f
.__name
__, params
, `val`
, `output`
)
17 test('and_', 0xf, 0xa, 0xa)
18 test('concat', 'py', 'python', 'thon')
20 test('countOf', [1, 2, 1, 3, 1, 4], 1, 3)
23 test('delitem', a
, None, 1)
25 print 'delitem() failed'
28 test('delslice', a
, None, 2, 8)
30 print 'delslice() failed'
34 test('getitem', a
, 2, 2)
35 test('getslice', a
, [4, 5], 4, 6)
36 test('indexOf', [4, 3, 2, 1], 1, 3)
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)
51 test('or_', 0xa, 0xf, 0x5)
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)
63 print 'setitem() failed'
66 test('setslice', a
, None, 1, 3, [2, 1])
68 print 'setslice() failed:', a
73 test('xor', 0xb, 0x7, 0xc)
77 test('indexOf', [4, 3, 2, 1], ValueError, 9)