Skip to content

Commit

Permalink
Testing: Demonstrate test utilities with Python
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Feb 9, 2024
1 parent cb80060 commit 4289a91
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 1 deletion.
67 changes: 67 additions & 0 deletions .github/workflows/testing-testcontainers-python.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pueblo>=0.0.4
pueblo>=0.0.8

# Development.
# pueblo @ git+https://github.com/pyveci/pueblo.git@main
24 changes: 24 additions & 0 deletions testing/testcontainers/python-pytest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions testing/testcontainers/python-pytest/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest<9
pytest-cov<5
5 changes: 5 additions & 0 deletions testing/testcontainers/python-pytest/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions testing/testcontainers/python-pytest/test_pytest.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions testing/testcontainers/python-unittest/.ngr-type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-unittest
4 changes: 4 additions & 0 deletions testing/testcontainers/python-unittest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PHONY: test

test:
python -m unittest -vvv
9 changes: 9 additions & 0 deletions testing/testcontainers/python-unittest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.coverage.run]
branch = false
omit = [
"test*",
]

[tool.coverage.report]
fail_under = 0
show_missing = true
5 changes: 5 additions & 0 deletions testing/testcontainers/python-unittest/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions testing/testcontainers/python-unittest/test_unittest.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4289a91

Please sign in to comment.