https://github.com/python/cpython/commit/5a1c637ec6264790d3cfeef46815c62c32b... commit: 5a1c637ec6264790d3cfeef46815c62c32b510f3 branch: main author: Victor Stinner <vstinner@python.org> committer: vstinner <vstinner@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)) +@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'