1313# limitations under the License.
1414
1515from __future__ import absolute_import
16- import os
17- import pathlib
1816
1917import nox
18+ import pathlib
2019
2120
2221CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
3029 "3.10" ,
3130 "3.11" ,
3231 "3.12" ,
32+ "3.13" ,
3333]
3434
3535# Error if a python version is missing
3636nox .options .error_on_missing_interpreters = True
3737
3838
3939@nox .session (python = PYTHON_VERSIONS )
40- def unit (session , proto = "python" ):
40+ @nox .parametrize ("implementation" , ["cpp" , "upb" , "python" ])
41+ def unit (session , implementation ):
4142 """Run the unit test suite."""
4243
4344 constraints_path = str (
4445 CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
4546 )
4647
47- session .env ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" ] = proto
48+ session .env ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" ] = implementation
4849 session .install ("coverage" , "pytest" , "pytest-cov" , "pytz" )
4950 session .install ("-e" , ".[testing]" , "-c" , constraints_path )
50- if proto == "cpp" : # 4.20 does not have cpp.
51- session .install ("protobuf==3.19.0" )
51+ # TODO(https://github.com/googleapis/proto-plus-python/issues/389):
52+ # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
53+ # The 'cpp' implementation requires Protobuf<4.
54+ if implementation == "cpp" :
55+ session .install ("protobuf<4" )
5256
5357 # TODO(https://github.com/googleapis/proto-plus-python/issues/403): re-enable `-W=error`
5458 # The warnings-as-errors flag `-W=error` was removed in
5559 # https://github.com/googleapis/proto-plus-python/pull/400.
5660 # It should be re-added once issue
57- # https://github.com/protocolbuffers/protobuf/issues/12186 is fixed.
61+ # https://github.com/protocolbuffers/protobuf/issues/15077 is fixed.
5862 session .run (
59- "py.test " ,
63+ "pytest " ,
6064 "--quiet" ,
6165 * (
6266 session .posargs # Coverage info when running individual tests is annoying.
@@ -71,17 +75,59 @@ def unit(session, proto="python"):
7175 )
7276
7377
74- # Check if protobuf has released wheels for new python versions
75- # https://pypi.org/project/protobuf/#files
76- # This list will generally be shorter than 'unit'
77- @nox .session (python = ["3.6" , "3.7" , "3.8" , "3.9" , "3.10" ])
78- def unitcpp (session ):
79- return unit (session , proto = "cpp" )
78+ # Only test upb and python implementation backends.
79+ # As of protobuf 4.x, the "ccp" implementation is not available in the PyPI package as per
80+ # https://github.com/protocolbuffers/protobuf/tree/main/python#implementation-backends
81+ @nox .session (python = PYTHON_VERSIONS [- 2 ])
82+ @nox .parametrize ("implementation" , ["python" , "upb" ])
83+ def prerelease_deps (session , implementation ):
84+ """Run the unit test suite against pre-release versions of dependencies."""
8085
86+ session .env ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" ] = implementation
8187
82- @nox .session (python = PYTHON_VERSIONS )
83- def unitupb (session ):
84- return unit (session , proto = "upb" )
88+ # Install test environment dependencies
89+ session .install ("coverage" , "pytest" , "pytest-cov" , "pytz" )
90+
91+ # Install the package without dependencies
92+ session .install ("-e" , "." , "--no-deps" )
93+
94+ prerel_deps = [
95+ "google-api-core" ,
96+ # dependency of google-api-core
97+ "googleapis-common-protos" ,
98+ ]
99+
100+ for dep in prerel_deps :
101+ session .install ("--pre" , "--no-deps" , "--upgrade" , dep )
102+
103+ session .install ("--pre" , "--upgrade" , "protobuf" )
104+ # Print out prerelease package versions
105+ session .run (
106+ "python" , "-c" , "import google.protobuf; print(google.protobuf.__version__)"
107+ )
108+ session .run (
109+ "python" , "-c" , "import google.api_core; print(google.api_core.__version__)"
110+ )
111+
112+ # TODO(https://github.com/googleapis/proto-plus-python/issues/403): re-enable `-W=error`
113+ # The warnings-as-errors flag `-W=error` was removed in
114+ # https://github.com/googleapis/proto-plus-python/pull/400.
115+ # It should be re-added once issue
116+ # https://github.com/protocolbuffers/protobuf/issues/15077 is fixed.
117+ session .run (
118+ "pytest" ,
119+ "--quiet" ,
120+ * (
121+ session .posargs # Coverage info when running individual tests is annoying.
122+ or [
123+ "--cov=proto" ,
124+ "--cov-config=.coveragerc" ,
125+ "--cov-report=term" ,
126+ "--cov-report=html" ,
127+ "tests" ,
128+ ]
129+ ),
130+ )
85131
86132
87133@nox .session (python = "3.9" )
0 commit comments