|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import os |
| 4 | +import re |
| 5 | +import subprocess |
| 6 | +from pathlib import Path |
| 7 | +from typing import List, Tuple |
| 8 | + |
| 9 | +import nox |
| 10 | +from nox.sessions import Session |
| 11 | + |
| 12 | + |
| 13 | +HERE = Path(__file__).parent |
| 14 | +POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$") |
| 15 | + |
| 16 | + |
| 17 | +@nox.session(reuse_venv=True) |
| 18 | +def manage(session: Session) -> None: |
| 19 | + session.install("-r", "requirements.txt") |
| 20 | + session.install("idom[stable]") |
| 21 | + session.install("-e", ".") |
| 22 | + session.chdir("tests") |
| 23 | + |
| 24 | + build_js_on_commands = ["runserver"] |
| 25 | + if set(session.posargs).intersection(build_js_on_commands): |
| 26 | + session.run("python", "manage.py", "build_js") |
| 27 | + |
| 28 | + session.run("python", "manage.py", *session.posargs) |
| 29 | + |
| 30 | + |
| 31 | +@nox.session(reuse_venv=True) |
| 32 | +def format(session: Session) -> None: |
| 33 | + install_requirements_file(session, "check-style") |
| 34 | + session.run("black", ".") |
| 35 | + session.run("isort", ".") |
| 36 | + |
| 37 | + |
| 38 | +@nox.session |
| 39 | +def test(session: Session) -> None: |
| 40 | + """Run the complete test suite""" |
| 41 | + session.install("--upgrade", "pip", "setuptools", "wheel") |
| 42 | + session.notify("test_suite", posargs=session.posargs) |
| 43 | + session.notify("test_style") |
| 44 | + |
| 45 | + |
| 46 | +@nox.session |
| 47 | +def test_suite(session: Session) -> None: |
| 48 | + """Run the Python-based test suite""" |
| 49 | + install_requirements_file(session, "test-env") |
| 50 | + session.install(".[all]") |
| 51 | + |
| 52 | + session.chdir(HERE / "tests") |
| 53 | + session.env["IDOM_DEBUG_MODE"] = "1" |
| 54 | + session.env["SELENIUM_HEADLESS"] = str(int("--headless" in session.posargs)) |
| 55 | + session.run("python", "manage.py", "build_js") |
| 56 | + session.run("python", "manage.py", "test") |
| 57 | + |
| 58 | + |
| 59 | +@nox.session |
| 60 | +def test_style(session: Session) -> None: |
| 61 | + """Check that style guidelines are being followed""" |
| 62 | + install_requirements_file(session, "check-style") |
| 63 | + session.run("flake8", "src/django_idom", "tests") |
| 64 | + black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist" |
| 65 | + session.run( |
| 66 | + "black", |
| 67 | + ".", |
| 68 | + "--check", |
| 69 | + "--exclude", |
| 70 | + rf"/({black_default_exclude}|venv|node_modules)/", |
| 71 | + ) |
| 72 | + session.run("isort", ".", "--check-only") |
| 73 | + |
| 74 | + |
| 75 | +def install_requirements_file(session: Session, name: str) -> None: |
| 76 | + file_path = HERE / "requirements" / (name + ".txt") |
| 77 | + assert file_path.exists(), f"requirements file {file_path} does not exist" |
| 78 | + session.install("-r", str(file_path)) |
0 commit comments