Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_operator.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | e3184e46303b |
| children | aa0d2d51fbde |
| rev | line source |
|---|---|
| 4777 | 1 import operator |
|
19163
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
2 import unittest |
| 4777 | 3 |
|
19163
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
4 import test_support |
| 4777 | 5 |
| 6 | |
|
19163
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
7 class OperatorTestCase(unittest.TestCase): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
8 def test_lt(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
9 self.failIf(operator.lt(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
10 self.failIf(operator.lt(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
11 self.failIf(operator.lt(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
12 self.failIf(operator.lt(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
13 self.failUnless(operator.lt(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
14 self.failUnless(operator.lt(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
15 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
16 def test_le(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
17 self.failIf(operator.le(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
18 self.failIf(operator.le(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
19 self.failUnless(operator.le(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
20 self.failUnless(operator.le(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
21 self.failUnless(operator.le(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
22 self.failUnless(operator.le(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
23 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
24 def test_eq(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
25 self.failIf(operator.eq(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
26 self.failIf(operator.eq(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
27 self.failUnless(operator.eq(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
28 self.failUnless(operator.eq(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
29 self.failIf(operator.eq(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
30 self.failIf(operator.eq(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
31 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
32 def test_ne(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
33 self.failUnless(operator.ne(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
34 self.failUnless(operator.ne(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
35 self.failIf(operator.ne(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
36 self.failIf(operator.ne(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
37 self.failUnless(operator.ne(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
38 self.failUnless(operator.ne(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
39 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
40 def test_ge(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
41 self.failUnless(operator.ge(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
42 self.failUnless(operator.ge(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
43 self.failUnless(operator.ge(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
44 self.failUnless(operator.ge(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
45 self.failIf(operator.ge(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
46 self.failIf(operator.ge(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
47 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
48 def test_gt(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
49 self.failUnless(operator.gt(1, 0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
50 self.failUnless(operator.gt(1, 0.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
51 self.failIf(operator.gt(1, 1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
52 self.failIf(operator.gt(1, 1.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
53 self.failIf(operator.gt(1, 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
54 self.failIf(operator.gt(1, 2.0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
55 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
56 def test_abs(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
57 self.failUnless(operator.abs(-1) == 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
58 self.failUnless(operator.abs(1) == 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
59 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
60 def test_add(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
61 self.failUnless(operator.add(3, 4) == 7) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
62 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
63 def test_bitwise_and(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
64 self.failUnless(operator.and_(0xf, 0xa) == 0xa) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
65 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
66 def test_concat(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
67 self.failUnless(operator.concat('py', 'thon') == 'python') |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
68 self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
69 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
70 def test_countOf(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
71 self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 3) == 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
72 self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 5) == 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
73 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
74 def test_delitem(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
75 a = [4, 3, 2, 1] |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
76 self.failUnless(operator.delitem(a, 1) is None) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
77 self.assert_(a == [4, 2, 1]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
78 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
79 def test_delslice(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
80 a = range(10) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
81 self.failUnless(operator.delslice(a, 2, 8) is None) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
82 self.assert_(a == [0, 1, 8, 9]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
83 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
84 def test_div(self): |
|
19694
3716b116fb31
The first batch of changes recommended by the fixdiv tool. These are
Guido van Rossum <guido@python.org>
parents:
19163
diff
changeset
|
85 self.failUnless(operator.floordiv(5, 2) == 2) |
|
19163
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
86 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
87 def test_floordiv(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
88 self.failUnless(operator.floordiv(5, 2) == 2) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
89 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
90 def test_truediv(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
91 self.failUnless(operator.truediv(5, 2) == 2.5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
92 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
93 def test_getitem(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
94 a = range(10) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
95 self.failUnless(operator.getitem(a, 2) == 2) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
96 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
97 def test_getslice(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
98 a = range(10) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
99 self.failUnless(operator.getslice(a, 4, 6) == [4, 5]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
100 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
101 def test_indexOf(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
102 self.failUnless(operator.indexOf([4, 3, 2, 1], 3) == 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
103 self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
104 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
105 def test_invert(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
106 self.failUnless(operator.inv(4) == -5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
107 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
108 def test_isCallable(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
109 class C: |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
110 pass |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
111 def check(self, o, v): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
112 self.assert_(operator.isCallable(o) == callable(o) == v) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
113 check(self, 4, 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
114 check(self, operator.isCallable, 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
115 check(self, C, 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
116 check(self, C(), 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
117 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
118 def test_isMappingType(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
119 self.failIf(operator.isMappingType(1)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
120 self.failIf(operator.isMappingType(operator.isMappingType)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
121 self.failUnless(operator.isMappingType(operator.__dict__)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
122 self.failUnless(operator.isMappingType({})) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
123 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
124 def test_isNumberType(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
125 self.failUnless(operator.isNumberType(8)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
126 self.failUnless(operator.isNumberType(8j)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
127 self.failUnless(operator.isNumberType(8L)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
128 self.failUnless(operator.isNumberType(8.3)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
129 self.failIf(operator.isNumberType(dir())) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
130 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
131 def test_isSequenceType(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
132 self.failUnless(operator.isSequenceType(dir())) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
133 self.failUnless(operator.isSequenceType(())) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
134 self.failUnless(operator.isSequenceType(xrange(10))) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
135 self.failUnless(operator.isSequenceType('yeahbuddy')) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
136 self.failIf(operator.isSequenceType(3)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
137 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
138 def test_lshift(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
139 self.failUnless(operator.lshift(5, 1) == 10) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
140 self.failUnless(operator.lshift(5, 0) == 5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
141 self.assertRaises(ValueError, operator.lshift, 2, -1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
142 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
143 def test_mod(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
144 self.failUnless(operator.mod(5, 2) == 1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
145 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
146 def test_mul(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
147 self.failUnless(operator.mul(5, 2) == 10) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
148 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
149 def test_neg(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
150 self.failUnless(operator.neg(5) == -5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
151 self.failUnless(operator.neg(-5) == 5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
152 self.failUnless(operator.neg(0) == 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
153 self.failUnless(operator.neg(-0) == 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
154 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
155 def test_bitwise_or(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
156 self.failUnless(operator.or_(0xa, 0x5) == 0xf) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
157 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
158 def test_pos(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
159 self.failUnless(operator.pos(5) == 5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
160 self.failUnless(operator.pos(-5) == -5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
161 self.failUnless(operator.pos(0) == 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
162 self.failUnless(operator.pos(-0) == 0) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
163 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
164 def test_repeat(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
165 a = range(3) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
166 self.failUnless(operator.repeat(a, 2) == a+a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
167 self.failUnless(operator.repeat(a, 1) == a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
168 self.failUnless(operator.repeat(a, 0) == []) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
169 a = (1, 2, 3) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
170 self.failUnless(operator.repeat(a, 2) == a+a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
171 self.failUnless(operator.repeat(a, 1) == a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
172 self.failUnless(operator.repeat(a, 0) == ()) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
173 a = '123' |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
174 self.failUnless(operator.repeat(a, 2) == a+a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
175 self.failUnless(operator.repeat(a, 1) == a) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
176 self.failUnless(operator.repeat(a, 0) == '') |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
177 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
178 def test_rshift(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
179 self.failUnless(operator.rshift(5, 1) == 2) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
180 self.failUnless(operator.rshift(5, 0) == 5) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
181 self.assertRaises(ValueError, operator.rshift, 2, -1) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
182 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
183 def test_contains(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
184 self.failUnless(operator.contains(range(4), 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
185 self.failIf(operator.contains(range(4), 5)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
186 self.failUnless(operator.sequenceIncludes(range(4), 2)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
187 self.failIf(operator.sequenceIncludes(range(4), 5)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
188 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
189 def test_setitem(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
190 a = range(3) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
191 self.failUnless(operator.setitem(a, 0, 2) is None) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
192 self.assert_(a == [2, 1, 2]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
193 self.assertRaises(IndexError, operator.setitem, a, 4, 2) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
194 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
195 def test_setslice(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
196 a = range(4) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
197 self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
198 self.assert_(a == [0, 2, 1, 3]) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
199 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
200 def test_sub(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
201 self.failUnless(operator.sub(5, 2) == 3) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
202 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
203 def test_truth(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
204 self.failUnless(operator.truth(5)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
205 self.failUnless(operator.truth([0])) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
206 self.failIf(operator.truth(0)) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
207 self.failIf(operator.truth([])) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
208 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
209 def test_bitwise_xor(self): |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
210 self.failUnless(operator.xor(0xb, 0xc) == 0x7) |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
211 |
|
b160fa63f40c
Added tests for rich comparison operator functions.
Fred Drake <fdrake@acm.org>
parents:
19112
diff
changeset
|
212 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
213 def test_main(): |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
214 test_support.run_unittest(OperatorTestCase) |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
215 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
216 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
217 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19694
diff
changeset
|
218 test_main() |
