-
Notifications
You must be signed in to change notification settings - Fork 38
fix: remove float_precision for protobuf 7 #559
Changes from 7 commits
bcd7ecd
a27845c
d946a7a
89e5ac2
41c8499
3b4a2e0
638c8f6
e6ef3c7
944c570
586cb92
9a24832
6672f08
e76ad73
ae854bf
e14707c
18e10e8
3a96248
2359c2d
78e201d
5bd83d3
c7093ff
d5d6d52
6689172
f849127
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,13 +253,33 @@ class Squid(proto.Message): | |
| assert re.search(r"massKg.*name", j) | ||
|
|
||
|
|
||
| # TODO: https://github.com/googleapis/proto-plus-python/issues/390 | ||
| def test_json_float_precision(): | ||
| if int(proto.message._PROTOBUF_MAJOR_VERSION) >= 7: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NO ACTION: I situations like this, I often choose to decorate a test with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I think they started out different, but the code is pretty similar now. I'll take another look |
||
| pytest.skip("float_precision was removed in protobuf 7.x") | ||
|
|
||
| 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) | ||
| s = Squid(name="Steve", mass_kg=3.141592) | ||
| j = Squid.to_json(s, float_precision=3, indent=None) | ||
|
|
||
| assert j == '{"name": "Steve", "massKg": 3.14}' | ||
|
|
||
|
|
||
| def test_json_float_precision_7_plus(): | ||
| if int(proto.message._PROTOBUF_MAJOR_VERSION) < 7: | ||
| pytest.skip("unsupported protobuf version for test") | ||
|
|
||
| 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.141592) | ||
| with pytest.warns(DeprecationWarning) as warnings: | ||
| j = Squid.to_json(s, float_precision=3, indent=None) | ||
|
|
||
| assert j == '{"name": "Steve", "massKg": 3.141592}' | ||
|
|
||
| assert len(warnings) == 1 | ||
| assert "`float_precision` has been removed" in warnings[0].message.args[0] | ||
Uh oh!
There was an error while loading. Please reload this page.