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

Python code coverage for Lib/test/test_abstract_numbers.py

#countcontent
1n/a"""Unit tests for numbers.py."""
2n/a
3n/aimport math
4n/aimport operator
5n/aimport unittest
6n/afrom numbers import Complex, Real, Rational, Integral
7n/a
8n/aclass TestNumbers(unittest.TestCase):
9n/a def test_int(self):
10n/a self.assertTrue(issubclass(int, Integral))
11n/a self.assertTrue(issubclass(int, Complex))
12n/a
13n/a self.assertEqual(7, int(7).real)
14n/a self.assertEqual(0, int(7).imag)
15n/a self.assertEqual(7, int(7).conjugate())
16n/a self.assertEqual(-7, int(-7).conjugate())
17n/a self.assertEqual(7, int(7).numerator)
18n/a self.assertEqual(1, int(7).denominator)
19n/a
20n/a def test_float(self):
21n/a self.assertFalse(issubclass(float, Rational))
22n/a self.assertTrue(issubclass(float, Real))
23n/a
24n/a self.assertEqual(7.3, float(7.3).real)
25n/a self.assertEqual(0, float(7.3).imag)
26n/a self.assertEqual(7.3, float(7.3).conjugate())
27n/a self.assertEqual(-7.3, float(-7.3).conjugate())
28n/a
29n/a def test_complex(self):
30n/a self.assertFalse(issubclass(complex, Real))
31n/a self.assertTrue(issubclass(complex, Complex))
32n/a
33n/a c1, c2 = complex(3, 2), complex(4,1)
34n/a # XXX: This is not ideal, but see the comment in math_trunc().
35n/a self.assertRaises(TypeError, math.trunc, c1)
36n/a self.assertRaises(TypeError, operator.mod, c1, c2)
37n/a self.assertRaises(TypeError, divmod, c1, c2)
38n/a self.assertRaises(TypeError, operator.floordiv, c1, c2)
39n/a self.assertRaises(TypeError, float, c1)
40n/a self.assertRaises(TypeError, int, c1)
41n/a
42n/a
43n/aif __name__ == "__main__":
44n/a unittest.main()