Skip to content

Commit

Permalink
Merge pull request #57 from ADBond/dev/isolate-clickhouse-tests
Browse files Browse the repository at this point in the history
Isolate clickhouse / chdb tests
  • Loading branch information
ADBond authored Jan 2, 2025
2 parents da04973 + f60b987 commit b54d68a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-install-no-chdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: uv python install 3.9

- name: Check package imports if we don't have dev dependencies
run: uv run --no-dev --isolated python -c "import splinkclickhouse"
run: uv run --no-group chdb --isolated python -c "import splinkclickhouse"
14 changes: 10 additions & 4 deletions .github/workflows/test-clickhouse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ jobs:
- name: Install dependencies
run: uv sync -p ${{ matrix.python-version }}

- name: Run tests
run: |
uv run pytest -vm ${{ matrix.test-set }} --cov=splinkclickhouse --cov-branch tests
mv .coverage .coverage.${{ matrix.test-set }}
- name: Run core or clickhouse tests
if: ${{ matrix.test-set != 'chdb_no_core'}}
run: uv run python -m pytest -vm ${{ matrix.test-set }} --cov=splinkclickhouse --cov-branch tests

- name: Run chdb tests
if: ${{ matrix.test-set == 'chdb_no_core'}}
run: uv run python -m pytest -vm ${{ matrix.test-set }} --cov=splinkclickhouse --cov-branch tests

- name: Rename coverage file
run: mv .coverage .coverage.${{ matrix.test-set }}

- name: Check directory contents
run: ls -alhR .
Expand Down
15 changes: 9 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
package = true
default-groups = ["dev", "chdb"]

[dependency-groups]
dev = [
"pyarrow >= 17.0.0",

"ruff == 0.6.4",
"mypy == 1.11.2",

"pytest == 8.3.3",
"pytest-cov>=6.0.0",

# probably not ideal having this doubled here,
# but saves having to pass --all_extras for 'uv run'
"chdb >= 2.0.1",
]
package = true
chdb = [
"chdb>=2.0.1",
]


[tool.hatch.build.targets.sdist]
# opt-in to build
Expand Down
65 changes: 39 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import clickhouse_connect
import numpy as np
import pandas as pd
import splink.comparison_library as cl
from chdb import dbapi
from pytest import fixture, mark, param
from splink import ColumnExpression, SettingsCreator, block_on, splink_datasets

from splinkclickhouse import ChDBAPI, ClickhouseServerAPI

df = splink_datasets.fake_1000

np.random.seed(2542546873)
Expand Down Expand Up @@ -49,35 +45,52 @@ def pytest_collection_modifyitems(items, config):

@fixture
def chdb_api_factory():
con = dbapi.connect()
yield lambda: ChDBAPI(con)
con.close()
# only import it if we need it
try:
from chdb import dbapi

from splinkclickhouse import ChDBAPI

con = dbapi.connect()
yield lambda: ChDBAPI(con)
con.close()
except ModuleNotFoundError:
yield None


@fixture(scope="module")
def clickhouse_api_factory():
conn_atts = {
"host": "localhost",
"port": 8123,
"username": "splinkognito",
"password": "splink123!",
}
# only import when we need
try:
import clickhouse_connect

db_name = "__temp_splink_db_pytest"
from splinkclickhouse import ClickhouseServerAPI

try:
default_client = clickhouse_connect.get_client(**conn_atts)
default_client.command(f"CREATE DATABASE IF NOT EXISTS {db_name}")
client = clickhouse_connect.get_client(
**conn_atts,
database=db_name,
)
conn_atts = {
"host": "localhost",
"port": 8123,
"username": "splinkognito",
"password": "splink123!",
}

db_name = "__temp_splink_db_pytest"

try:
default_client = clickhouse_connect.get_client(**conn_atts)
default_client.command(f"CREATE DATABASE IF NOT EXISTS {db_name}")
client = clickhouse_connect.get_client(
**conn_atts,
database=db_name,
)

yield lambda: ClickhouseServerAPI(client)
client.close()
default_client.command(f"DROP DATABASE {db_name}")
default_client.close()
except clickhouse_connect.driver.exceptions.OperationalError:
yield None

yield lambda: ClickhouseServerAPI(client)
client.close()
default_client.command(f"DROP DATABASE {db_name}")
default_client.close()
except clickhouse_connect.driver.exceptions.OperationalError:
except ModuleNotFoundError:
yield None


Expand Down
Loading

0 comments on commit b54d68a

Please sign in to comment.