summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-03 18:42:55 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-03 18:42:55 (GMT)
commit16931c3559689cfa9d98e3b56e612b7e1e635b7a (patch)
treedd63cb2a5960a03eeb2a9560222ffebe03965817 /Lib/test/test_float.py
parentbb7f7327fea85d73e13950e83e5e39d57f7488df (diff)
downloadcpython-16931c3559689cfa9d98e3b56e612b7e1e635b7a.zip
cpython-16931c3559689cfa9d98e3b56e612b7e1e635b7a.tar.gz
cpython-16931c3559689cfa9d98e3b56e612b7e1e635b7a.tar.bz2
Issue #26983: float() now always return an instance of exact float.
The deprecation warning is emitted if __float__ returns an instance of a strict subclass of float. In a future versions of Python this can be an error.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 427f044..68b212e 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -161,11 +161,12 @@ class GeneralFloatCases(unittest.TestCase):
def __float__(self):
return float(str(self)) + 1
- self.assertAlmostEqual(float(Foo1()), 42.)
- self.assertAlmostEqual(float(Foo2()), 42.)
- self.assertAlmostEqual(float(Foo3(21)), 42.)
+ self.assertEqual(float(Foo1()), 42.)
+ self.assertEqual(float(Foo2()), 42.)
+ with self.assertWarns(DeprecationWarning):
+ self.assertEqual(float(Foo3(21)), 42.)
self.assertRaises(TypeError, float, Foo4(42))
- self.assertAlmostEqual(float(FooStr('8')), 9.)
+ self.assertEqual(float(FooStr('8')), 9.)
class Foo5:
def __float__(self):
@@ -176,10 +177,14 @@ class GeneralFloatCases(unittest.TestCase):
class F:
def __float__(self):
return OtherFloatSubclass(42.)
- self.assertAlmostEqual(float(F()), 42.)
- self.assertIs(type(float(F())), OtherFloatSubclass)
- self.assertAlmostEqual(FloatSubclass(F()), 42.)
- self.assertIs(type(FloatSubclass(F())), FloatSubclass)
+ with self.assertWarns(DeprecationWarning):
+ self.assertEqual(float(F()), 42.)
+ with self.assertWarns(DeprecationWarning):
+ self.assertIs(type(float(F())), float)
+ with self.assertWarns(DeprecationWarning):
+ self.assertEqual(FloatSubclass(F()), 42.)
+ with self.assertWarns(DeprecationWarning):
+ self.assertIs(type(FloatSubclass(F())), FloatSubclass)
def test_is_integer(self):
self.assertFalse((1.1).is_integer())