Skip to content

Commit 3bc4687

Browse files
committed
Appropriate formatting for __init__ file. REALLY run the pre-commits in the unit tests.
1 parent 97e4458 commit 3bc4687

File tree

3 files changed

+23
-87
lines changed

3 files changed

+23
-87
lines changed

python-project-template/.pre-commit-config.yaml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ repos:
139139
{%- endif %}
140140
]
141141
{%- endif %}
142-
{%- if include_notebooks %}
142+
{%- if include_docs and include_notebooks %}
143143
# Make sure Sphinx can build the documentation while explicitly omitting
144144
# notebooks from the docs, so users don't have to wait through the execution
145145
# of each notebook or each commit. By default, these will be checked in the
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from ._version import __version__
21
{% if create_example_module -%}
2+
from ._version import __version__
33
from .example_module import greetings, meaning
44

5-
__all__ = ["greetings", "meaning"]
5+
__all__ = ["greetings", "meaning", "__version__"]
6+
{% else -%}
7+
from ._version import __version__
8+
9+
__all__ = ["__version__"]
610
{% endif -%}

tests/test_package_creation.py

Lines changed: 16 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""Verify package creation using `pytest-copie`"""
22

3+
import os
34
import subprocess
45

56
import pytest
67

8+
os.environ["SKIP"] = "no-commit-to-branch,check-added-large-files"
9+
710

811
def create_project_with_basic_checks(copie, extra_answers, package_name="example_package"):
912
"""Create the project using copier. Perform a handful of basic checks on the created directory."""
@@ -24,12 +27,6 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
2427
)
2528
assert build_results.returncode == 0
2629

27-
# pyproject_toml_is_valid
28-
precommit_results = subprocess.run(
29-
["pre-commit", "run", "validate-pyproject"], cwd=result.project_dir, check=False
30-
)
31-
assert precommit_results.returncode == 0
32-
3330
# directory_structure_is_correct
3431
assert (result.project_dir / f"src/{package_name}").is_dir() and (
3532
result.project_dir / f"tests/{package_name}"
@@ -54,81 +51,17 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
5451
print("Required file not generated:", file)
5552
assert all_found
5653

57-
# black_runs_successfully for src and tests
58-
black_results = subprocess.run(
59-
["python", "-m", "black", "--check", "--verbose", result.project_dir],
60-
cwd=result.project_dir,
61-
check=False,
62-
)
63-
assert black_results.returncode == 0
64-
65-
return result
66-
67-
68-
def pylint_runs_successfully(result):
69-
"""Test to ensure that the pylint linter runs successfully on the project"""
70-
# run pylint to ensure that the hydrated files are linted correctly
71-
pylint_src_results = subprocess.run(
72-
[
73-
"python",
74-
"-m",
75-
"pylint",
76-
"--recursive=y",
77-
"--rcfile=./src/.pylintrc",
78-
(result.project_dir / "src"),
79-
],
80-
cwd=result.project_dir,
81-
check=False,
82-
)
83-
84-
pylint_test_results = subprocess.run(
85-
[
86-
"python",
87-
"-m",
88-
"pylint",
89-
"--recursive=y",
90-
"--rcfile=./tests/.pylintrc",
91-
(result.project_dir / "tests"),
92-
],
93-
cwd=result.project_dir,
94-
check=False,
95-
)
96-
97-
return pylint_src_results.returncode == 0 and pylint_test_results.returncode == 0
98-
99-
100-
def docs_build_successfully(result):
101-
"""Test that we can build the doc tree.
102-
103-
!!! NOTE - This doesn't currently work because we need to `pip install` the hydrated
104-
project before running the tests. And we don't have a way to create a temporary
105-
virtual environment for the project.
106-
"""
107-
108-
required_files = [
109-
".readthedocs.yml",
110-
]
111-
all_found = True
112-
for file in required_files:
113-
if not (result.project_dir / file).is_file():
114-
all_found = False
115-
print("Required file not generated:", file)
116-
return all_found
117-
118-
# sphinx_results = subprocess.run(
119-
# ["make", "html"],
120-
# cwd=(result.project_dir / "docs"),
121-
# )
122-
123-
# return sphinx_results.returncode == 0
54+
## Initialize local git repository and add ALL new files to it.
55+
git_results = subprocess.run(["git", "init", "."], cwd=result.project_dir, check=False)
56+
assert git_results.returncode == 0
57+
git_results = subprocess.run(["git", "add", "."], cwd=result.project_dir, check=False)
58+
assert git_results.returncode == 0
12459

60+
## This will run ALL of the relevant pre-commits (excludes only "no-commit-to-branch,check-added-large-files")
61+
precommit_results = subprocess.run(["pre-commit", "run", "-a"], cwd=result.project_dir, check=False)
62+
assert precommit_results.returncode == 0
12563

126-
def github_workflows_are_valid(result):
127-
"""Test to ensure that the GitHub workflows are valid"""
128-
workflows_results = subprocess.run(
129-
["pre-commit", "run", "check-github-workflows"], cwd=result.project_dir, check=False
130-
)
131-
return workflows_results.returncode == 0
64+
return result
13265

13366

13467
def test_all_defaults(copie):
@@ -139,7 +72,8 @@ def test_all_defaults(copie):
13972
result = create_project_with_basic_checks(copie, {})
14073

14174
# uses ruff instead of (black/isort/pylint)
142-
assert not pylint_runs_successfully(result)
75+
assert not (result.project_dir / "src/.pylintrc").is_file()
76+
assert not (result.project_dir / "tests/.pylintrc").is_file()
14377

14478
# check to see if the README file was hydrated with copier answers.
14579
found_line = False
@@ -163,7 +97,8 @@ def test_use_black_and_no_example_modules(copie):
16397
"create_example_module": False,
16498
}
16599
result = create_project_with_basic_checks(copie, extra_answers)
166-
assert pylint_runs_successfully(result)
100+
assert (result.project_dir / "src/.pylintrc").is_file()
101+
assert (result.project_dir / "tests/.pylintrc").is_file()
167102

168103
# make sure that the files that were not requested were not created
169104
assert not (result.project_dir / "src/example_package/example_module.py").is_file()
@@ -263,7 +198,6 @@ def test_doc_combinations(copie, doc_answers):
263198
# run copier to hydrate a temporary project
264199
result = create_project_with_basic_checks(copie, doc_answers)
265200

266-
assert docs_build_successfully(result)
267201
assert (result.project_dir / "docs").is_dir()
268202

269203

@@ -310,5 +244,3 @@ def test_github_workflows_schema(copie):
310244
"include_docs": True,
311245
}
312246
result = create_project_with_basic_checks(copie, extra_answers)
313-
314-
assert github_workflows_are_valid(result)

0 commit comments

Comments
 (0)