• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from test.test_support import run_unittest, check_py3k_warnings
2import unittest
3
4class TestImplementationComparisons(unittest.TestCase):
5
6    def test_type_comparisons(self):
7        self.assertTrue(str < int or str > int)
8        self.assertTrue(int <= str or int >= str)
9        self.assertTrue(cmp(int, str) != 0)
10        self.assertTrue(int is int)
11        self.assertTrue(str == str)
12        self.assertTrue(int != str)
13
14    def test_cell_comparisons(self):
15        def f(x):
16            if x:
17                y = 1
18            def g():
19                return x
20            def h():
21                return y
22            return g, h
23        g, h = f(0)
24        g_cell, = g.func_closure
25        h_cell, = h.func_closure
26        self.assertTrue(h_cell < g_cell)
27        self.assertTrue(g_cell >= h_cell)
28        self.assertEqual(cmp(g_cell, h_cell), 1)
29        self.assertTrue(g_cell is g_cell)
30        self.assertTrue(g_cell == g_cell)
31        self.assertTrue(h_cell == h_cell)
32        self.assertTrue(g_cell != h_cell)
33
34def test_main():
35    with check_py3k_warnings():
36        run_unittest(TestImplementationComparisons)
37
38if __name__ == '__main__':
39    test_main()
40