From d11e714fb7e9ba5343baf9c5e510e6a88b3a6d52 Mon Sep 17 00:00:00 2001 From: Edmond Chuc Date: Wed, 7 Jul 2021 10:02:01 +1000 Subject: Add running tests instructions to README. Add scripts and files to run tests in a Docker container. --- Dockerfile | 12 ++++++++++++ Makefile | 8 ++++++++ README.md | 37 +++++++++++++++++++++++++++++++++++++ docker-compose.yml | 12 ++++++++++++ run_tests.sh | 9 +++++++++ run_tests_with_coverage_report.sh | 9 +++++++++ 6 files changed, 87 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml create mode 100755 run_tests.sh create mode 100755 run_tests_with_coverage_report.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bb92a3b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# 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 + +WORKDIR /rdflib diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..cd9d8032 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +tests: + docker compose up test-runner --exit-code-from test-runner + +build: + docker compose build + +coverage: + docker compose up test-runner-coverage --exit-code-from test-runner-coverage \ No newline at end of file diff --git a/README.md b/README.md index a8478ffc..962f3360 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,43 @@ You can also raise issues here: * +## 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.yml b/docker-compose.yml new file mode 100644 index 00000000..0103edcc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +services: + test-runner: + build: . + volumes: + - .:/rdflib + command: ["/rdflib/run_tests.sh"] + + test-runner-coverage: + build: . + 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 -- cgit v1.2.1 From 198c92f5eca53cee378ae9c2bffb61d8d3e29580 Mon Sep 17 00:00:00 2001 From: Edmond Chuc Date: Wed, 7 Jul 2021 15:11:14 +1000 Subject: Move tests Dockerfile image to the test directory. Rename docker-compose.yml to docker-compose.tests.yml. --- Dockerfile | 12 ------------ Makefile | 8 +++++--- docker-compose.tests.yml | 16 ++++++++++++++++ docker-compose.yml | 12 ------------ test/Dockerfile | 12 ++++++++++++ 5 files changed, 33 insertions(+), 27 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker-compose.tests.yml delete mode 100644 docker-compose.yml create mode 100644 test/Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bb92a3b0..00000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -# 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 - -WORKDIR /rdflib diff --git a/Makefile b/Makefile index cd9d8032..7c484cfc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ tests: - docker compose up test-runner --exit-code-from test-runner + docker-compose -f docker-compose.tests.yml up test-runner + docker-compose -f docker-compose.tests.yml down build: - docker compose build + docker-compose -f docker-compose.tests.yml build coverage: - docker compose up test-runner-coverage --exit-code-from test-runner-coverage \ No newline at end of file + 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 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/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 0103edcc..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - test-runner: - build: . - volumes: - - .:/rdflib - command: ["/rdflib/run_tests.sh"] - - test-runner-coverage: - build: . - volumes: - - .:/rdflib - command: ["/rdflib/run_tests_with_coverage_report.sh"] \ No newline at end of file diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 00000000..bb92a3b0 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,12 @@ +# 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 + +WORKDIR /rdflib -- cgit v1.2.1 From b9d7c7202211bfcf15e9956bd3f25cb63dd6eb34 Mon Sep 17 00:00:00 2001 From: Edmond Chuc Date: Wed, 7 Jul 2021 15:37:35 +1000 Subject: Add Dockerfile VOLUME instruction. Add RUN statement to create /rdflib directory. --- test/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Dockerfile b/test/Dockerfile index bb92a3b0..462f55a2 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -9,4 +9,6 @@ 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 -- cgit v1.2.1