diff --git a/noxfile.py b/noxfile.py index 3a059f3..58b274d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,6 +3,7 @@ from pathlib import Path import os import shutil +import tempfile import nox @@ -116,3 +117,41 @@ def test_filled_template(session: nox.Session): # Run the tests. session.run("nox", "-s", "tests", "--verbose") + + +@nox.session() +def test_lint_run_template(session: nox.Session): + """Creates a new repo from template and lints it.""" + session.install("cookiecutter", "pre-commit", "nox") + + # Need to not use nox' temporary directories to avoid submodule issues. + with tempfile.TemporaryDirectory() as tmp_dir_name: + tmp_dir = Path(tmp_dir_name) + + template_dir = Path(".").resolve() + + with session.chdir(".."): + session.run( + "cookiecutter", + "--no-input", + "--default-config", + str(template_dir), + "-o", + str(tmp_dir), + ) + + new_package_path = tmp_dir / "default_instrument_name_dr_package" + + with session.chdir(tmp_dir): + assert new_package_path.exists() + + with session.chdir(new_package_path): + session.run("git", "init", external=True) + session.run("git", "add", ".", external=True) + session.run( + "pre-commit", + "run", + "-c", + "./.pre-commit-config.yaml", + "--all-files", + ) diff --git a/{{ cookiecutter.project_slug }}/.pre-commit-config.yaml b/{{ cookiecutter.project_slug }}/.pre-commit-config.yaml index b6cd047..797b917 100644 --- a/{{ cookiecutter.project_slug }}/.pre-commit-config.yaml +++ b/{{ cookiecutter.project_slug }}/.pre-commit-config.yaml @@ -22,3 +22,4 @@ repos: - id: ruff args: ['--fix'] - id: ruff-format + args: ['--check', '--diff'] diff --git a/{{ cookiecutter.project_slug }}/tests/test_adclass.py b/{{ cookiecutter.project_slug }}/tests/test_adclass.py index 5115a62..90795a9 100644 --- a/{{ cookiecutter.project_slug }}/tests/test_adclass.py +++ b/{{ cookiecutter.project_slug }}/tests/test_adclass.py @@ -4,7 +4,7 @@ {{ cookiecutter.instrument_name }}_instruments/adclass.py. """ -from {{ cookiecutter.instrument_name_lower }}_instruments.{{ cookiecutter.instrument_name_lower }} import AstroData{{ cookiecutter.instrument_name_title }} +from {{ cookiecutter.instrument_name_lower }}_instruments.{{ cookiecutter.instrument_name_lower }} import AstroData{{ cookiecutter.instrument_name_title }} # fmt: skip def test_adclass_exists(): diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.instrument_name_lower }}_instruments/__init__.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.instrument_name_lower }}_instruments/__init__.py index add2e35..353fe4c 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.instrument_name_lower }}_instruments/__init__.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.instrument_name_lower }}_instruments/__init__.py @@ -1,6 +1,6 @@ # Import the modules under this package to trigger any class # registering that may be needed. -import astrodata +import astrodata # noqa: F401 -from . import {{ cookiecutter.instrument_name_lower }} +from . import {{ cookiecutter.instrument_name_lower }} # noqa: F401