From 9eb5f46aa58672763d3309537416eef1bdfb2273 Mon Sep 17 00:00:00 2001 From: Isaias Gutierrez-Cruz <64386035+IsaiasGutierrezCruz@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:47:58 -0600 Subject: [PATCH] ci: add tests for the queries of TPC-H (#899) --- .github/workflows/check_tpch_queries.yml | 30 ++++++++++++++++++++++++ pyproject.toml | 1 + requirements-dev.txt | 1 + tpch/tests/__init__.py | 0 tpch/tests/test_queries.py | 29 +++++++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 .github/workflows/check_tpch_queries.yml create mode 100644 tpch/tests/__init__.py create mode 100644 tpch/tests/test_queries.py diff --git a/.github/workflows/check_tpch_queries.yml b/.github/workflows/check_tpch_queries.yml new file mode 100644 index 000000000..397163091 --- /dev/null +++ b/.github/workflows/check_tpch_queries.yml @@ -0,0 +1,30 @@ +name: Tests for TPCH Queries + +on: + pull_request: + types: [labeled] + +jobs: + validate-queries: + if: ${{ github.event.label.name == 'full-test' }} + strategy: + matrix: + python-version: ["3.12"] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: install-reqs + run: uv pip install --upgrade -r requirements-dev.txt --system + - name: local-install + run: uv pip install -e . --system + - name: generate-data + run: cd tpch && python generate_data.py + - name: tpch-tests + run: python -m unittest discover -s 'tpch/tests' \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a279280bf..b3a2a0c28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,6 +76,7 @@ lint.ignore = [ [tool.ruff.lint.per-file-ignores] "tests/*" = ["S101"] +"tpch/tests/*" = ["S101"] "utils/*" = ["S311", "PTH123"] "tpch/execute/*" = ["T201"] diff --git a/requirements-dev.txt b/requirements-dev.txt index 213fcdcb8..23ff1757e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ +tqdm covdefaults duckdb pandas diff --git a/tpch/tests/__init__.py b/tpch/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tpch/tests/test_queries.py b/tpch/tests/test_queries.py new file mode 100644 index 000000000..4b7cdd866 --- /dev/null +++ b/tpch/tests/test_queries.py @@ -0,0 +1,29 @@ +import os +import subprocess +import sys +import unittest +from pathlib import Path + + +class TestQueries(unittest.TestCase): + def test_execute_scripts(self) -> None: + root = Path(__file__).resolve().parent.parent + # directory containing all the queries + execute_dir = root / "execute" + + env = os.environ.copy() + env["PYTHONPATH"] = str(root) + + for script_path in execute_dir.glob("q[1-9]*.py"): + result = subprocess.run( # noqa: S603 + [sys.executable, str(script_path)], + capture_output=True, + text=True, + env=env, + cwd=root, + check=False, + shell=False, + ) + assert ( + result.returncode == 0 + ), f"Script {script_path} failed with error: {result.stderr}"