Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit 8a70f0b

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #82 from staticdev/tests-upgrade
Tests upgrade
2 parents 4831f9e + e3752a3 commit 8a70f0b

3 files changed

Lines changed: 103 additions & 28 deletions

File tree

.github/dependabot.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
version: 2
22
updates:
3-
- package-ecosystem: github-actions
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: '09:00'
8-
open-pull-requests-limit: 10
9-
- package-ecosystem: pip
10-
directory: "/.github/workflows"
11-
schedule:
12-
interval: daily
13-
time: '09:00'
14-
open-pull-requests-limit: 10
15-
- package-ecosystem: pip
16-
directory: "/"
17-
schedule:
18-
interval: daily
19-
time: '09:00'
20-
open-pull-requests-limit: 10
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "09:00"
8+
open-pull-requests-limit: 10
9+
- package-ecosystem: pip
10+
directory: "/.github/workflows"
11+
schedule:
12+
interval: daily
13+
time: "09:00"
14+
open-pull-requests-limit: 10
15+
- package-ecosystem: pip
16+
directory: "/"
17+
schedule:
18+
interval: daily
19+
time: "09:00"
20+
open-pull-requests-limit: 10

.github/workflows/tests.yml

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on:
4+
- push
5+
- pull_request
46

57
jobs:
68
tests:
7-
name: Tests (${{ matrix.python-version }}, ${{ matrix.os }})
9+
name: ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }}
810
runs-on: ${{ matrix.os }}
911
strategy:
1012
fail-fast: false
1113
matrix:
1214
include:
13-
- { python-version: 3.8, os: ubuntu-latest }
14-
# - { python-version: 3.8, os: windows-latest }
15-
- { python-version: 3.8, os: macos-latest }
16-
- { python-version: 3.7, os: ubuntu-latest }
15+
- { python-version: 3.8, os: ubuntu-latest, session: "pre-commit" }
16+
- { python-version: 3.8, os: ubuntu-latest, session: "safety" }
17+
- { python-version: 3.8, os: ubuntu-latest, session: "mypy" }
18+
- { python-version: 3.7, os: ubuntu-latest, session: "mypy" }
19+
- { python-version: 3.8, os: ubuntu-latest, session: "tests" }
20+
- { python-version: 3.7, os: ubuntu-latest, session: "tests" }
21+
# - { python-version: 3.8, os: windows-latest, session: "tests" }
22+
- { python-version: 3.8, os: macos-latest, session: "tests" }
23+
# - { python-version: 3.8, os: ubuntu-latest, session: "docs" }
24+
25+
env:
26+
NOXSESSION: ${{ matrix.session }}
27+
1728
steps:
1829
- name: Check out the repository
19-
uses: actions/checkout@v2.1.0
30+
uses: actions/checkout@v2.1.1
2031

2132
- name: Set up Python ${{ matrix.python-version }}
2233
uses: actions/setup-python@v2
@@ -38,10 +49,41 @@ jobs:
3849
pip install --constraint=.github/workflows/constraints.txt nox
3950
nox --version
4051
52+
- name: Compute pre-commit cache key
53+
if: matrix.session == 'pre-commit'
54+
id: pre-commit-cache
55+
shell: python
56+
run: |
57+
import hashlib
58+
import sys
59+
60+
python = "py{}.{}".format(*sys.version_info[:2])
61+
payload = sys.version.encode() + sys.executable.encode()
62+
digest = hashlib.sha256(payload).hexdigest()
63+
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
64+
65+
print("::set-output name=result::{}".format(result))
66+
67+
- name: Restore pre-commit cache
68+
uses: actions/cache@v1.2.0
69+
if: matrix.session == 'pre-commit'
70+
with:
71+
path: ~/.cache/pre-commit
72+
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
73+
restore-keys: |
74+
${{ steps.pre-commit-cache.outputs.result }}-
75+
4176
- name: Run Nox
4277
run: |
4378
nox --force-color
4479
80+
# - name: Upload documentation
81+
# if: matrix.session == 'docs'
82+
# uses: actions/upload-artifact@v2
83+
# with:
84+
# name: docs
85+
# path: docs/_build
86+
4587
- name: Create coverage report
4688
if: always() && matrix.session == 'tests'
4789
run: |

noxfile.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Nox sessions."""
22
import contextlib
3+
import shutil
34
import tempfile
45
from pathlib import Path
56
from typing import cast
@@ -10,7 +11,7 @@
1011

1112

1213
package = "toml_validator"
13-
python_versions = ["3.8"]
14+
python_versions = ["3.7", "3.8"]
1415
nox.options.sessions = "pre-commit", "safety", "mypy", "tests"
1516
locations = "src", "tests", "noxfile.py"
1617

@@ -139,8 +140,10 @@ def tests(session: Session) -> None:
139140
"""Run the test suite."""
140141
install_package(session)
141142
install(session, "coverage[toml]", "pytest", "pytest_mock")
142-
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
143-
session.notify("coverage")
143+
try:
144+
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
145+
finally:
146+
session.notify("coverage")
144147

145148

146149
@nox.session
@@ -159,3 +162,33 @@ def typeguard(session: Session) -> None:
159162
install_package(session)
160163
install(session, "pytest", "typeguard", "pytest_mock")
161164
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
165+
166+
167+
@nox.session(python=python_versions)
168+
def xdoctest(session: Session) -> None:
169+
"""Run examples with xdoctest."""
170+
args = session.posargs or ["all"]
171+
install_package(session)
172+
install(session, "xdoctest")
173+
session.run("python", "-m", "xdoctest", package, *args)
174+
175+
176+
@nox.session(python="3.8")
177+
def docs(session: Session) -> None:
178+
"""Build the documentation."""
179+
args = session.posargs or ["docs", "docs/_build"]
180+
181+
if session.interactive and not session.posargs:
182+
args.insert(0, "--open-browser")
183+
184+
builddir = Path("docs", "_build")
185+
if builddir.exists():
186+
shutil.rmtree(builddir)
187+
188+
install_package(session)
189+
install(session, "sphinx", "sphinx-autobuild")
190+
191+
if session.interactive:
192+
session.run("sphinx-autobuild", *args)
193+
else:
194+
session.run("sphinx-build", *args)

0 commit comments

Comments
 (0)