Skip to content

Commit ce22809

Browse files
committed
Limit python versions.
1 parent 27d4683 commit ce22809

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
4+
5+
6+
def pytest_addoption(parser):
7+
parser.addoption("--python_version", action="store", default="3.12", choices=PYTHON_VERSIONS)
8+
9+
10+
@pytest.fixture(scope="session", name="python_version")
11+
def python_version(request):
12+
yield request.config.getoption("--python_version")
13+
14+
15+
@pytest.fixture
16+
def default_answers(python_version):
17+
return {"python_versions": [python_version]}

tests/test_package_creation.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
5252
assert all_found
5353

5454
## Initialize local git repository and add ALL new files to it.
55+
git_results = subprocess.run(
56+
["git", "config", "--global", "init.defaultBranch", "main"], cwd=result.project_dir, check=False
57+
)
58+
assert git_results.returncode == 0
5559
git_results = subprocess.run(["git", "init", "."], cwd=result.project_dir, check=False)
5660
assert git_results.returncode == 0
5761
git_results = subprocess.run(["git", "add", "."], cwd=result.project_dir, check=False)
@@ -64,12 +68,11 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
6468
return result
6569

6670

67-
def test_all_defaults(copie):
71+
def test_all_defaults(copie, default_answers):
6872
"""Test that the default values are used when no arguments are given.
6973
Ensure that the project is created and that the basic files exist.
7074
"""
71-
# run copier to hydrate a temporary project
72-
result = create_project_with_basic_checks(copie, {})
75+
result = create_project_with_basic_checks(copie, default_answers)
7376

7477
# uses ruff instead of (black/isort/pylint)
7578
assert not (result.project_dir / "src/.pylintrc").is_file()
@@ -85,18 +88,17 @@ def test_all_defaults(copie):
8588
assert found_line
8689

8790

88-
def test_use_black_and_no_example_modules(copie):
91+
def test_use_black_and_no_example_modules(copie, default_answers):
8992
"""We want to provide non-default arguments for the linter and example modules
9093
copier questions and ensure that the pyproject.toml file is created with Black
9194
and that no example modules are created.
9295
"""
93-
94-
# provide a dictionary of the non-default answers to use
95-
extra_answers = {
96+
extra_answers = default_answers | {
9697
"enforce_style": ["black", "pylint", "isort"],
9798
"create_example_module": False,
9899
}
99100
result = create_project_with_basic_checks(copie, extra_answers)
101+
100102
assert (result.project_dir / "src/.pylintrc").is_file()
101103
assert (result.project_dir / "tests/.pylintrc").is_file()
102104

@@ -126,12 +128,10 @@ def test_use_black_and_no_example_modules(copie):
126128
["black", "pylint", "isort", "ruff_lint", "ruff_format"],
127129
],
128130
)
129-
def test_code_style_combinations(copie, enforce_style):
131+
def test_code_style_combinations(copie, enforce_style, default_answers):
130132
"""Test that various combinations of code style enforcement will
131133
still result in a valid project being created."""
132-
133-
# provide a dictionary of the non-default answers to use
134-
extra_answers = {
134+
extra_answers = default_answers | {
135135
"enforce_style": enforce_style,
136136
}
137137
result = create_project_with_basic_checks(copie, extra_answers)
@@ -146,16 +146,13 @@ def test_code_style_combinations(copie, enforce_style):
146146
["email", "slack"],
147147
],
148148
)
149-
def test_smoke_test_notification(copie, notification):
149+
def test_smoke_test_notification(copie, notification, default_answers):
150150
"""Confirm we can generate a "smoke_test.yaml" file, with all
151151
notification mechanisms selected."""
152-
153-
# provide a dictionary of the non-default answers to use
154-
extra_answers = {
152+
extra_answers = default_answers | {
155153
"failure_notification": notification,
156154
}
157155

158-
# run copier to hydrate a temporary project
159156
result = create_project_with_basic_checks(copie, extra_answers)
160157

161158

@@ -169,13 +166,10 @@ def test_smoke_test_notification(copie, notification):
169166
["none"],
170167
],
171168
)
172-
def test_license(copie, license):
169+
def test_license(copie, license, default_answers):
173170
"""Confirm we get a valid project for different license options."""
171+
extra_answers = default_answers | {"license": license}
174172

175-
# provide a dictionary of the non-default answers to use
176-
extra_answers = {"license": license}
177-
178-
# run copier to hydrate a temporary project
179173
result = create_project_with_basic_checks(copie, extra_answers)
180174

181175

@@ -192,11 +186,10 @@ def test_license(copie, license):
192186
},
193187
],
194188
)
195-
def test_doc_combinations(copie, doc_answers):
189+
def test_doc_combinations(copie, doc_answers, default_answers):
196190
"""Confirm the docs directory is well-formed, when including docs."""
197-
198-
# run copier to hydrate a temporary project
199-
result = create_project_with_basic_checks(copie, doc_answers)
191+
extra_answers = default_answers | doc_answers
192+
result = create_project_with_basic_checks(copie, extra_answers)
200193

201194
assert (result.project_dir / "docs").is_dir()
202195

@@ -214,32 +207,29 @@ def test_doc_combinations(copie, doc_answers):
214207
},
215208
],
216209
)
217-
def test_doc_combinations_no_docs(copie, doc_answers):
210+
def test_doc_combinations_no_docs(copie, doc_answers, default_answers):
218211
"""Confirm there is no 'docs' directory, if not including docs."""
212+
extra_answers = default_answers | doc_answers
219213

220-
# run copier to hydrate a temporary project
221-
result = create_project_with_basic_checks(copie, doc_answers)
214+
result = create_project_with_basic_checks(copie, extra_answers)
222215

223216
assert not (result.project_dir / "docs").is_dir()
224217

225218

226219
@pytest.mark.parametrize("test_lowest_version", ["none", "direct", "all"])
227-
def test_test_lowest_version(copie, test_lowest_version):
220+
def test_test_lowest_version(copie, test_lowest_version, default_answers):
228221
"""Confirm we can generate a "testing_and_coverage.yaml" file, with all
229222
test_lowest_version mechanisms selected."""
230-
231-
# provide a dictionary of the non-default answers to use
232-
extra_answers = {
223+
extra_answers = default_answers | {
233224
"test_lowest_version": test_lowest_version,
234225
}
235226

236-
# run copier to hydrate a temporary project
237227
result = create_project_with_basic_checks(copie, extra_answers)
238228

239229

240-
def test_github_workflows_schema(copie):
230+
def test_github_workflows_schema(copie, default_answers):
241231
"""Confirm the current GitHub workflows have valid schemas."""
242-
extra_answers = {
232+
extra_answers = default_answers | {
243233
"include_benchmarks": True,
244234
"include_docs": True,
245235
}

0 commit comments

Comments
 (0)