22import pytest_copie
33import subprocess
44
5+
56def successfully_created_project (result ):
67 """Basic assertions that indicate the copier was able to create a project"""
78 return result .exit_code == 0 and result .exception is None and result .project_dir .is_dir ()
89
910
10- def directory_structure_is_correct (result , package_name = "example_package" ):
11+ def directory_structure_is_correct (result , package_name = "example_package" ):
1112 """Test to ensure that the default directory structure ws created correctly"""
12- return (result .project_dir / f"src/{ package_name } " ).is_dir () and (result .project_dir / f"tests/{ package_name } " ).is_dir ()
13+ return (result .project_dir / f"src/{ package_name } " ).is_dir () and (
14+ result .project_dir / f"tests/{ package_name } "
15+ ).is_dir ()
1316
1417
1518def black_runs_successfully (result ):
1619 """Test to ensure that the black linter runs successfully on the project"""
1720 # run black with `--check` to look for lint errors, but don't fix them.
1821 black_results = subprocess .run (
19- ["python" , "-m" , "black" , "--check" , (result .project_dir / "src" )],
20- cwd = result .project_dir
22+ ["python" , "-m" , "black" , "--check" , (result .project_dir / "src" )], cwd = result .project_dir
2123 )
2224
2325 return black_results .returncode == 0
@@ -27,27 +29,21 @@ def pylint_runs_successfully(result):
2729 """Test to ensure that the pylint linter runs successfully on the project"""
2830 # run pylint to ensure that the hydrated files are linted correctly
2931 pylint_results = subprocess .run (
30- ["python" , "-m" , "pylint" ,
31- "--recursive=y" ,
32- "--rcfile=./src/.pylintrc" ,
33- (result .project_dir / "src" )],
34- cwd = result .project_dir
32+ ["python" , "-m" , "pylint" , "--recursive=y" , "--rcfile=./src/.pylintrc" , (result .project_dir / "src" )],
33+ cwd = result .project_dir ,
3534 )
3635
3736 return pylint_results .returncode == 0
3837
3938
40- def unit_tests_in_project_run_successfully (result , package_name = "example_package" ):
39+ def unit_tests_in_project_run_successfully (result , package_name = "example_package" ):
4140 """Test to ensure that the unit tests run successfully on the project
4241
4342 !!! NOTE - This doesn't currently work because we need to `pip install` the hydrated
4443 project before running the tests. And we don't have a way to create a temporary
4544 virtual environment for the project.
4645 """
47- pytest_results = subprocess .run (
48- ["python" , "-m" , "pytest" ],
49- cwd = result .project_dir
50- )
46+ pytest_results = subprocess .run (["python" , "-m" , "pytest" ], cwd = result .project_dir )
5147
5248 return pytest_results .returncode == 0
5349
@@ -73,10 +69,10 @@ def test_all_defaults(copie):
7369 # check to see if the README file was hydrated with copier answers.
7470 found_line = False
7571 with open (result .project_dir / "README.md" ) as f :
76- for line in f :
77- if "example_project" in line :
78- found_line = True
79- break
72+ for line in f :
73+ if "example_project" in line :
74+ found_line = True
75+ break
8076 assert found_line
8177
8278
@@ -107,15 +103,43 @@ def test_use_black_and_no_example_modules(copie):
107103 # check to see if the pyproject.toml file has the expected dependencies
108104 found_line = False
109105 with open (result .project_dir / "pyproject.toml" ) as f :
110- for line in f :
111- if " \" black\ " , # Used for static linting of files" in line :
112- found_line = True
113- break
106+ for line in f :
107+ if '" black", # Used for static linting of files' in line :
108+ found_line = True
109+ break
114110 assert found_line
115111
116112 assert black_runs_successfully (result )
117113
118114
115+ @pytest .mark .parametrize (
116+ "enforce_style" ,
117+ [
118+ [],
119+ ["ruff_lint" ],
120+ ["ruff_format" ],
121+ ["ruff_lint" , "pylint" ],
122+ ["ruff_format" , "black" ],
123+ ["black" , "pylint" , "isort" ],
124+ ["ruff_lint" , "ruff_format" ],
125+ ["black" , "pylint" , "isort" , "ruff_lint" , "ruff_format" ],
126+ ],
127+ )
128+ def test_code_style_combinations (copie , enforce_style ):
129+ """Test that various combinations of code style enforcement will
130+ still result in a valid project being created."""
131+
132+ # provide a dictionary of the non-default answers to use
133+ extra_answers = {
134+ "enforce_style" : enforce_style ,
135+ }
136+ result = copie .copy (extra_answers = extra_answers )
137+ assert successfully_created_project (result )
138+ assert directory_structure_is_correct (result )
139+ # black would still run successfully.
140+ assert black_runs_successfully (result )
141+
142+
119143def test_smoke_test_notification (copie ):
120144 """Confirm we can generate a "smoke_test.yaml" file, with all
121145 notification mechanisms selected."""
@@ -130,4 +154,4 @@ def test_smoke_test_notification(copie):
130154
131155 assert successfully_created_project (result )
132156 assert directory_structure_is_correct (result )
133- assert black_runs_successfully (result )
157+ assert black_runs_successfully (result )
0 commit comments