Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated test
  • Loading branch information
daniel-sanche committed Jan 24, 2026
commit 3b4a2e096d799356d547981b9ee66e0198693919
23 changes: 22 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ class Squid(proto.Message):
assert re.search(r"massKg.*name", j)


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

assert j == '{"name": "Steve", "massKg": 3.14}'

pytest.skipif(
int(proto.message._PROTOBUF_MAJOR_VERSION) < 7,
"unsupported protobuf version for test"
)
def test_json_float_precision_7_plus():
class Squid(proto.Message):
name = proto.Field(proto.STRING, number=1)
mass_kg = proto.Field(proto.FLOAT, number=2)

s = Squid(name="Steve", mass_kg=3.14159265)
with pytest.warns(DeprecationWarning) as warnings:
j = Squid.to_json(s, float_precision=3, indent=None)

assert j == '{"name": "Steve", "massKg": 3.14159265}'

assert len(warnings) == 1
assert "`float_precision` has been removed" in warnings[0].message.args[0]