@@ -571,7 +571,7 @@ def test_generate_router_preserves_path_parameter_name(output_dir: Path) -> None
571571
572572@pytest .mark .cli_doc (
573573 options = ["--specify-tags" ],
574- option_description = "Regenerate only the routers matching a comma-separated tag list." ,
574+ option_description = "Generate or regenerate only the routers matching a comma-separated tag list." ,
575575 cli_args = [
576576 "--input" ,
577577 "openapi/using_routers/using_routers_example.yaml" ,
@@ -619,21 +619,37 @@ def test_generate_modify_specific_routers(oas_file: Path, output_dir: Path) -> N
619619
620620@freeze_time ("2023-04-11" )
621621def test_generate_specific_tags_without_existing_main (output_dir : Path ) -> None :
622- run_cli_and_assert (
623- input_path = DATA_PATH
624- / OPEN_API_USING_ROUTERS_DIR_NAME
625- / "using_routers_example.yaml" ,
626- output_path = output_dir ,
627- expected_path = EXPECTED_OPENAPI_PATH / "using_routers" / "using_routers_example" ,
628- extra_args = [
629- "--template-dir" ,
630- str (BUILTIN_MODULAR_TEMPLATE_DIR ),
631- "--generate-routers" ,
632- "--specify-tags" ,
633- SPECIFIC_TAGS ,
634- ],
622+ assert (
623+ run_main_with_args (
624+ [
625+ "--input" ,
626+ str (
627+ DATA_PATH
628+ / OPEN_API_USING_ROUTERS_DIR_NAME
629+ / "using_routers_example.yaml"
630+ ),
631+ "--output" ,
632+ str (output_dir ),
633+ "--template-dir" ,
634+ str (BUILTIN_MODULAR_TEMPLATE_DIR ),
635+ "--generate-routers" ,
636+ "--specify-tags" ,
637+ SPECIFIC_TAGS ,
638+ ]
639+ )
640+ == 0
635641 )
636642
643+ main_text = output_dir .joinpath ("main.py" ).read_text (encoding = "utf-8" )
644+ assert "from .routers import fat_cats, wild_boars" in main_text
645+ assert "app.include_router(fat_cats.router)" in main_text
646+ assert "app.include_router(wild_boars.router)" in main_text
647+ assert "slim_dogs" not in main_text
648+ assert output_dir .joinpath ("routers" , "fat_cats.py" ).exists ()
649+ assert output_dir .joinpath ("routers" , "wild_boars.py" ).exists ()
650+ assert not output_dir .joinpath ("routers" , "slim_dogs.py" ).exists ()
651+ validate_generated_code (output_dir )
652+
637653
638654@freeze_time ("2023-04-11" )
639655def test_generate_specific_tags_with_existing_main_without_router_includes (
@@ -644,21 +660,35 @@ def test_generate_specific_tags_with_existing_main_without_router_includes(
644660 "from fastapi import FastAPI\n \n app = FastAPI()\n " ,
645661 encoding = "utf-8" ,
646662 )
647- run_cli_and_assert (
648- input_path = DATA_PATH
649- / OPEN_API_USING_ROUTERS_DIR_NAME
650- / "using_routers_example.yaml" ,
651- output_path = output_dir ,
652- expected_path = EXPECTED_OPENAPI_PATH / "using_routers" / "using_routers_example" ,
653- extra_args = [
654- "--template-dir" ,
655- str (BUILTIN_MODULAR_TEMPLATE_DIR ),
656- "--generate-routers" ,
657- "--specify-tags" ,
658- SPECIFIC_TAGS ,
659- ],
663+ assert (
664+ run_main_with_args (
665+ [
666+ "--input" ,
667+ str (
668+ DATA_PATH
669+ / OPEN_API_USING_ROUTERS_DIR_NAME
670+ / "using_routers_example.yaml"
671+ ),
672+ "--output" ,
673+ str (output_dir ),
674+ "--template-dir" ,
675+ str (BUILTIN_MODULAR_TEMPLATE_DIR ),
676+ "--generate-routers" ,
677+ "--specify-tags" ,
678+ SPECIFIC_TAGS ,
679+ ]
680+ )
681+ == 0
660682 )
661683
684+ main_text = output_dir .joinpath ("main.py" ).read_text (encoding = "utf-8" )
685+ assert "from .routers import fat_cats, wild_boars" in main_text
686+ assert "slim_dogs" not in main_text
687+ assert output_dir .joinpath ("routers" , "fat_cats.py" ).exists ()
688+ assert output_dir .joinpath ("routers" , "wild_boars.py" ).exists ()
689+ assert not output_dir .joinpath ("routers" , "slim_dogs.py" ).exists ()
690+ validate_generated_code (output_dir )
691+
662692
663693@freeze_time ("2020-06-19" )
664694def test_generate_non_200_responses (output_dir : Path ) -> None :
0 commit comments