summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-05-06 13:08:15 (GMT)
committerEric Smith <eric@trueblade.com>2009-05-06 13:08:15 (GMT)
commit741191f17a921191355c1a67ca9f7fda08c3ae57 (patch)
tree2ead9e0086ce417631365543e133a789d9f75eeb /Lib/test
parent5776c1623c1d14b8624547db5755fec8d60fc8ed (diff)
downloadcpython-741191f17a921191355c1a67ca9f7fda08c3ae57.zip
cpython-741191f17a921191355c1a67ca9f7fda08c3ae57.tar.gz
cpython-741191f17a921191355c1a67ca9f7fda08c3ae57.tar.bz2
Issue #3382. float 'F' formatting no longer maps to 'f'. This only affects nan and inf.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_complex.py18
-rw-r--r--Lib/test/test_float.py6
-rw-r--r--Lib/test/test_unicode.py8
3 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 1593f7b..43282d6 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -507,6 +507,24 @@ class ComplexTest(unittest.TestCase):
# make sure everything works in ''.format()
self.assertEqual('*{0:.3f}*'.format(3.14159+2.71828j), '*3.142+2.718j*')
+ # issue 3382
+ self.assertEqual(format(complex(NAN, NAN), 'f'), 'nan+nanj')
+ self.assertEqual(format(complex(1, NAN), 'f'), '1.000000+nanj')
+ self.assertEqual(format(complex(NAN, 1), 'f'), 'nan+1.000000j')
+ self.assertEqual(format(complex(NAN, -1), 'f'), 'nan-1.000000j')
+ self.assertEqual(format(complex(NAN, NAN), 'F'), 'NAN+NANj')
+ self.assertEqual(format(complex(1, NAN), 'F'), '1.000000+NANj')
+ self.assertEqual(format(complex(NAN, 1), 'F'), 'NAN+1.000000j')
+ self.assertEqual(format(complex(NAN, -1), 'F'), 'NAN-1.000000j')
+ self.assertEqual(format(complex(INF, INF), 'f'), 'inf+infj')
+ self.assertEqual(format(complex(1, INF), 'f'), '1.000000+infj')
+ self.assertEqual(format(complex(INF, 1), 'f'), 'inf+1.000000j')
+ self.assertEqual(format(complex(INF, -1), 'f'), 'inf-1.000000j')
+ self.assertEqual(format(complex(INF, INF), 'F'), 'INF+INFj')
+ self.assertEqual(format(complex(1, INF), 'F'), '1.000000+INFj')
+ self.assertEqual(format(complex(INF, 1), 'F'), 'INF+1.000000j')
+ self.assertEqual(format(complex(INF, -1), 'F'), 'INF-1.000000j')
+
def test_main():
support.run_unittest(ComplexTest)
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index b617fa3..c259d4f 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -320,6 +320,12 @@ class FormatTestCase(unittest.TestCase):
self.assertRaises(ValueError, format, 1e-100, format_spec)
self.assertRaises(ValueError, format, -1e-100, format_spec)
+ # issue 3382
+ self.assertEqual(format(NAN, 'f'), 'nan')
+ self.assertEqual(format(NAN, 'F'), 'NAN')
+ self.assertEqual(format(INF, 'f'), 'inf')
+ self.assertEqual(format(INF, 'F'), 'INF')
+
@unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
"test requires IEEE 754 doubles")
def test_format_testfile(self):
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 21bb922..3ede057 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -779,6 +779,14 @@ class UnicodeTest(
return '\u1234'
self.assertEqual('%s' % Wrapper(), '\u1234')
+ # issue 3382
+ NAN = float('nan')
+ INF = float('inf')
+ self.assertEqual('%f' % NAN, 'nan')
+ self.assertEqual('%F' % NAN, 'NAN')
+ self.assertEqual('%f' % INF, 'inf')
+ self.assertEqual('%F' % INF, 'INF')
+
@support.run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
def test_format_float(self):
# should not format with a comma, but always with C locale