@@ -242,8 +242,30 @@ def showcase_library(
242242 include_service_yaml = True ,
243243 retry_config = True ,
244244 rest_async_io_enabled = False ,
245+ install_async_rest_extra = False ,
245246):
246- """Install the generated library into the session for showcase tests."""
247+ """Install the generated library into the session for showcase tests.
248+
249+ Args:
250+ session: The nox session object.
251+ templates (str): The template directory to use for code generation.
252+ Defaults to "DEFAULT".
253+ other_opts (typing.Iterable[str]): Additional options passed to
254+ `--python_gapic_opt` during code generation.
255+ include_service_yaml (bool): Whether to download and pass
256+ `showcase_v1beta1.yaml` to the generator.
257+ retry_config (bool): Whether to download and pass
258+ `showcase_grpc_service_config.json` to the generator.
259+ rest_async_io_enabled (bool): Whether to enable the experimental
260+ `rest_async_io_enabled` setting in `showcase_v1beta1.yaml` so
261+ `rest_asyncio` transports are generated for all services. When True,
262+ the `[async_rest]` extra is also installed.
263+ install_async_rest_extra (bool): Whether to install the generated
264+ library with the `[async_rest]` extra and its corresponding
265+ `constraints-{python}-async-rest.txt` file even when
266+ `rest_async_io_enabled` is False in `showcase_v1beta1.yaml` (e.g.,
267+ for services with resumable upload methods).
268+ """
247269
248270 session .log ("-" * 70 )
249271 session .log ("Note: Showcase must be running for these tests to work." )
@@ -371,19 +393,19 @@ def showcase_library(
371393 constraints_path = str (
372394 f"{ tmp_dir } /testing/constraints-{ session .python } .txt"
373395 )
374- async_rest_constraints_path = str (
375- f"{ tmp_dir } /testing/constraints-{ session .python } -async-rest.txt"
376- )
377- if os .path .exists (async_rest_constraints_path ):
378- # use async-rest constraints if available
379- constraints_path = async_rest_constraints_path
380- else :
381- session .log (
382- f"{ async_rest_constraints_path } not found. Using base constraints file"
396+ extras = ""
397+ if rest_async_io_enabled or install_async_rest_extra :
398+ async_rest_constraints_path = str (
399+ f"{ tmp_dir } /testing/constraints-{ session .python } -async-rest.txt"
383400 )
384- # Showcase protos include `resumable_media.proto`
385- # Include the `async_rest` extra.
386- extras = "[async_rest]"
401+ if os .path .exists (async_rest_constraints_path ):
402+ # use async-rest constraints if available
403+ constraints_path = async_rest_constraints_path
404+ extras = "[async_rest]"
405+ else :
406+ session .log (
407+ f"{ async_rest_constraints_path } not found. Using base constraints file"
408+ )
387409 session .install ("-e" , f"{ tmp_dir } { extras } " , "-r" , constraints_path )
388410 else :
389411 # The ads templates do not have constraints files.
@@ -395,15 +417,22 @@ def showcase_library(
395417
396418
397419@nox .session (python = ALL_PYTHON )
420+ @nox .parametrize ("install_async_rest_extra" , [False , True ])
398421def showcase (
399422 session ,
423+ install_async_rest_extra = False ,
400424 templates = "DEFAULT" ,
401425 other_opts : typing .Iterable [str ] = (),
402426 env : typing .Optional [typing .Dict [str , str ]] = {},
403427):
404428 """Run the Showcase test suite."""
405429
406- with showcase_library (session , templates = templates , other_opts = other_opts ):
430+ with showcase_library (
431+ session ,
432+ templates = templates ,
433+ other_opts = other_opts ,
434+ install_async_rest_extra = install_async_rest_extra ,
435+ ):
407436 # Use pytest-asyncio<1.0.0 while we investigate the recent failure described in
408437 # https://github.com/googleapis/gapic-generator-python/issues/2399
409438 session .install ("pytest" , "pytest-asyncio<1.0.0" )
@@ -501,7 +530,26 @@ def showcase_pqc(
501530 session .run ("py.test" , "--quiet" , "--tls" , * (session .posargs or ["tests/system/test_pqc.py" ]), env = env )
502531
503532
504- def run_showcase_unit_tests (session , fail_under = 100 , rest_async_io_enabled = False ):
533+ def run_showcase_unit_tests (
534+ session ,
535+ fail_under = 100 ,
536+ rest_async_io_enabled = False ,
537+ install_async_rest_extra = False ,
538+ ):
539+ """Run the generated Showcase unit test suite with coverage verification.
540+
541+ Args:
542+ session: The nox session object.
543+ fail_under (int): Minimum required test coverage percentage.
544+ Defaults to 100.
545+ rest_async_io_enabled (bool): Whether `rest_async_io_enabled` was enabled
546+ in `showcase_v1beta1.yaml` during code generation.
547+ install_async_rest_extra (bool): Whether the library was installed with
548+ the `[async_rest]` extra. When both `rest_async_io_enabled` and
549+ `install_async_rest_extra` are False, `**/rest_asyncio.py` is omitted
550+ from coverage since optional `async_rest` dependencies are not
551+ installed.
552+ """
505553 session .install (
506554 "coverage" ,
507555 "pytest" ,
@@ -512,6 +560,20 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False
512560 # Freeze and print python environment package versions
513561 session .run ("python" , "-m" , "pip" , "freeze" )
514562
563+ if (
564+ not rest_async_io_enabled
565+ and not install_async_rest_extra
566+ and path .exists (".coveragerc" )
567+ ):
568+ with open (".coveragerc" , "r" ) as f :
569+ coveragerc = f .read ()
570+ if "**/rest_asyncio.py" not in coveragerc :
571+ coveragerc = coveragerc .replace (
572+ "omit =\n " , "omit =\n **/rest_asyncio.py\n "
573+ )
574+ with open (".coveragerc" , "w" ) as f :
575+ f .write (coveragerc )
576+
515577 # Run the tests.
516578 session .run (
517579 "py.test" ,
@@ -530,15 +592,24 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False
530592
531593
532594@nox .session (python = ALL_PYTHON )
595+ @nox .parametrize ("install_async_rest_extra" , [False , True ])
533596def showcase_unit (
534597 session ,
598+ install_async_rest_extra = False ,
535599 templates = "DEFAULT" ,
536600 other_opts : typing .Iterable [str ] = (),
537601):
538602 """Run the generated unit tests against the Showcase library."""
539- with showcase_library (session , templates = templates , other_opts = other_opts ) as lib :
603+ with showcase_library (
604+ session ,
605+ templates = templates ,
606+ other_opts = other_opts ,
607+ install_async_rest_extra = install_async_rest_extra ,
608+ ) as lib :
540609 session .chdir (lib )
541- run_showcase_unit_tests (session )
610+ run_showcase_unit_tests (
611+ session , install_async_rest_extra = install_async_rest_extra
612+ )
542613
543614
544615# TODO: `showcase_unit_w_rest_async` nox session runs showcase unit tests with the
0 commit comments