Skip to content

Commit 7c3918c

Browse files
author
a.pirogov
committed
move sanity-checks from the pytest into the post-generation hook (workaround)
1 parent 7666e6b commit 7c3918c

2 files changed

Lines changed: 17 additions & 41 deletions

File tree

src/fair_python_cookiecutter/template/hooks/post_gen_project.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ rm tests/test_api.py
2727
# finalize repo setup
2828
git init
2929

30-
poetry install --with docs
30+
# make sure we are not in some venv (or poetry would just use that!)
31+
if pip -V | grep poetry; then
32+
env=$(pip -V | awk '{print $4}' | sed 's/\/lib\/.*//')
33+
echo WARNING: deactivating currently active virtual environment "$env"
34+
source "$env/bin/activate"
35+
deactivate
36+
fi
37+
38+
poetry install --with docs # install everything into a new venv
3139
poetry run poe init-dev # init git repo + register pre-commit
3240
poetry run pip install pipx # install pipx into venv without adding it as dep
3341
poetry run pipx run reuse download --all # get license files for REUSE compliance
@@ -49,3 +57,9 @@ poetry run git commit \
4957

5058
# make sure that the default branch is called 'main'
5159
git branch -M main
60+
61+
# sanity-check that main tasks all work
62+
poetry install --with docs
63+
poetry run poe lint --all-files
64+
poetry run poe test
65+
poetry run poe docs

tests/test_main.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,9 @@
11
import subprocess
22
import sys
33

4-
from fair_python_cookiecutter.main import create_repository, CookiecutterConfig
5-
from fair_python_cookiecutter.utils import TempDir
6-
7-
8-
def sanity_check_project(proj_path):
9-
"""Sanity-check a generated project (linters, tests, doc generation)."""
10-
try:
11-
subprocess.check_output(
12-
"poetry install --with docs".split(), cwd=proj_path, stderr=subprocess.PIPE
13-
)
14-
subprocess.check_output(
15-
"poetry run poe lint --all-files".split(),
16-
cwd=proj_path,
17-
stderr=subprocess.PIPE,
18-
)
19-
subprocess.check_output(
20-
"poetry run poe test".split(), cwd=proj_path, stderr=subprocess.PIPE
21-
)
22-
subprocess.check_output(
23-
"poetry run poe docs".split(), cwd=proj_path, stderr=subprocess.PIPE
24-
)
25-
except subprocess.CalledProcessError as e:
26-
print("exit code: {}".format(e.returncode))
27-
print("stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding())))
4+
import pytest
285

29-
30-
# def test_defaults(tmp_path):
31-
# # generate with default values
32-
# conf = CookiecutterConfig()
33-
# dir = create_repository(conf, tmp_path)
34-
# sanity_check_project(dir)
35-
36-
# # should NOT have the code files
37-
# assert not (dir / f"src/{DEMO_PROJ_SLUG}api.py").is_file()
38-
# assert not (dir / f"src/{DEMO_PROJ_SLUG}/cli.py").is_file()
39-
# assert not (dir / "tests/test_api.py").is_file()
40-
# assert not (dir / "tests/test_cli.py").is_file()
41-
# # and the expected license (MIT)
42-
# first_license_line = open(dir / "LICENSE", "r").readline()
43-
# assert first_license_line.find("MIT") >= 0
6+
from fair_python_cookiecutter.main import create_repository, CookiecutterConfig
447

458

469
def test_configured(tmp_path):
@@ -51,7 +14,6 @@ def test_configured(tmp_path):
5114
)
5215
DEMO_PROJ_PKG = "my_project"
5316
dir = create_repository(conf, tmp_path)
54-
sanity_check_project(dir)
5517

5618
# should have the code files
5719
assert (dir / f"src/{DEMO_PROJ_PKG}/api.py").is_file()

0 commit comments

Comments
 (0)