From 9b56837bc08bb4d6bda33f8e7995b7e5e6afd367 Mon Sep 17 00:00:00 2001 From: Lukas Lalinsky Date: Mon, 2 Dec 2024 20:54:11 +0100 Subject: [PATCH 1/3] Try to run python tests in github actions --- .github/workflows/build.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ee2709..0b7b71c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,6 +22,14 @@ jobs: - run: zig build test --summary all - run: zig build + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + cache: 'pip' + + - run: pip install pytest requests + - run: pytest -v tests/ + - name: Log in to the Container registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 From 877388f451462bf375d68b4a3199b665553dcb3c Mon Sep 17 00:00:00 2001 From: Lukas Lalinsky Date: Mon, 2 Dec 2024 20:55:37 +0100 Subject: [PATCH 2/3] Add requirements.txt --- .github/workflows/build.yml | 2 +- tests/requirements.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b7b71c..0f322d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: python-version: '3.13' cache: 'pip' - - run: pip install pytest requests + - run: pip install -r tests/requirements.txt - run: pytest -v tests/ - name: Log in to the Container registry diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..16d3b77 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +pytest +requests \ No newline at end of file From 510242ea4fd7e487b9d64a7303b8adc656fdf85e Mon Sep 17 00:00:00 2001 From: Lukas Lalinsky Date: Mon, 2 Dec 2024 21:10:29 +0100 Subject: [PATCH 3/3] Start our own instance of fpserver for tests --- tests/conftest.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0cffab8..035a767 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,42 @@ import requests import pytest +import subprocess +import socket from urllib.parse import urljoin +@pytest.fixture(scope='session') +def server_port(): + sock = socket.socket() + sock.bind(('', 0)) + return sock.getsockname()[1] + + +@pytest.fixture(scope='session') +def server(server_port, tmp_path_factory): + tmp_dir = tmp_path_factory.mktemp("server") + data_dir = tmp_dir / 'data' + stderr = tmp_dir / 'server.stderr.log' + command = [ + 'zig-out/bin/fpindex', + '--dir', str(data_dir), + '--port', str(server_port), + '--log-level', 'debug', + ] + process = subprocess.Popen( + command, + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=stderr.open('w'), + ) + yield + process.terminate() + retcode = process.wait() + if retcode != 0: + for line in stderr.read_text().splitlines(): + print(line) + + @pytest.fixture def index_name(): return 'testidx' @@ -36,8 +70,8 @@ def session(): @pytest.fixture -def client(session): - return Client(session, 'http://localhost:8080') +def client(session, server_port, server): + return Client(session, f'http://localhost:{server_port}') @pytest.fixture(autouse=True)