diff --git a/requirements.txt b/requirements.txt index f5b71f6e5..e5d9e8879 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,5 +11,6 @@ flake8==3.7.6 # ------------------------------------------------------------------------------ tox==3.6.1 pytest==4.3.1 +pytest_cases==1.5.1 pytest-cookies==0.3.0 pyyaml==5.1 diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 061a0f28d..36395627f 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -2,6 +2,7 @@ import os import re import pytest +from pytest_cases import pytest_fixture_plus import sh import yaml from binaryornot.check import is_binary @@ -9,7 +10,7 @@ from binaryornot.check import is_binary PATTERN = "{{(\s?cookiecutter)[.](.*?)}}" RE_OBJ = re.compile(PATTERN) -BINARY_CHOICES = ["y", "n"] +YN_CHOICES = ["y", "n"] @pytest.fixture @@ -26,6 +27,35 @@ def context(): } +@pytest_fixture_plus +@pytest.mark.parametrize("windows", YN_CHOICES, ids=lambda yn: f"win:{yn}") +@pytest.mark.parametrize("use_docker", YN_CHOICES, ids=lambda yn: f"docker:{yn}") +@pytest.mark.parametrize("use_celery", YN_CHOICES, ids=lambda yn: f"celery:{yn}") +@pytest.mark.parametrize("use_mailhog", YN_CHOICES, ids=lambda yn: f"mailhog:{yn}") +@pytest.mark.parametrize("use_sentry", YN_CHOICES, ids=lambda yn: f"sentry:{yn}") +@pytest.mark.parametrize("use_compressor", YN_CHOICES, ids=lambda yn: f"cmpr:{yn}") +@pytest.mark.parametrize("use_whitenoise", YN_CHOICES, ids=lambda yn: f"wnoise:{yn}") +def context_combination( + windows, + use_docker, + use_celery, + use_mailhog, + use_sentry, + use_compressor, + use_whitenoise, +): + """Fixture that parametrize the function where it's used.""" + return { + "windows": windows, + "use_docker": use_docker, + "use_compressor": use_compressor, + "use_celery": use_celery, + "use_mailhog": use_mailhog, + "use_sentry": use_sentry, + "use_whitenoise": use_whitenoise, + } + + def build_files_list(root_dir): """Build a list containing absolute paths to the generated files.""" return [ @@ -50,36 +80,13 @@ def check_paths(paths): assert match is None, msg.format(path) -@pytest.mark.parametrize("windows", BINARY_CHOICES) -@pytest.mark.parametrize("use_docker", BINARY_CHOICES) -@pytest.mark.parametrize("use_celery", BINARY_CHOICES) -@pytest.mark.parametrize("use_mailhog", BINARY_CHOICES) -@pytest.mark.parametrize("use_sentry", BINARY_CHOICES) -@pytest.mark.parametrize("use_compressor", BINARY_CHOICES) -@pytest.mark.parametrize("use_whitenoise", BINARY_CHOICES) -def test_project_generation( - cookies, - context, - windows, - use_docker, - use_celery, - use_mailhog, - use_sentry, - use_compressor, - use_whitenoise, -): - result = cookies.bake( - extra_context={ - **context, - "windows": windows, - "use_docker": use_docker, - "use_compressor": use_compressor, - "use_celery": use_celery, - "use_mailhog": use_mailhog, - "use_sentry": use_sentry, - "use_whitenoise": use_whitenoise, - } - ) +def test_project_generation(cookies, context, context_combination): + """ + Test that project is generated and fully rendered. + + This is parametrized for each combination from ``context_combination`` fixture + """ + result = cookies.bake(extra_context={**context, **context_combination}) assert result.exit_code == 0 assert result.exception is None assert result.project.basename == context["project_slug"] @@ -90,35 +97,13 @@ def test_project_generation( check_paths(paths) -@pytest.mark.parametrize("windows", BINARY_CHOICES) -@pytest.mark.parametrize("use_docker", BINARY_CHOICES) -@pytest.mark.parametrize("use_celery", BINARY_CHOICES) -@pytest.mark.parametrize("use_mailhog", BINARY_CHOICES) -@pytest.mark.parametrize("use_sentry", BINARY_CHOICES) -@pytest.mark.parametrize("use_compressor", BINARY_CHOICES) -@pytest.mark.parametrize("use_whitenoise", BINARY_CHOICES) -def test_linting_passes( - cookies, - windows, - use_docker, - use_celery, - use_mailhog, - use_sentry, - use_compressor, - use_whitenoise, -): - """generated project should pass flake8 & black.""" - result = cookies.bake( - extra_context={ - "windows": windows, - "use_docker": use_docker, - "use_compressor": use_compressor, - "use_celery": use_celery, - "use_mailhog": use_mailhog, - "use_sentry": use_sentry, - "use_whitenoise": use_whitenoise, - } - ) +def test_linting_passes(cookies, context_combination): + """ + Generated project should pass flake8 & black. + + This is parametrized for each combination from ``context_combination`` fixture + """ + result = cookies.bake(extra_context=context_combination) try: sh.flake8(str(result.project))