Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit 3b4a2e0

Browse files
committed
updated test
1 parent 41c8499 commit 3b4a2e0

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

tests/test_json.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ class Squid(proto.Message):
253253
assert re.search(r"massKg.*name", j)
254254

255255

256-
# TODO: https://github.com/googleapis/proto-plus-python/issues/390
256+
pytest.skipif(
257+
int(proto.message._PROTOBUF_MAJOR_VERSION) >= 7,
258+
"float_precision removed in protobuf 7.x"
259+
)
257260
def test_json_float_precision():
258261
class Squid(proto.Message):
259262
name = proto.Field(proto.STRING, number=1)
@@ -263,3 +266,21 @@ class Squid(proto.Message):
263266
j = Squid.to_json(s, float_precision=3, indent=None)
264267

265268
assert j == '{"name": "Steve", "massKg": 3.14}'
269+
270+
pytest.skipif(
271+
int(proto.message._PROTOBUF_MAJOR_VERSION) < 7,
272+
"unsupported protobuf version for test"
273+
)
274+
def test_json_float_precision_7_plus():
275+
class Squid(proto.Message):
276+
name = proto.Field(proto.STRING, number=1)
277+
mass_kg = proto.Field(proto.FLOAT, number=2)
278+
279+
s = Squid(name="Steve", mass_kg=3.14159265)
280+
with pytest.warns(DeprecationWarning) as warnings:
281+
j = Squid.to_json(s, float_precision=3, indent=None)
282+
283+
assert j == '{"name": "Steve", "massKg": 3.14159265}'
284+
285+
assert len(warnings) == 1
286+
assert "`float_precision` has been removed" in warnings[0].message.args[0]

0 commit comments

Comments
 (0)