Skip to content

Commit 7e93d84

Browse files
fangchenliShashwatAgrawal20
authored andcommitted
TST: parametrize Decimal ujson test (#60843)
1 parent f86d925 commit 7e93d84

File tree

1 file changed

+17
-53
lines changed

1 file changed

+17
-53
lines changed

pandas/tests/io/json/test_ujson.py

+17-53
Original file line numberDiff line numberDiff line change
@@ -53,60 +53,24 @@ def orient(request):
5353

5454
class TestUltraJSONTests:
5555
@pytest.mark.skipif(not IS64, reason="not compliant on 32-bit, xref #15865")
56-
def test_encode_decimal(self):
57-
sut = decimal.Decimal("1337.1337")
58-
encoded = ujson.ujson_dumps(sut, double_precision=15)
59-
decoded = ujson.ujson_loads(encoded)
60-
assert decoded == "1337.1337"
61-
62-
sut = decimal.Decimal("0.95")
63-
encoded = ujson.ujson_dumps(sut, double_precision=1)
64-
assert encoded == '"0.95"'
65-
66-
decoded = ujson.ujson_loads(encoded)
67-
assert decoded == "0.95"
68-
69-
sut = decimal.Decimal("0.94")
70-
encoded = ujson.ujson_dumps(sut, double_precision=1)
71-
assert encoded == '"0.94"'
72-
73-
decoded = ujson.ujson_loads(encoded)
74-
assert decoded == "0.94"
75-
76-
sut = decimal.Decimal("1.95")
77-
encoded = ujson.ujson_dumps(sut, double_precision=1)
78-
assert encoded == '"1.95"'
79-
80-
decoded = ujson.ujson_loads(encoded)
81-
assert decoded == "1.95"
82-
83-
sut = decimal.Decimal("-1.95")
84-
encoded = ujson.ujson_dumps(sut, double_precision=1)
85-
assert encoded == '"-1.95"'
86-
87-
decoded = ujson.ujson_loads(encoded)
88-
assert decoded == "-1.95"
89-
90-
sut = decimal.Decimal("0.995")
91-
encoded = ujson.ujson_dumps(sut, double_precision=2)
92-
assert encoded == '"0.995"'
93-
94-
decoded = ujson.ujson_loads(encoded)
95-
assert decoded == "0.995"
96-
97-
sut = decimal.Decimal("0.9995")
98-
encoded = ujson.ujson_dumps(sut, double_precision=3)
99-
assert encoded == '"0.9995"'
100-
101-
decoded = ujson.ujson_loads(encoded)
102-
assert decoded == "0.9995"
103-
104-
sut = decimal.Decimal("0.99999999999999944")
105-
encoded = ujson.ujson_dumps(sut, double_precision=15)
106-
assert encoded == '"0.99999999999999944"'
107-
56+
@pytest.mark.parametrize(
57+
"value, double_precision",
58+
[
59+
("1337.1337", 15),
60+
("0.95", 1),
61+
("0.94", 1),
62+
("1.95", 1),
63+
("-1.95", 1),
64+
("0.995", 2),
65+
("0.9995", 3),
66+
("0.99999999999999944", 15),
67+
],
68+
)
69+
def test_encode_decimal(self, value, double_precision):
70+
sut = decimal.Decimal(value)
71+
encoded = ujson.ujson_dumps(sut, double_precision=double_precision)
10872
decoded = ujson.ujson_loads(encoded)
109-
assert decoded == "0.99999999999999944"
73+
assert decoded == value
11074

11175
@pytest.mark.parametrize("ensure_ascii", [True, False])
11276
def test_encode_string_conversion(self, ensure_ascii):

0 commit comments

Comments
 (0)