From ac47c3213058b571305090b784db2c619cd16f26 Mon Sep 17 00:00:00 2001 From: jmkerloch Date: Mon, 20 Feb 2023 17:50:30 +0100 Subject: [PATCH] wip(test): add test on GitHub actions wip(test): test with 172.17.0.1 postgres host wip(test): call pytest with python feat(test): test with GitHub action for coverage --- .github/workflows/unit-test.yml | 57 +++++++++++++++++++++++++++++++++ requirements/testing.txt | 3 ++ setup.cfg | 31 ++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/workflows/unit-test.yml create mode 100644 requirements/testing.txt create mode 100644 setup.cfg diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000..bfc4719 --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,57 @@ + +name: Unit tests + +on: + pull_request: + paths: + - ".github/workflows/unit-test.yml" + - "**/*.py" + +permissions: + contents: read + pull-requests: write + +env: + POSTGRES_VERSION: "15" + POSTGIS_VERSION: "3.0" + POSTGRES_DB: ign + POSTGRES_USER: ign + POSTGRES_PASSWORD: ign + POSTGRES_HOST: "172.17.0.1" + +jobs: + test: + name: Run unit tests + runs-on: ubuntu-latest + + container: 'ghcr.io/ignf/route-graph-generator:develop' + + services: + postgis: + image: postgis/postgis # unable to handle var in image name. Was: "postgis/postgis:${POSTGRES_VERSION}-${POSTGIS_VERSION}-alpine" + env: + POSTGRES_DB: ign # mandatory duplicate + POSTGRES_USER: ign # mandatory duplicate + POSTGRES_PASSWORD: ign # mandatory duplicate + ports: + # Maps tcp port 5555 on service container to the host + - 5555:5432 + + steps: + + - uses: actions/checkout@v3 + + - name: Install test dependencies + run: | + pip install -r requirements/testing.txt + + - name: Run test + run: | + python -m pytest + + - name: Get Coverage + uses: orgoro/coverage@v3 + with: + coverageFile: coverage.xml + token: ${{ secrets.GITHUB_TOKEN }} + diff --git a/requirements/testing.txt b/requirements/testing.txt new file mode 100644 index 0000000..b90c448 --- /dev/null +++ b/requirements/testing.txt @@ -0,0 +1,3 @@ +# Testing dependencies +# -------------------- +pytest-cov>=4,<5 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d10e343 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,31 @@ +# -- Tests ---------------------------------------------- +[tool:pytest] +addopts = + --junitxml=junit/test-results.xml + --cov-config=setup.cfg + --cov=r2gg + --cov-report=html + --cov-report=term + --cov-report=xml + --ignore=tests/_wip/ +junit_family = xunit2 +norecursedirs = .* build dev development dist docs CVS fixtures _darcs {arch} *.egg venv _wip +python_files = test_*.py +testpaths = tests + +[coverage:run] +branch = True +omit = + .venv/* + docs/* + *tests* + +[coverage:report] +exclude_lines = + if self.debug: + pragma: no cover + raise NotImplementedError + if __name__ == .__main__.: + +ignore_errors = True +show_missing = True