From 1d87eeb42c4ab3825e780cfdd2625bb627a0ec90 Mon Sep 17 00:00:00 2001 From: inifares23lab Date: Thu, 7 Dec 2023 22:38:55 +0100 Subject: [PATCH] Add basic test configuration. Add test for app.py. Modified CI to run tests. --- .github/workflows/parser_ci.yml | 17 ++++++++--------- .gitignore | 5 +++-- requirements_test.txt | 1 + tests/__init__.py | 0 tests/test_app.py | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 requirements_test.txt create mode 100644 tests/__init__.py create mode 100644 tests/test_app.py diff --git a/.github/workflows/parser_ci.yml b/.github/workflows/parser_ci.yml index ac2d015..b6473fd 100644 --- a/.github/workflows/parser_ci.yml +++ b/.github/workflows/parser_ci.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] steps: - uses: actions/checkout@v3 @@ -57,16 +57,15 @@ jobs: file_name="nx.html" [[ -f ./$file_name ]] && echo "$file_name created - OK" || exit 1 - - name: Run app.py server - run: | - python app.py & - - name: Check that the server is reachable - run: | - head=$(curl --head http://127.0.0.1:8050/ | head -n 1) - [[ $head = *"200 OK"* ]] && echo "$head" || exit 1 + - name: Prepare for tests + run: pip install -r requirements_test.txt + + - name: Run pytest + run: pytest . do_something_else: runs-on: ubuntu-latest needs: test_parser steps: - - run: echo "Doing something else" + - name: Do something else + run: echo "Doing something else" diff --git a/.gitignore b/.gitignore index 1568c6c..5f43a61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ file.* -*test* +*test conf/conf.env -__pycache__ +*__pycache__ certs/* output.* graph.py @@ -13,3 +13,4 @@ tmp .vscode *.log .ropeproject +*cache* diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1 @@ +pytest diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..ee3b3cb --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,14 @@ +import pytest + +# Assuming the Dash app is initialized in a file named app.py and the server is an attribute of the app +from app import app + + +@pytest.fixture(scope='module') +def client(): + return app.server.test_client() + +def test_server_is_up_and_running(client): + response = client.head('http://127.0.0.1:8050/') + assert response.status_code == 200 +