From 5cc8903a746c933b9844280ce22afe7458010e2f Mon Sep 17 00:00:00 2001 From: Peter Sobolewski Date: Mon, 19 Feb 2024 21:02:10 -0500 Subject: [PATCH 1/3] use parametrize to test plugins with every answer combo --- tests/test_create_template.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index dfd9b1e..905aae9 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -19,10 +19,20 @@ def run_tox(plugin): except subprocess.CalledProcessError as e: pytest.fail("Subprocess fail", pytrace=True) - -def test_run_cookiecutter_and_plugin_tests(cookies, capsys): +@pytest.mark.parametrize("include_reader_plugin", ["y", "n"]) +@pytest.mark.parametrize("include_writer_plugin", ["y", "n"]) +@pytest.mark.parametrize("include_sample_data_plugin", ["y", "n"]) +@pytest.mark.parametrize("include_widget_plugin", ["y", "n"]) +def test_run_cookiecutter_and_plugin_tests(cookies, capsys, include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin): """Create a new plugin via cookiecutter and run its tests.""" - result = cookies.bake(extra_context={"plugin_name": "foo-bar"}) + result = cookies.bake(extra_context={ + "plugin_name": "foo-bar", + "include_reader_plugin": include_reader_plugin, + "include_writer_plugin": include_writer_plugin, + "include_sample_data_plugin": include_sample_data_plugin, + "include_widget_plugin": include_widget_plugin, + } + ) assert result.exit_code == 0 assert result.exception is None @@ -30,9 +40,19 @@ def test_run_cookiecutter_and_plugin_tests(cookies, capsys): assert result.project_path.is_dir() assert result.project_path.joinpath("src").is_dir() assert result.project_path.joinpath("src", "foo_bar", "__init__.py").is_file() - assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_reader.py").is_file() - run_tox(str(result.project_path)) + if include_reader_plugin == "y": + assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_reader.py").is_file() + if include_writer_plugin == "y": + assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_writer.py").is_file() + if include_sample_data_plugin == "y": + assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_sample_data.py").is_file() + if include_widget_plugin == "y": + assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_widget.py").is_file() + + # if all are `n` there are no modules or tests + if not (include_reader_plugin == "n" and include_writer_plugin == "n" and include_sample_data_plugin == "n" and include_widget_plugin == "n"): + run_tox(str(result.project_path)) def test_run_cookiecutter_and_plugin_tests_with_napari_prefix(cookies, capsys): From 531066cd574cfe3eb4a30de4a4add6ed3432aa91 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 20 Feb 2024 21:48:48 +1100 Subject: [PATCH 2/3] Apply @czaki's suggestions Co-authored-by: Grzegorz Bokota --- tests/test_create_template.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index 905aae9..5efcaa4 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -41,17 +41,18 @@ def test_run_cookiecutter_and_plugin_tests(cookies, capsys, include_reader_plugi assert result.project_path.joinpath("src").is_dir() assert result.project_path.joinpath("src", "foo_bar", "__init__.py").is_file() + test_path = result.project_path.joinpath("src", "foo_bar", "_tests") if include_reader_plugin == "y": - assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_reader.py").is_file() + assert (test_path / "test_reader.py").is_file() if include_writer_plugin == "y": - assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_writer.py").is_file() + assert (test_path / "test_writer.py").is_file() if include_sample_data_plugin == "y": - assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_sample_data.py").is_file() + assert (test_path / test_sample_data.py").is_file() if include_widget_plugin == "y": - assert result.project_path.joinpath("src", "foo_bar", "_tests", "test_widget.py").is_file() + assert (test_path / "test_widget.py").is_file() # if all are `n` there are no modules or tests - if not (include_reader_plugin == "n" and include_writer_plugin == "n" and include_sample_data_plugin == "n" and include_widget_plugin == "n"): + if "y" in {include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin}: run_tox(str(result.project_path)) From b4f964ec0f161a00301b29fb853aa889b17ff5fb Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Tue, 20 Feb 2024 12:44:22 +0100 Subject: [PATCH 3/3] Update tests/test_create_template.py --- tests/test_create_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_create_template.py b/tests/test_create_template.py index 5efcaa4..3b5f0b7 100644 --- a/tests/test_create_template.py +++ b/tests/test_create_template.py @@ -47,7 +47,7 @@ def test_run_cookiecutter_and_plugin_tests(cookies, capsys, include_reader_plugi if include_writer_plugin == "y": assert (test_path / "test_writer.py").is_file() if include_sample_data_plugin == "y": - assert (test_path / test_sample_data.py").is_file() + assert (test_path / "test_sample_data.py").is_file() if include_widget_plugin == "y": assert (test_path / "test_widget.py").is_file()