[Python-checkins] bpo-46852: Restore test_getformat() test (GH-31601)

vstinner webhook-mailer at python.org
Sat Feb 26 19:12:37 EST 2022


https://github.com/python/cpython/commit/5a1c637ec6264790d3cfeef46815c62c32b510f3
commit: 5a1c637ec6264790d3cfeef46815c62c32b510f3
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-02-27T01:12:33+01:00
summary:

bpo-46852: Restore test_getformat() test (GH-31601)

files:
M Lib/test/test_float.py

diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 3d2a21f1522ea..61950289ae1d2 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -16,9 +16,6 @@
 INF = float("inf")
 NAN = float("nan")
 
-have_getformat = hasattr(float, "__getformat__")
-requires_getformat = unittest.skipUnless(have_getformat,
-                                         "requires __getformat__")
 
 #locate file with float format test values
 test_dir = os.path.dirname(__file__) or os.curdir
@@ -610,6 +607,17 @@ class F(float, H):
         self.assertEqual(hash(value), object.__hash__(value))
 
 
+ at unittest.skipUnless(hasattr(float, "__getformat__"), "requires __getformat__")
+class FormatFunctionsTestCase(unittest.TestCase):
+    def test_getformat(self):
+        self.assertIn(float.__getformat__('double'),
+                      ['unknown', 'IEEE, big-endian', 'IEEE, little-endian'])
+        self.assertIn(float.__getformat__('float'),
+                      ['unknown', 'IEEE, big-endian', 'IEEE, little-endian'])
+        self.assertRaises(ValueError, float.__getformat__, 'chicken')
+        self.assertRaises(TypeError, float.__getformat__, 1)
+
+
 BE_DOUBLE_INF = b'\x7f\xf0\x00\x00\x00\x00\x00\x00'
 LE_DOUBLE_INF = bytes(reversed(BE_DOUBLE_INF))
 BE_DOUBLE_NAN = b'\x7f\xf8\x00\x00\x00\x00\x00\x00'



More information about the Python-checkins mailing list