diff options
author | Edmond Chuc <37032744+edmondchuc@users.noreply.github.com> | 2021-07-07 15:49:43 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-07 15:49:43 +1000 |
commit | f7313bf35455e3b3ede971214d5b67455596df30 (patch) | |
tree | 9dd0f352bfb633ecae5402d891628783a9db9b82 | |
parent | 538446e08f992b7fc333151367dd216611dcd8e3 (diff) | |
parent | b9d7c7202211bfcf15e9956bd3f25cb63dd6eb34 (diff) | |
download | rdflib-f7313bf35455e3b3ede971214d5b67455596df30.tar.gz |
Merge pull request #1352 from RDFLib/feat/tests-improve
Improve running tests locally
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | README.md | 37 | ||||
-rw-r--r-- | docker-compose.tests.yml | 16 | ||||
-rwxr-xr-x | run_tests.sh | 9 | ||||
-rwxr-xr-x | run_tests_with_coverage_report.sh | 9 | ||||
-rw-r--r-- | test/Dockerfile | 14 |
6 files changed, 95 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..7c484cfc --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +tests: + docker-compose -f docker-compose.tests.yml up test-runner + docker-compose -f docker-compose.tests.yml down + +build: + docker-compose -f docker-compose.tests.yml build + +coverage: + docker-compose -f docker-compose.tests.yml up test-runner-coverage + docker-compose -f docker-compose.tests.yml down
\ No newline at end of file @@ -183,6 +183,43 @@ You can also raise issues here: * <https://github.com/RDFLib/rdflib/issues> +## Running tests + +### Running the tests on the host + +Run the test suite with `nose`. +```shell +nosetests +``` + +### Running test coverage on the host with coverage report + +Run the test suite and generate a HTML coverage report with `nose` and `coverage`. +```shell +nosetests --with-timer --timer-top-n 42 --with-coverage --cover-tests --cover-package=rdflib +``` + +### Running the tests in a Docker container + +Run the test suite inside a Docker container for cross-platform support. This resolves issues such as installing BerkeleyDB on Windows and avoids the host and port issues on macOS. +```shell +make tests +``` + +Tip: If the underlying Dockerfile for the test runner changes, use `make build`. + +### Running the tests in a Docker container with coverage report + +Run the test suite inside a Docker container with HTML coverage report. + +### Viewing test coverage + +Once tests have produced HTML output of the coverage report, view it by running: +```shell +python -m http.server --directory=cover +``` + + ## Contacts If you want to contact the rdflib maintainers, please do so via the rdflib-dev mailing list: diff --git a/docker-compose.tests.yml b/docker-compose.tests.yml new file mode 100644 index 00000000..c71e3143 --- /dev/null +++ b/docker-compose.tests.yml @@ -0,0 +1,16 @@ +services: + test-runner: + build: + context: . + dockerfile: test/Dockerfile + volumes: + - .:/rdflib + command: ["/rdflib/run_tests.sh"] + + test-runner-coverage: + build: + context: . + dockerfile: test/Dockerfile + volumes: + - .:/rdflib + command: ["/rdflib/run_tests_with_coverage_report.sh"]
\ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..ddf2f7b4 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +cd /rdflib +pip install -e . + +test_command="nosetests --with-timer --timer-top-n 42 --with-coverage --cover-tests --cover-package=rdflib" +echo "Running tests..." +echo "Test command: $test_command" +$test_command
\ No newline at end of file diff --git a/run_tests_with_coverage_report.sh b/run_tests_with_coverage_report.sh new file mode 100755 index 00000000..a5383aaf --- /dev/null +++ b/run_tests_with_coverage_report.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +cd /rdflib +pip install -e . + +test_command="nosetests --with-timer --timer-top-n 42 --with-coverage --cover-tests --cover-package=rdflib --cover-html" +echo "Running tests..." +echo "Test command: $test_command" +$test_command
\ No newline at end of file diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 00000000..462f55a2 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,14 @@ +# Docker image for the rdflib test-runner. + +# Use the lowest supported Python version to run tests. +FROM python:3.6 + +COPY requirements.dev.txt . +COPY requirements.txt . + +RUN pip install --no-cache -r requirements.dev.txt +RUN pip install --no-cache -r requirements.txt + +RUN mkdir -p /rdflib +VOLUME /rdflib +WORKDIR /rdflib |