From 4289a9194d778919de975e42ba9446b88bbe21d8 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 8 Feb 2024 14:30:17 +0100 Subject: [PATCH] Testing: Demonstrate test utilities with Python --- .../testing-testcontainers-python.yml | 67 +++++++++++++++++++ requirements.txt | 2 +- .../python-pytest/pyproject.toml | 24 +++++++ .../python-pytest/requirements-dev.txt | 2 + .../python-pytest/requirements.txt | 5 ++ .../python-pytest/test_pytest.py | 12 ++++ .../testcontainers/python-unittest/.ngr-type | 1 + .../testcontainers/python-unittest/Makefile | 4 ++ .../python-unittest/pyproject.toml | 9 +++ .../python-unittest/requirements.txt | 5 ++ .../python-unittest/test_unittest.py | 29 ++++++++ 11 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/testing-testcontainers-python.yml create mode 100644 testing/testcontainers/python-pytest/pyproject.toml create mode 100644 testing/testcontainers/python-pytest/requirements-dev.txt create mode 100644 testing/testcontainers/python-pytest/requirements.txt create mode 100644 testing/testcontainers/python-pytest/test_pytest.py create mode 100644 testing/testcontainers/python-unittest/.ngr-type create mode 100644 testing/testcontainers/python-unittest/Makefile create mode 100644 testing/testcontainers/python-unittest/pyproject.toml create mode 100644 testing/testcontainers/python-unittest/requirements.txt create mode 100644 testing/testcontainers/python-unittest/test_unittest.py diff --git a/.github/workflows/testing-testcontainers-python.yml b/.github/workflows/testing-testcontainers-python.yml new file mode 100644 index 00000000..2c48838e --- /dev/null +++ b/.github/workflows/testing-testcontainers-python.yml @@ -0,0 +1,67 @@ +name: SQLAlchemy + +on: + pull_request: + branches: ~ + paths: + - '.github/workflows/testing-testcontainers-python.yml' + - 'testing/testcontainers/python**' + - 'requirements.txt' + push: + branches: [ main ] + paths: + - '.github/workflows/testing-testcontainers-python.yml' + - 'testing/testcontainers/python**' + - 'requirements.txt' + + # Allow job to be triggered manually. + workflow_dispatch: + + # Run job each night after CrateDB nightly has been published. + schedule: + - cron: '0 3 * * *' + +# Cancel in-progress jobs when pushing to the same branch. +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + test: + name: " + Python: ${{ matrix.python-version }} + CrateDB: ${{ matrix.cratedb-version }} + on ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ 'ubuntu-latest' ] + python-version: [ '3.12' ] + cratedb-version: [ 'nightly' ] + + steps: + + - name: Acquire sources + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + cache: 'pip' + cache-dependency-path: | + requirements.txt + testing/testcontainers/python-pytest/requirements.txt + testing/testcontainers/python-pytest/requirements-dev.txt + testing/testcontainers/python-unittest/requirements.txt + + - name: Install utilities + run: | + pip install -r requirements.txt + + - name: Validate testing/testcontainers/python-{pytest,unittest} + run: | + ngr test --accept-no-venv testing/testcontainers/python-pytest + ngr test --accept-no-venv testing/testcontainers/python-unittest diff --git a/requirements.txt b/requirements.txt index 44ade5f0..38926af8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pueblo>=0.0.4 +pueblo>=0.0.8 # Development. # pueblo @ git+https://github.com/pyveci/pueblo.git@main diff --git a/testing/testcontainers/python-pytest/pyproject.toml b/testing/testcontainers/python-pytest/pyproject.toml new file mode 100644 index 00000000..8b23aa00 --- /dev/null +++ b/testing/testcontainers/python-pytest/pyproject.toml @@ -0,0 +1,24 @@ +[tool.pytest.ini_options] +minversion = "2.0" +addopts = """ + -rfEX -p pytester --strict-markers --verbosity=3 + --cov --cov-report=term-missing --cov-report=xml + --capture=no + """ +log_level = "DEBUG" +log_cli_level = "DEBUG" +testpaths = ["*.py"] +xfail_strict = true +markers = [ +] + + +[tool.coverage.run] +branch = false +omit = [ + "test*", +] + +[tool.coverage.report] +fail_under = 0 +show_missing = true diff --git a/testing/testcontainers/python-pytest/requirements-dev.txt b/testing/testcontainers/python-pytest/requirements-dev.txt new file mode 100644 index 00000000..e03009bf --- /dev/null +++ b/testing/testcontainers/python-pytest/requirements-dev.txt @@ -0,0 +1,2 @@ +pytest<9 +pytest-cov<5 diff --git a/testing/testcontainers/python-pytest/requirements.txt b/testing/testcontainers/python-pytest/requirements.txt new file mode 100644 index 00000000..b0f765a7 --- /dev/null +++ b/testing/testcontainers/python-pytest/requirements.txt @@ -0,0 +1,5 @@ +crash==0.31.2 +# cratedb-toolkit[testing]==0.0.3 + +# Temporary, until a new `cratedb-toolkit` has been released. +cratedb-toolkit[testing] @ git+https://github.com/crate-workbench/cratedb-toolkit@main diff --git a/testing/testcontainers/python-pytest/test_pytest.py b/testing/testcontainers/python-pytest/test_pytest.py new file mode 100644 index 00000000..a6eacdb2 --- /dev/null +++ b/testing/testcontainers/python-pytest/test_pytest.py @@ -0,0 +1,12 @@ +import shlex +import subprocess + + +def run(command: str): + subprocess.check_call(shlex.split(command)) + + +def test_crash(cratedb_service): + http_url = cratedb_service.get_http_url() + cmd = f"time crash --hosts '{http_url}' --command 'SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;'" + run(cmd) diff --git a/testing/testcontainers/python-unittest/.ngr-type b/testing/testcontainers/python-unittest/.ngr-type new file mode 100644 index 00000000..d225aa5c --- /dev/null +++ b/testing/testcontainers/python-unittest/.ngr-type @@ -0,0 +1 @@ +python-unittest diff --git a/testing/testcontainers/python-unittest/Makefile b/testing/testcontainers/python-unittest/Makefile new file mode 100644 index 00000000..bb5473b0 --- /dev/null +++ b/testing/testcontainers/python-unittest/Makefile @@ -0,0 +1,4 @@ +PHONY: test + +test: + python -m unittest -vvv diff --git a/testing/testcontainers/python-unittest/pyproject.toml b/testing/testcontainers/python-unittest/pyproject.toml new file mode 100644 index 00000000..b2c65e67 --- /dev/null +++ b/testing/testcontainers/python-unittest/pyproject.toml @@ -0,0 +1,9 @@ +[tool.coverage.run] +branch = false +omit = [ + "test*", +] + +[tool.coverage.report] +fail_under = 0 +show_missing = true diff --git a/testing/testcontainers/python-unittest/requirements.txt b/testing/testcontainers/python-unittest/requirements.txt new file mode 100644 index 00000000..f3f03222 --- /dev/null +++ b/testing/testcontainers/python-unittest/requirements.txt @@ -0,0 +1,5 @@ +crash==0.31.2 +cratedb-toolkit[testing]==0.0.3 + +# Temporary, until a new `cratedb-toolkit` has been released. +# cratedb-toolkit[testing] @ git+https://github.com/crate-workbench/cratedb-toolkit@main diff --git a/testing/testcontainers/python-unittest/test_unittest.py b/testing/testcontainers/python-unittest/test_unittest.py new file mode 100644 index 00000000..b2bb5b9d --- /dev/null +++ b/testing/testcontainers/python-unittest/test_unittest.py @@ -0,0 +1,29 @@ +import shlex +import subprocess +from unittest import TestCase + +from cratedb_toolkit.testing.testcontainers.cratedb import CrateDBTestAdapter + +node = CrateDBTestAdapter() + + +def run(command: str): + subprocess.check_call(shlex.split(command)) + + +def setUpModule(): + node.start() + + +def tearDownModule(): + node.stop() + + +class CrashTest(TestCase): + def setUp(self): + node.reset() + + def test_crash(self): + http_url = node.get_http_url() + cmd = f"time crash --hosts '{http_url}' --command 'SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3;'" + run(cmd)