From: Benjamin Peterson Date: Fri, 2 Jul 2010 23:05:27 +0000 (+0000) Subject: don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754... X-Git-Tag: v2.7~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0df5a858e78e113f7af20a1055d60c88e6acb82a;p=python don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally --- diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 96024cd225..0328d1adc1 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -12,8 +12,13 @@ import sys INF = float("inf") NAN = float("nan") +have_getformat = hasattr(float, "__getformat__") +requires_getformat = unittest.skipUnless(have_getformat, + "requires __getformat__") +requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"), + "requires __setformat__") # decorator for skipping tests on non-IEEE 754 platforms -requires_IEEE_754 = unittest.skipUnless( +requires_IEEE_754 = unittest.skipUnless(have_getformat and float.__getformat__("double").startswith("IEEE"), "test requires IEEE 754 doubles") @@ -357,6 +362,7 @@ class GeneralFloatCases(unittest.TestCase): #self.assertTrue(0.0 > pow_op(-2.0, -1047) > -1e-315) +@requires_setformat class FormatFunctionsTestCase(unittest.TestCase): def setUp(self): @@ -407,6 +413,7 @@ LE_FLOAT_NAN = ''.join(reversed(BE_FLOAT_NAN)) # on non-IEEE platforms, attempting to unpack a bit pattern # representing an infinity or a NaN should raise an exception. +@requires_setformat class UnknownFormatTestCase(unittest.TestCase): def setUp(self): self.save_formats = {'double':float.__getformat__('double'), @@ -439,41 +446,42 @@ class UnknownFormatTestCase(unittest.TestCase): # let's also try to guarantee that -0.0 and 0.0 don't get confused. class IEEEFormatTestCase(unittest.TestCase): - if float.__getformat__("double").startswith("IEEE"): - def test_double_specials_do_unpack(self): - for fmt, data in [('>d', BE_DOUBLE_INF), - ('>d', BE_DOUBLE_NAN), - ('f', BE_FLOAT_INF), - ('>f', BE_FLOAT_NAN), - ('d', BE_DOUBLE_INF), + ('>d', BE_DOUBLE_NAN), + ('f', BE_FLOAT_INF), + ('>f', BE_FLOAT_NAN), + ('