[New-bugs-announce] [issue18745] Test enum in test_json is ignorant of infinity value

Vajrasky Kok report at bugs.python.org
Thu Aug 15 09:59:00 CEST 2013


New submission from Vajrasky Kok:

Test enum json in Lib/test/test_json/test_enum.py is ignorant of infinity values. Also, NaN, but since NaN is a weirdo, let's not take that into account.

The unit test should represent of what will work in every case. For example:

    def test_floats(self):
         for enum in FloatNum:
            self.assertEqual(self.dumps(enum), repr(enum.value))

This will fail if enum is infinity.

This wisdom about infinity was bestowed upon me when I was reading Lib/test/test_json/test_float.py.

    def test_floats(self):
        for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100, 3.1]:
            self.assertEqual(float(self.dumps(num)), num)
            self.assertEqual(self.loads(self.dumps(num)), num)

    def test_ints(self):
        for num in [1, 1<<32, 1<<64]:
            self.assertEqual(self.dumps(num), str(num))
            self.assertEqual(int(self.dumps(num)), num)

As you can see, in float case, we don't use str(num) because it does not work with infinity.

Attached the patch to refactor the test to handle infinity value. For the completeness sake, I added the case of negative infinity and NaN as well.

----------
components: Tests
files: add_infinity_to_test_enum_in_json.patch
keywords: patch
messages: 195238
nosy: ethan.furman, vajrasky
priority: normal
severity: normal
status: open
title: Test enum in test_json is ignorant of infinity value
versions: Python 3.4
Added file: http://bugs.python.org/file31298/add_infinity_to_test_enum_in_json.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18745>
_______________________________________


More information about the New-bugs-announce mailing list