summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-07-05 11:33:52 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2008-07-05 11:33:52 (GMT)
commitbf9f4d801530f4b4f40fe7baf93b1b4d55873275 (patch)
tree5e0027737673ad3b9a34f262f46b8bd16775a2e0 /Lib
parente78fbcce3e9fef7d4f701971186baa4bdec6b9b1 (diff)
downloadcpython-bf9f4d801530f4b4f40fe7baf93b1b4d55873275.zip
cpython-bf9f4d801530f4b4f40fe7baf93b1b4d55873275.tar.gz
cpython-bf9f4d801530f4b4f40fe7baf93b1b4d55873275.tar.bz2
Issue 3188: accept float('infinity') as well as float('inf'). This
makes the float constructor behave in the same way as specified by various other language standards, including C99, IEEE 754r, and the IBM Decimal standard.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_float.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 1a11707..bb48df0 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -253,24 +253,36 @@ class ReprTestCase(unittest.TestCase):
floats_file.close()
# Beginning with Python 2.6 float has cross platform compatible
-# ways to create and representate inf and nan
+# ways to create and represent inf and nan
class InfNanTest(unittest.TestCase):
def test_inf_from_str(self):
self.assert_(isinf(float("inf")))
self.assert_(isinf(float("+inf")))
self.assert_(isinf(float("-inf")))
+ self.assert_(isinf(float("infinity")))
+ self.assert_(isinf(float("+infinity")))
+ self.assert_(isinf(float("-infinity")))
self.assertEqual(repr(float("inf")), "inf")
self.assertEqual(repr(float("+inf")), "inf")
self.assertEqual(repr(float("-inf")), "-inf")
+ self.assertEqual(repr(float("infinity")), "inf")
+ self.assertEqual(repr(float("+infinity")), "inf")
+ self.assertEqual(repr(float("-infinity")), "-inf")
self.assertEqual(repr(float("INF")), "inf")
self.assertEqual(repr(float("+Inf")), "inf")
self.assertEqual(repr(float("-iNF")), "-inf")
+ self.assertEqual(repr(float("Infinity")), "inf")
+ self.assertEqual(repr(float("+iNfInItY")), "inf")
+ self.assertEqual(repr(float("-INFINITY")), "-inf")
self.assertEqual(str(float("inf")), "inf")
self.assertEqual(str(float("+inf")), "inf")
self.assertEqual(str(float("-inf")), "-inf")
+ self.assertEqual(str(float("infinity")), "inf")
+ self.assertEqual(str(float("+infinity")), "inf")
+ self.assertEqual(str(float("-infinity")), "-inf")
self.assertRaises(ValueError, float, "info")
self.assertRaises(ValueError, float, "+info")
@@ -278,6 +290,10 @@ class InfNanTest(unittest.TestCase):
self.assertRaises(ValueError, float, "in")
self.assertRaises(ValueError, float, "+in")
self.assertRaises(ValueError, float, "-in")
+ self.assertRaises(ValueError, float, "infinit")
+ self.assertRaises(ValueError, float, "+Infin")
+ self.assertRaises(ValueError, float, "-INFI")
+ self.assertRaises(ValueError, float, "infinitys")
def test_inf_as_str(self):
self.assertEqual(repr(1e300 * 1e300), "inf")