Skip to content

Commit

Permalink
test(lint): Add linting and run test on initial repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
teald committed Oct 24, 2024
1 parent 1f5ccd2 commit d151ea7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
39 changes: 39 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import os
import shutil
import tempfile

import nox

Expand Down Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions {{ cookiecutter.project_slug }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ repos:
- id: ruff
args: ['--fix']
- id: ruff-format
args: ['--check', '--diff']
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/tests/test_adclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d151ea7

Please sign in to comment.