Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parameterized for launching table tests #18

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ jobs:
# - Windows
# - MacOs
py:
# https://github.com/PyCQA/pylint/issues/6535
# waiting for fix ^
# - "3.11"
- "3.11"
- "3.10"
- "3.9"
- "3.8"
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
.PHONY: setup
setup:
pip install tox
python3 -m pip install tox==4.8.0

.PHONY: setup-dev
setup-dev:
pyenv install -s 3.6.15
pyenv install -s 3.7.12
pyenv install -s 3.8.6
pyenv install -s 3.9.9
pyenv install -s 3.10.0
pyenv local 3.6.15 3.7.12 3.8.6 3.9.9 3.10.0
pip install tox-pyenv
python3 -m pip install tox
pyenv install -s 3.10.7
pyenv install -s 3.11.0
pyenv local 3.7.12 3.8.6 3.9.9 3.10.7 3.11.0
python3 -m pip install tox==4.8.0

.PHONY: test
test:
Expand Down
5 changes: 3 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==6.2.5
pytest-cov==3.0.0
pytest==7.4.1
pytest-cov==4.1.0
parameterized==0.9.0
15 changes: 15 additions & 0 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from clickhouse_migrations.clickhouse_cluster import ClickhouseCluster


@pytest.fixture
def cluster():
return ClickhouseCluster("localhost", "default", "")


@pytest.fixture(autouse=True)
def before(cluster: ClickhouseCluster):
with cluster.connection("") as conn:
conn.execute("DROP DATABASE IF EXISTS pytest")
conn.execute("CREATE DATABASE pytest")
17 changes: 0 additions & 17 deletions src/tests/test_clickhouse_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,13 @@
import pytest
from clickhouse_driver.errors import ServerException

from clickhouse_migrations.clickhouse_cluster import ClickhouseCluster
from clickhouse_migrations.cmd import get_context, migrate
from clickhouse_migrations.exceptions import MigrationException
from clickhouse_migrations.types import Migration

TESTS_DIR = Path(__file__).parent


@pytest.fixture
def cluster():
return ClickhouseCluster("localhost", "default", "")


@pytest.fixture(autouse=True)
def before(cluster):
clean_slate(cluster)


def clean_slate(migrator):
with migrator.connection("") as conn:
conn.execute("DROP DATABASE IF EXISTS pytest")
conn.execute("CREATE DATABASE pytest")


def test_empty_list_of_migrations_ok(cluster):
with tempfile.TemporaryDirectory("empty_dir") as temp_dir:
applied = cluster.migrate("pytest", temp_dir)
Expand Down
47 changes: 19 additions & 28 deletions src/tests/test_log_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,23 @@
from clickhouse_migrations.cmd import log_level


def test_valid_log_levels():
# Test upper (canonical) case input
for level in logging._nameToLevel: # pylint: disable=W0212
assert log_level(level.upper()) == level
# Test lower case input
for level in logging._nameToLevel: # pylint: disable=W0212
assert log_level(level.lower()) == level
# Test mixed case input
for level in logging._nameToLevel: # pylint: disable=W0212
level_char_list = []
for i, ch in enumerate(level):
ch = chr(ord(ch) | 0b0010_0000) if (i % 2) == 0 else ch
level_char_list.append(ch)
mixed_case_level = "".join(level_char_list)
assert log_level(mixed_case_level) == level
# Test mixed case input
for level in logging._nameToLevel: # pylint: disable=W0212
level_char_list = []
for i, ch in enumerate(level):
ch = chr(ord(ch) | 0b0010_0000) if (i % 2) != 0 else ch
level_char_list.append(ch)
mixed_case_level = "".join(level_char_list)
assert log_level(mixed_case_level) == level
@pytest.mark.parametrize(
"good_input,expected",
(
*((v.lower(), v) for v in logging._nameToLevel), # pylint: disable=W0212
*((v.upper(), v) for v in logging._nameToLevel), # pylint: disable=W0212
("wArN", "WARN"),
("errOR", "ERROR"),
("InFO", "INFO"),
),
)
def test_valid_log_levels(good_input, expected):
assert log_level(good_input) == expected


def test_invalid_log_levels():
bad_input = (
@pytest.mark.parametrize(
"bad_input",
(
"",
" ",
"FOO",
Expand All @@ -42,7 +32,8 @@ def test_invalid_log_levels():
"WARN ",
" WARN",
" WARN ",
)
),
)
def test_invalid_log_levels(bad_input):
with pytest.raises(ValueError):
for value in bad_input:
log_level(value)
log_level(bad_input)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ commands = flake8 --config={toxinidir}/tox.ini src/
[testenv:pylint-check]
deps =
{[testenv]deps}
pylint==2.13.9
pylint==2.17.5
commands = pylint src/tests/ --rcfile={toxinidir}/tox.ini
pylint src/clickhouse_migrations/ --rcfile={toxinidir}/tox.ini

Expand Down Expand Up @@ -106,7 +106,7 @@ commands = coverage erase

########
# pylint
[MESSAGES CONTROL]
[pylint.main]
# C0114: Missing module docstring
# C0116: Missing function or method docstring
disable=fixme, invalid-name, R0801, W0621, C0116, C0114, R0913, C0115
Expand Down