Skip to content

Commit

Permalink
Use nox for test automation (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed May 9, 2022
1 parent 750c30d commit 7d13824
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
17 changes: 4 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
Expand All @@ -36,9 +34,8 @@ jobs:
architecture: x64

- run: |
python -m venv venv
venv/bin/pip install -r requirements_test.txt
venv/bin/py.test tests/
pip install nox==2022.1.7 poetry==1.1.13
nox -rs tests
coverage:

Expand All @@ -55,14 +52,8 @@ jobs:
architecture: x64

- run: |
python -m venv venv
venv/bin/pip install -r requirements_test.txt
venv/bin/py.test \
-s \
--verbose \
--cov-report term-missing \
--cov-report xml \
--cov=aioguardian tests
pip install nox==2022.1.7 poetry==1.1.13
nox -rs coverage
- uses: codecov/codecov-action@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
.DS_Store
.coverage
.mypy_cache
.tox/
.nox
.tox
.venv
__pycache__/
__pycache__
coverage.xml
dist/
docs/_build
poetry.lock
tags
5 changes: 4 additions & 1 deletion aioguardian/errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Define exception types for ``aioguardian``."""
from __future__ import annotations

from aioguardian.helpers.command import Command
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from aioguardian.helpers.command import Command

ERROR_CODE_MAPPING = {
3: "sensor_not_paired",
Expand Down
54 changes: 54 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Define nox actions."""
import tempfile
from typing import Any

import nox


def install_with_constraints(session: nox.sessions.Session, *args: str, **kwargs: Any):
"""Install PyPI packages based on pyproject.toml constraints."""
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)


@nox.session
def coverage(session: nox.sessions.Session) -> None:
"""Run all tests."""
args = session.posargs or [
"-s",
"--cov=aioguardian",
"--cov-report=term-missing",
"--cov-report=xml",
"tests/",
]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "aresponses", "pytest", "pytest-aiohttp", "pytest-cov"
)
session.run("pytest", *args)


@nox.session
def docs(session: nox.sessions.Session) -> None:
"""Generate a local copy of the docs."""
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(session, "Sphinx", "sphinx-rtd-theme")
session.run("sphinx-build", "./docs", "./docs/_build")


@nox.session
def tests(session: nox.sessions.Session) -> None:
"""Run all tests."""
args = session.posargs or ["-s", "tests/"]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(session, "aresponses", "pytest", "pytest-aiohttp")
session.run("pytest", *args)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ voluptuous = ">=0.11.7"
[tool.poetry.dev-dependencies]
Sphinx = "^4.0.0"
asynctest = "^0.13.0"
nox = "^2022.1.7"
pre-commit = "^2.0.1"
pytest = "^7.0.0"
pytest-aiohttp = "^1.0.0"
Expand Down
8 changes: 0 additions & 8 deletions requirements_test.txt

This file was deleted.

0 comments on commit 7d13824

Please sign in to comment.