10000 test: verify json_name is respected (#270) · renovate-bot/proto-plus-python@2bdbcce · GitHub
[go: up one dir, main page]

Skip to content

Commit 2bdbcce

Browse files
authored
test: verify json_name is respected (googleapis#270)
Fields can customize their json name representation. Add a test to verify that this customization is respected by both Python and C++ runtimes. Boost protobuf requirement to gain required upstream bugfix.
1 parent 79ec820 commit 2bdbcce

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

noxfile.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
2323

2424

25-
@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
25+
PYTHON_VERSIONS = [
26+
"3.6",
27+
"3.7",
28+
"3.8",
29+
"3.9",
30+
"3.10",
31+
]
32+
33+
34+
@nox.session(python=PYTHON_VERSIONS)
2635
def unit(session, proto="python"):
2736
"""Run the unit test suite."""
2837

@@ -54,12 +63,13 @@ def unit(session, proto="python"):
5463
# Check if protobuf has released wheels for new python versions
5564
# https://pypi.org/project/protobuf/#files
5665
# This list will generally be shorter than 'unit'
57-
@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
66+
@nox.session(python=PYTHON_VERSIONS)
5867
def unitcpp(session):
5968
return unit(session, proto="cpp")
6069

6170

62-
@nox.session(python="3.9")
71+
# Just use the most recent version for docs
72+
@nox.session(python=PYTHON_VERSIONS[-1])
6373
def docs(session):
6474
"""Build the docs."""
6575

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
long_description=README,
3737
platforms="Posix; MacOS X",
3838
include_package_data=True,
39-
install_requires=("protobuf >= 3.12.0",),
39+
install_requires=("protobuf >= 3.19.0",),
4040
extras_require={"testing": ["google-api-core[grpc] >= 1.22.2",],},
4141
python_requires=">=3.6",
4242
classifiers=[

testing/constraints-3.6.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
#
66
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
77
# Then this file should have foo==1.14.0
8-
protobuf==3.15.6
98
google-api-core==1.22.2

tests/test_json.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,17 @@ class Squid(proto.Message):
148148
assert s.mass_kg == 20
149149

150150
assert Squid.to_json(s, preserving_proto_field_name=True) == json_str
151+
152+
153+
def test_json_name():
154+
class Squid(proto.Message):
155+
massKg = proto.Field(proto.INT32, number=1, json_name="mass_in_kilograms")
156+
157+
s = Squid(massKg=20)
158+
j = Squid.to_json(s)
159+
160+
assert "mass_in_kilograms" in j
161+
162+
s_two = Squid.from_json(j)
163+
164+
assert s == s_two

0 commit comments

Comments
 (0)
0