Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
[MAINT] use parametrize to test plugins with every answer combo (#174)
Browse files Browse the repository at this point in the history
* use parametrize to test plugins with every answer combo

* Apply @Czaki's suggestions

Co-authored-by: Grzegorz Bokota <[email protected]>

* Update tests/test_create_template.py

---------

Co-authored-by: Juan Nunez-Iglesias <[email protected]>
Co-authored-by: Grzegorz Bokota <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent 6343bd4 commit d6efeb2
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions tests/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,41 @@ 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
assert result.project_path.name == "foo-bar"
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))
test_path = result.project_path.joinpath("src", "foo_bar", "_tests")
if include_reader_plugin == "y":
assert (test_path / "test_reader.py").is_file()
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()
if include_widget_plugin == "y":
assert (test_path / "test_widget.py").is_file()

# if all are `n` there are no modules or tests
if "y" in {include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin}:
run_tox(str(result.project_path))


def test_run_cookiecutter_and_plugin_tests_with_napari_prefix(cookies, capsys):
Expand Down

0 comments on commit d6efeb2

Please sign in to comment.