ยปCore Development>Code coverage>Lib/test/test_unary.py

Python code coverage for Lib/test/test_unary.py

#countcontent
1n/a"""Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2"""
2n/a
3n/aimport unittest
4n/a
5n/aclass UnaryOpTestCase(unittest.TestCase):
6n/a
7n/a def test_negative(self):
8n/a self.assertTrue(-2 == 0 - 2)
9n/a self.assertEqual(-0, 0)
10n/a self.assertEqual(--2, 2)
11n/a self.assertTrue(-2 == 0 - 2)
12n/a self.assertTrue(-2.0 == 0 - 2.0)
13n/a self.assertTrue(-2j == 0 - 2j)
14n/a
15n/a def test_positive(self):
16n/a self.assertEqual(+2, 2)
17n/a self.assertEqual(+0, 0)
18n/a self.assertEqual(++2, 2)
19n/a self.assertEqual(+2, 2)
20n/a self.assertEqual(+2.0, 2.0)
21n/a self.assertEqual(+2j, 2j)
22n/a
23n/a def test_invert(self):
24n/a self.assertTrue(-2 == 0 - 2)
25n/a self.assertEqual(-0, 0)
26n/a self.assertEqual(--2, 2)
27n/a self.assertTrue(-2 == 0 - 2)
28n/a
29n/a def test_no_overflow(self):
30n/a nines = "9" * 32
31n/a self.assertTrue(eval("+" + nines) == 10**32-1)
32n/a self.assertTrue(eval("-" + nines) == -(10**32-1))
33n/a self.assertTrue(eval("~" + nines) == ~(10**32-1))
34n/a
35n/a def test_negation_of_exponentiation(self):
36n/a # Make sure '**' does the right thing; these form a
37n/a # regression test for SourceForge bug #456756.
38n/a self.assertEqual(-2 ** 3, -8)
39n/a self.assertEqual((-2) ** 3, -8)
40n/a self.assertEqual(-2 ** 4, -16)
41n/a self.assertEqual((-2) ** 4, 16)
42n/a
43n/a def test_bad_types(self):
44n/a for op in '+', '-', '~':
45n/a self.assertRaises(TypeError, eval, op + "b'a'")
46n/a self.assertRaises(TypeError, eval, op + "'a'")
47n/a
48n/a self.assertRaises(TypeError, eval, "~2j")
49n/a self.assertRaises(TypeError, eval, "~2.0")
50n/a
51n/a
52n/aif __name__ == "__main__":
53n/a unittest.main()