diff options
Diffstat (limited to 'Lib/test/test_float.py')
| -rw-r--r-- | Lib/test/test_float.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 24fe128..cb1f6db 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -822,6 +822,14 @@ class RoundTestCase(unittest.TestCase): test(sfmt, NAN, ' nan') test(sfmt, -NAN, ' nan') + def test_None_ndigits(self): + for x in round(1.23), round(1.23, None), round(1.23, ndigits=None): + self.assertEqual(x, 1) + self.assertIsInstance(x, int) + for x in round(1.78), round(1.78, None), round(1.78, ndigits=None): + self.assertEqual(x, 2) + self.assertIsInstance(x, int) + # Beginning with Python 2.6 float has cross platform compatible # ways to create and represent inf and nan @@ -1347,19 +1355,24 @@ class HexFloatTestCase(unittest.TestCase): else: self.identical(x, fromHex(toHex(x))) + def test_subclass(self): + class F(float): + def __new__(cls, value): + return float.__new__(cls, value + 1) + + f = F.fromhex((1.5).hex()) + self.assertIs(type(f), F) + self.assertEqual(f, 2.5) + + class F2(float): + def __init__(self, value): + self.foo = 'bar' + + f = F2.fromhex((1.5).hex()) + self.assertIs(type(f), F2) + self.assertEqual(f, 1.5) + self.assertEqual(getattr(f, 'foo', 'none'), 'bar') -def test_main(): - support.run_unittest( - GeneralFloatCases, - FormatFunctionsTestCase, - UnknownFormatTestCase, - IEEEFormatTestCase, - FormatTestCase, - ReprTestCase, - RoundTestCase, - InfNanTest, - HexFloatTestCase, - ) if __name__ == '__main__': - test_main() + unittest.main() |
