Skip to content

Commit

Permalink
HAPI-225 add testing infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
turnerm committed Oct 13, 2023
1 parent 45247e2 commit 79bf484
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .config/coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[run]
source = src

omit = */_version.py

[report]
exclude_also =
from ._version
def __repr__
if self.debug:
if settings.DEBUG
raise AssertionError
raise NotImplementedError
if 0:
if __name__ == .__main__.:
if TYPE_CHECKING:
@(abc\.)?abstractmethod
4 changes: 4 additions & 0 deletions .config/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
pythonpath = ../src
addopts = "--color=yes"
log_cli = 1
48 changes: 48 additions & 0 deletions .github/workflows/run-python-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow will install Python dependencies, lint and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run tests

on:
workflow_dispatch: # add run button in github
push:
branches-ignore:
- gh-pages
- 'dependabot/**'
pull_request:
branches-ignore:
- gh-pages

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade hatch
- name: Test with hatch/pytest
run: |
hatch run test:test
- name: Check styling
if: always()
run: |
hatch run lint:style
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
junit_files: test-results.xml
- name: Publish in Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: tests
format: lcov
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Homepage = "https://github.com/OCHA-DAP/hapi-schemas"

[project.optional-dependencies]
database = ["hdx-python-database>=1.2.8"]
dev = ["pre-commit"]
test = ["pytest", "pytest-cov"]

#########
# Hatch #
Expand All @@ -64,3 +66,31 @@ source = "vcs"
[tool.hatch.version.raw-options]
local_scheme = "no-local-version"
version_scheme = "python-simplified-semver"

# Tests

[tool.hatch.envs.test]
features = ["test"]

[tool.hatch.envs.test.scripts]
test = """
pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
--cov --cov-config=.config/coveragerc --no-cov-on-fail \
--cov-report=lcov --cov-report=term-missing
"""

[[tool.hatch.envs.test.matrix]]
python = ["3.11"]

[tool.hatch.envs.lint]
detached = true
dependencies = [
"black",
"ruff",
]

[tool.hatch.envs.lint.scripts]
style = [
"ruff --config .config/ruff.toml {args:.}",
"black --config .config/black.toml --check --diff {args:.}",
]
35 changes: 35 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,48 @@
#
# pip-compile --all-extras --output-file=requirements.txt pyproject.toml
#
cfgv==3.4.0
# via pre-commit
coverage[toml]==7.3.2
# via pytest-cov
distlib==0.3.7
# via virtualenv
filelock==3.12.4
# via virtualenv
greenlet==3.0.0
# via sqlalchemy
hdx-python-database==1.2.8
# via hapi-schema (pyproject.toml)
identify==2.5.30
# via pre-commit
iniconfig==2.0.0
# via pytest
nodeenv==1.8.0
# via pre-commit
packaging==23.2
# via pytest
platformdirs==3.11.0
# via virtualenv
pluggy==1.3.0
# via pytest
pre-commit==3.4.0
# via hapi-schema (pyproject.toml)
pytest==7.4.2
# via
# hapi-schema (pyproject.toml)
# pytest-cov
pytest-cov==4.1.0
# via hapi-schema (pyproject.toml)
pyyaml==6.0.1
# via pre-commit
sqlalchemy==2.0.22
# via
# hapi-schema (pyproject.toml)
# hdx-python-database
typing-extensions==4.8.0
# via sqlalchemy
virtualenv==20.24.5
# via pre-commit

# The following packages are considered to be unsafe in a requirements file:
# setuptools

0 comments on commit 79bf484

Please sign in to comment.