summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-02-27 00:12:33 (GMT)
committerGitHub <noreply@github.com>2022-02-27 00:12:33 (GMT)
commit5a1c637ec6264790d3cfeef46815c62c32b510f3 (patch)
tree9c866546106995f64219d139d689813acb34d718
parentad56919c5ed54523f866e6605a2573ab7b7d5235 (diff)
downloadcpython-5a1c637ec6264790d3cfeef46815c62c32b510f3.zip
cpython-5a1c637ec6264790d3cfeef46815c62c32b510f3.tar.gz
cpython-5a1c637ec6264790d3cfeef46815c62c32b510f3.tar.bz2
bpo-46852: Restore test_getformat() test (GH-31601)
-rw-r--r--Lib/test/test_float.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 3d2a21f..6195028 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -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'