From 4f6dc93c00ab0841586c6751e5e8e0cedad9e41c Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 29 Dec 2023 08:50:13 +0100 Subject: Improve running tests --- .gitignore | 2 ++ README.rst | 24 +++++++++++++++++++++--- check | 4 ++-- kerbana/config.py | 6 +++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4896b18..b00f7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,9 @@ db.sqlite3 data/ +test_data/ kerbana.yaml +kerbana_tests.yaml .*.sw? diff --git a/README.rst b/README.rst index 6a00502..96a1aef 100644 --- a/README.rst +++ b/README.rst @@ -26,9 +26,27 @@ Contributing Running Tests ------------- -To run the MQTT integration tests, create a file ``kerbana_tests.toml`` -in the base directory with the variable ``MQTT_SERVER`` pointing to a -valid mqtt server you can use. +To run the MQTT integration tests, create a file ``kerbana_tests.yaml`` +in the base directory with at least the variable ``MQTT_SERVER`` +pointing to a valid mqtt server you can use, then run the tests with +``KERBANA_CONFIG=kerbana_tests.yaml ./manage.py test``. + +The ``check`` script can be used to run the tests with the above setting +and for other checks and common tasks, with the following subcommands: + +test + run the test suite +coverage + run the test suite and print coverage data +qa + run qa checks (code style etc.) +static + run static analysis tests +run + runs the development server +devdb + initalizes the db and creates ad admin user (whose password needs to + be set manually afterwards) License ------- diff --git a/check b/check index 4821df4..1983f5d 100755 --- a/check +++ b/check @@ -24,12 +24,12 @@ shift 1 case $SUBCMD in "tests") cd "$root" - ./manage.py test $@ + KERBANA_CONFIG=kerbana_tests.yaml ./manage.py test $@ cd - ;; "coverage") cd "$root" - python3-coverage run ./manage.py test $@ + KERBANA_CONFIG=kerbana_tests.yaml python3-coverage run ./manage.py test $@ python3-coverage report cd - ;; diff --git a/kerbana/config.py b/kerbana/config.py index 358d2fe..af35ab2 100644 --- a/kerbana/config.py +++ b/kerbana/config.py @@ -1,5 +1,6 @@ import logging import os +import pathlib import sys import strictyaml @@ -10,7 +11,10 @@ log = logging.getLogger(__name__) def read_from_yaml(fp): data = strictyaml.load(fp.read()) for k, v in data.data.items(): - setattr(sys.modules[__name__], k, v) + if k.endswith("PATH"): + setattr(sys.modules[__name__], k, pathlib.Path(v)) + else: + setattr(sys.modules[__name__], k, v) conf_file = "/etc/kerbana/kerbana.yaml" -- cgit v1.2.3