Lines Matching refs:self
12 def __repr__(self):
16 def __init__(self, arg):
17 self.arg = arg
19 def __repr__(self):
20 return '<Cmp %s>' % self.arg
22 def __eq__(self, other):
23 return self.arg == other
29 def test_comparisons(self):
30 for a in self.candidates:
31 for b in self.candidates:
32 if ((a in self.set1) and (b in self.set1)) or a is b:
33 self.assertEqual(a, b)
35 self.assertNotEqual(a, b)
37 def test_id_comparisons(self):
41 L.insert(len(L)//2, self.Empty())
44 self.assertEqual(a == b, a is b, 'a=%r, b=%r' % (a, b))
46 def test_ne_defaults_to_not_eq(self):
47 a = self.Cmp(1)
48 b = self.Cmp(1)
49 c = self.Cmp(2)
50 self.assertIs(a == b, True)
51 self.assertIs(a != b, False)
52 self.assertIs(a != c, True)
54 def test_ne_high_priority(self):
70 self.assertSequenceEqual(calls, ['Left.__eq__', 'Right.__ne__'])
72 def test_ne_low_priority(self):
88 self.assertSequenceEqual(calls, ['Derived.__ne__', 'Base.__eq__'])
90 def test_other_delegation(self):
100 with self.subTest(name):
102 self.fail('Unexpected operator method called')
109 self.assertIs(func(C(), object()), False)
111 self.assertRaises(TypeError, func, C(), object())
113 def test_issue_1393(self):
115 self.assertEqual(x, ALWAYS_EQ)
116 self.assertEqual(ALWAYS_EQ, x)
118 self.assertEqual(y, ALWAYS_EQ)
119 self.assertEqual(ALWAYS_EQ, y)
144 def __eq__(self, other):
145 return self.x == other.x
149 def __ne__(self, other):
150 return self.x != other.x
154 def __eq__(self, other):
155 return self.x == other.x
156 def __ne__(self, other):
157 return self.x != other.x
163 def __lt__(self, other):
164 return self.x < other.x
168 def __gt__(self, other):
169 return self.x > other.x
173 def __lt__(self, other):
174 return self.x < other.x
175 def __gt__(self, other):
176 return self.x > other.x
182 def __le__(self, other):
183 return self.x <= other.x
187 def __ge__(self, other):
188 return self.x >= other.x
192 def __le__(self, other):
193 return self.x <= other.x
194 def __ge__(self, other):
195 return self.x >= other.x
205 def create_sorted_instances(self, class_, values):
224 def assert_equality_only(self, a, b, equal):
230 self.assertEqual(a == b, equal)
231 self.assertEqual(b == a, equal)
232 self.assertEqual(a != b, not equal)
233 self.assertEqual(b != a, not equal)
234 with self.assertRaisesRegex(TypeError, "not supported"):
236 with self.assertRaisesRegex(TypeError, "not supported"):
238 with self.assertRaisesRegex(TypeError, "not supported"):
240 with self.assertRaisesRegex(TypeError, "not supported"):
242 with self.assertRaisesRegex(TypeError, "not supported"):
244 with self.assertRaisesRegex(TypeError, "not supported"):
246 with self.assertRaisesRegex(TypeError, "not supported"):
248 with self.assertRaisesRegex(TypeError, "not supported"):
251 def assert_total_order(self, a, b, comp, a_meth=None, b_meth=None):
265 self.assert_eq_subtest(a, b, comp, a_meth, b_meth)
266 self.assert_ne_subtest(a, b, comp, a_meth, b_meth)
267 self.assert_lt_subtest(a, b, comp, a_meth, b_meth)
268 self.assert_le_subtest(a, b, comp, a_meth, b_meth)
269 self.assert_gt_subtest(a, b, comp, a_meth, b_meth)
270 self.assert_ge_subtest(a, b, comp, a_meth, b_meth)
279 def assert_eq_subtest(self, a, b, comp, a_meth, b_meth):
281 self.assertEqual(a == b, comp == 0)
282 self.assertEqual(b == a, comp == 0)
284 self.assertEqual(a == b, a is b)
285 self.assertEqual(b == a, a is b)
287 def assert_ne_subtest(self, a, b, comp, a_meth, b_meth):
289 self.assertEqual(a != b, comp != 0)
290 self.assertEqual(b != a, comp != 0)
292 self.assertEqual(a != b, a is not b)
293 self.assertEqual(b != a, a is not b)
295 def assert_lt_subtest(self, a, b, comp, a_meth, b_meth):
297 self.assertEqual(a < b, comp < 0)
298 self.assertEqual(b > a, comp < 0)
300 with self.assertRaisesRegex(TypeError, "not supported"):
302 with self.assertRaisesRegex(TypeError, "not supported"):
305 def assert_le_subtest(self, a, b, comp, a_meth, b_meth):
307 self.assertEqual(a <= b, comp <= 0)
308 self.assertEqual(b >= a, comp <= 0)
310 with self.assertRaisesRegex(TypeError, "not supported"):
312 with self.assertRaisesRegex(TypeError, "not supported"):
315 def assert_gt_subtest(self, a, b, comp, a_meth, b_meth):
317 self.assertEqual(a > b, comp > 0)
318 self.assertEqual(b < a, comp > 0)
320 with self.assertRaisesRegex(TypeError, "not supported"):
322 with self.assertRaisesRegex(TypeError, "not supported"):
325 def assert_ge_subtest(self, a, b, comp, a_meth, b_meth):
327 self.assertEqual(a >= b, comp >= 0)
328 self.assertEqual(b <= a, comp >= 0)
330 with self.assertRaisesRegex(TypeError, "not supported"):
332 with self.assertRaisesRegex(TypeError, "not supported"):
335 def test_objects(self):
339 self.assert_equality_only(a, a, True)
340 self.assert_equality_only(a, b, False)
342 def test_comp_classes_same(self):
345 for cls in self.all_comp_classes:
346 with self.subTest(cls):
347 instances = self.create_sorted_instances(cls, (1, 2, 1))
350 self.assert_total_order(instances[0], instances[0], 0,
354 self.assert_total_order(instances[0], instances[2], 0,
358 self.assert_total_order(instances[0], instances[1], -1,
364 self.assert_total_order(instances[1], instances[2], +1,
367 def test_comp_classes_different(self):
370 for cls_a in self.all_comp_classes:
371 for cls_b in self.all_comp_classes:
372 with self.subTest(a=cls_a, b=cls_b):
380 self.assert_total_order(
382 self.assert_total_order(
385 def test_str_subclass(self):
396 self.assert_total_order(s1, s1, 0)
397 self.assert_total_order(s1, s2, -1)
398 self.assert_total_order(c1, c1, 0)
399 self.assert_total_order(c1, c2, -1)
400 self.assert_total_order(c2, c3, 0)
402 self.assert_total_order(s1, c2, -1)
403 self.assert_total_order(s2, c3, 0)
404 self.assert_total_order(c1, s2, -1)
405 self.assert_total_order(c2, s2, 0)
407 def test_numbers(self):
413 self.assert_total_order(i1, i1, 0)
414 self.assert_total_order(i1, i2, -1)
418 self.assert_total_order(f1, f1, 0)
419 self.assert_total_order(f1, f2, -1)
423 self.assert_total_order(q1, q1, 0)
424 self.assert_total_order(q1, q2, -1)
428 self.assert_total_order(d1, d1, 0)
429 self.assert_total_order(d1, d2, -1)
433 self.assert_equality_only(c1, c1, True)
434 self.assert_equality_only(c1, c2, False)
439 self.assert_total_order(n1, n2, 0)
441 self.assert_equality_only(n1, c1, True)
443 def test_sequences(self):
447 self.assert_total_order(l1, l1, 0)
448 self.assert_total_order(l1, l2, -1)
452 self.assert_total_order(t1, t1, 0)
453 self.assert_total_order(t1, t2, -1)
457 self.assert_equality_only(r1, r1, True)
458 self.assert_equality_only(r1, r2, False)
460 self.assert_equality_only(t1, l1, False)
461 self.assert_equality_only(l1, r1, False)
462 self.assert_equality_only(r1, t1, False)
464 def test_bytes(self):
468 self.assert_total_order(bs1, bs1, 0)
469 self.assert_total_order(bs1, bs2, -1)
473 self.assert_total_order(ba1, ba1, 0)
474 self.assert_total_order(ba1, ba2, -1)
476 self.assert_total_order(bs1, ba1, 0)
477 self.assert_total_order(bs1, ba2, -1)
478 self.assert_total_order(ba1, bs1, 0)
479 self.assert_total_order(ba1, bs2, -1)
481 def test_sets(self):
485 self.assert_total_order(s1, s1, 0)
486 self.assert_total_order(s1, s2, -1)
490 self.assert_total_order(f1, f1, 0)
491 self.assert_total_order(f1, f2, -1)
493 self.assert_total_order(s1, f1, 0)
494 self.assert_total_order(s1, f2, -1)
495 self.assert_total_order(f1, s1, 0)
496 self.assert_total_order(f1, s2, -1)
498 def test_mappings(self):
504 self.assert_equality_only(d1, d1, True)
505 self.assert_equality_only(d1, d2, False)
506 self.assert_equality_only(d2, d3, True)