Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] use parametrize to test plugins with every answer combo #174

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Czaki marked this conversation as resolved.
Show resolved Hide resolved
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
Loading