blob: 61de7a22bdef1cfaa166a9b62c5e25867e379004 [file] [log] [blame]
Steven Bethardae42f332008-03-18 17:26:10 +00001import unittest
2from test.test_support import catch_warning, TestSkipped, run_unittest
3import warnings
4
5# TODO: This is a hack to raise TestSkipped if -3 is not enabled. Instead
6# of relying on callable to have a warning, we should expose the -3 flag
7# to Python code somehow
8with catch_warning() as w:
9 callable(int)
10 if w.message is None:
11 raise TestSkipped('%s must be run with the -3 flag' % __name__)
12
13class TestPy3KWarnings(unittest.TestCase):
14
15 def test_type_inequality_comparisons(self):
16 expected = 'type inequality comparisons not supported in 3.x.'
17 with catch_warning() as w:
18 self.assertWarning(int < str, w, expected)
19 with catch_warning() as w:
20 self.assertWarning(type < object, w, expected)
21
22 def test_object_inequality_comparisons(self):
23 expected = 'comparing unequal types not supported in 3.x.'
24 with catch_warning() as w:
25 self.assertWarning(str < [], w, expected)
26 with catch_warning() as w:
27 self.assertWarning(object() < (1, 2), w, expected)
28
29 def test_dict_inequality_comparisons(self):
30 expected = 'dict inequality comparisons not supported in 3.x.'
31 with catch_warning() as w:
32 self.assertWarning({} < {2:3}, w, expected)
33 with catch_warning() as w:
34 self.assertWarning({} <= {}, w, expected)
35 with catch_warning() as w:
36 self.assertWarning({} > {2:3}, w, expected)
37 with catch_warning() as w:
38 self.assertWarning({2:3} >= {}, w, expected)
39
40 def test_cell_inequality_comparisons(self):
41 expected = 'cell comparisons not supported in 3.x.'
42 def f(x):
43 def g():
44 return x
45 return g
46 cell0, = f(0).func_closure
47 cell1, = f(1).func_closure
48 with catch_warning() as w:
49 self.assertWarning(cell0 == cell1, w, expected)
50 with catch_warning() as w:
51 self.assertWarning(cell0 < cell1, w, expected)
52
53 def assertWarning(self, _, warning, expected_message):
54 self.assertEqual(str(warning.message), expected_message)
55
56def test_main():
57 run_unittest(TestPy3KWarnings)
58
59if __name__ == '__main__':
60 test_main()