Back to index

python3.2  3.2.2
Public Member Functions
test.test_parser.STObjectTestCase Class Reference

List of all members.

Public Member Functions

def test_comparisons

Detailed Description

Test operations on ST objects themselves

Definition at line 550 of file test_parser.py.


Member Function Documentation

Definition at line 553 of file test_parser.py.

00553 
00554     def test_comparisons(self):
00555         # ST objects should support order and equality comparisons
00556         st1 = parser.expr('2 + 3')
00557         st2 = parser.suite('x = 2; y = x + 3')
00558         st3 = parser.expr('list(x**3 for x in range(20))')
00559         st1_copy = parser.expr('2 + 3')
00560         st2_copy = parser.suite('x = 2; y = x + 3')
00561         st3_copy = parser.expr('list(x**3 for x in range(20))')
00562 
00563         # exercise fast path for object identity
00564         self.assertEqual(st1 == st1, True)
00565         self.assertEqual(st2 == st2, True)
00566         self.assertEqual(st3 == st3, True)
00567         # slow path equality
00568         self.assertEqual(st1, st1_copy)
00569         self.assertEqual(st2, st2_copy)
00570         self.assertEqual(st3, st3_copy)
00571         self.assertEqual(st1 == st2, False)
00572         self.assertEqual(st1 == st3, False)
00573         self.assertEqual(st2 == st3, False)
00574         self.assertEqual(st1 != st1, False)
00575         self.assertEqual(st2 != st2, False)
00576         self.assertEqual(st3 != st3, False)
00577         self.assertEqual(st1 != st1_copy, False)
00578         self.assertEqual(st2 != st2_copy, False)
00579         self.assertEqual(st3 != st3_copy, False)
00580         self.assertEqual(st2 != st1, True)
00581         self.assertEqual(st1 != st3, True)
00582         self.assertEqual(st3 != st2, True)
00583         # we don't particularly care what the ordering is;  just that
00584         # it's usable and self-consistent
00585         self.assertEqual(st1 < st2, not (st2 <= st1))
00586         self.assertEqual(st1 < st3, not (st3 <= st1))
00587         self.assertEqual(st2 < st3, not (st3 <= st2))
00588         self.assertEqual(st1 < st2, st2 > st1)
00589         self.assertEqual(st1 < st3, st3 > st1)
00590         self.assertEqual(st2 < st3, st3 > st2)
00591         self.assertEqual(st1 <= st2, st2 >= st1)
00592         self.assertEqual(st3 <= st1, st1 >= st3)
00593         self.assertEqual(st2 <= st3, st3 >= st2)
00594         # transitivity
00595         bottom = min(st1, st2, st3)
00596         top = max(st1, st2, st3)
00597         mid = sorted([st1, st2, st3])[1]
00598         self.assertTrue(bottom < mid)
00599         self.assertTrue(bottom < top)
00600         self.assertTrue(mid < top)
00601         self.assertTrue(bottom <= mid)
00602         self.assertTrue(bottom <= top)
00603         self.assertTrue(mid <= top)
00604         self.assertTrue(bottom <= bottom)
00605         self.assertTrue(mid <= mid)
00606         self.assertTrue(top <= top)
00607         # interaction with other types
00608         self.assertEqual(st1 == 1588.602459, False)
00609         self.assertEqual('spanish armada' != st2, True)
00610         self.assertRaises(TypeError, operator.ge, st3, None)
00611         self.assertRaises(TypeError, operator.le, False, st1)
00612         self.assertRaises(TypeError, operator.lt, st1, 1815)
00613         self.assertRaises(TypeError, operator.gt, b'waterloo', st2)
00614 

Here is the call graph for this function:


The documentation for this class was generated from the following file: