]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46852: Restore test_getformat() test (GH-31601)
authorVictor Stinner <vstinner@python.org>
Sun, 27 Feb 2022 00:12:33 +0000 (01:12 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Feb 2022 00:12:33 +0000 (01:12 +0100)
Lib/test/test_float.py

index 3d2a21f1522ea23b6564d53b91d27a7589b886a8..61950289ae1d217c4656770214e14ca7ed35c0a8 100644 (file)
@@ -16,9 +16,6 @@ from math import isinf, isnan, copysign, ldexp
 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 GeneralFloatCases(unittest.TestCase):
         self.assertEqual(hash(value), object.__hash__(value))
 
 
+@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'