1 """Unit tests for numbers.py."""
5 from numbers
import Complex
, Real
, Rational
, Integral
6 from test
import test_support
8 class TestNumbers(unittest
.TestCase
):
10 self
.assertTrue(issubclass(int, Integral
))
11 self
.assertTrue(issubclass(int, Complex
))
13 self
.assertEqual(7, int(7).real
)
14 self
.assertEqual(0, int(7).imag
)
15 self
.assertEqual(7, int(7).conjugate())
16 self
.assertEqual(7, int(7).numerator
)
17 self
.assertEqual(1, int(7).denominator
)
20 self
.assertTrue(issubclass(long, Integral
))
21 self
.assertTrue(issubclass(long, Complex
))
23 self
.assertEqual(7, long(7).real
)
24 self
.assertEqual(0, long(7).imag
)
25 self
.assertEqual(7, long(7).conjugate())
26 self
.assertEqual(7, long(7).numerator
)
27 self
.assertEqual(1, long(7).denominator
)
30 self
.assertFalse(issubclass(float, Rational
))
31 self
.assertTrue(issubclass(float, Real
))
33 self
.assertEqual(7.3, float(7.3).real
)
34 self
.assertEqual(0, float(7.3).imag
)
35 self
.assertEqual(7.3, float(7.3).conjugate())
37 def test_complex(self
):
38 self
.assertFalse(issubclass(complex, Real
))
39 self
.assertTrue(issubclass(complex, Complex
))
41 c1
, c2
= complex(3, 2), complex(4,1)
42 # XXX: This is not ideal, but see the comment in math_trunc().
43 self
.assertRaises(AttributeError, math
.trunc
, c1
)
44 self
.assertRaises(TypeError, float, c1
)
45 self
.assertRaises(TypeError, int, c1
)
48 test_support
.run_unittest(TestNumbers
)
51 if __name__
== "__main__":