Skip to content

Commit

Permalink
feat: bump bepatient version and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dawid-szaniawski authored Aug 12, 2024
1 parent 0203c00 commit 5c23361
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 100 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
Linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -22,9 +22,9 @@ jobs:
os: [ubuntu-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion bepatient_db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from bepatient_db.api import SQLWaiter

__version__ = "0.3.0"
__version__ = "0.4.0"
__all__ = [
"SQLWaiter",
]
Expand Down
6 changes: 3 additions & 3 deletions bepatient_db/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from bepatient import Checker
from bepatient.waiter_src.comparators import COMP_DICT, COMPARATORS
from bepatient.waiter_src import comparators
from bepatient.waiter_src.waiter import wait_for_executor

from .sql_checkers import ResultType, SQLChecker
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(self, cursor: DbCursor, query: str):
def add_checker(
self,
expected_value: Any,
comparer: COMPARATORS,
comparer: comparators.COMPARATORS,
dict_path: str | None = None,
search_query: str | None = None,
):
Expand All @@ -62,7 +62,7 @@ def add_checker(
self: updated RequestsWaiter instance."""
self.executor.add_checker(
SQLChecker(
comparer=COMP_DICT[comparer],
comparer=getattr(comparators, comparer),
expected_value=expected_value,
dict_path=dict_path,
search_query=search_query,
Expand Down
2 changes: 1 addition & 1 deletion bepatient_db/sql_checkers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Any, Callable, TypeAlias

from bepatient.waiter_src.checker import Checker
from bepatient import Checker
from dictor import dictor

log = logging.getLogger(__name__)
Expand Down
8 changes: 6 additions & 2 deletions bepatient_db/sql_executor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import sqlite3
import uuid
from typing import TypeAlias

from bepatient.waiter_src.executor import Executor
from bepatient.waiter_src.executors.executor import Executor
from mysql.connector.cursor import CursorBase
from psycopg2.extensions import cursor

Expand Down Expand Up @@ -34,10 +35,13 @@ def is_condition_met(self) -> bool:
Returns:
bool: True if the condition has been met, False otherwise."""
log.info("Query send to database: %s", self._input)
run_uuid: str = str(uuid.uuid4())
self._result = self._cursor.execute(self._input).fetchall()

self._failed_checkers = [
checker for checker in self._checkers if not checker.check(self._result)
checker
for checker in self._checkers
if not checker.check(self._result, run_uuid)
]

if len(self._failed_checkers) == 0:
Expand Down
32 changes: 16 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ requires-python = ">=3.10"
authors = [{ name = "Dawid Szaniawski", email = "[email protected]" }]
license = { file = "LICENSE" }
dependencies = [
"bepatient>=0.5.1",
"bepatient>=0.10.2",
"dictor>=0.1.12",
"mysql-connector-python>=8.1.0",
"psycopg2-binary>=2.9.7"
"mysql-connector-python~=8.1.0",
"psycopg2-binary~=2.9.7"
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand Down Expand Up @@ -58,21 +58,21 @@ keywords = [

[project.optional-dependencies]
dev = [
"black>=23.7.0",
"flake8>=6.1.0",
"isort>=5.12.0",
"mypy>=1.4.1",
"pylint>=2.17.5",
"pytest>=7.4.0",
"pytest-cov>=4.1.0",
"pytest-mock>=3.11.1",
"ruff>=0.0.282",
"tox>=4.7.0",
"twine>=4.0.2"
"black>=24.8.0",
"flake8>=7.1.1",
"isort>=5.13.2",
"mypy>=1.11.1",
"pylint>=3.2.6",
"pytest>=8.3.2",
"pytest-cov>=5.0.0",
"pytest-mock>=3.14.0",
"ruff>=0.5.7",
"tox>=4.17.1",
"twine>=5.1.1"
]
docs = [
"mkdocs-material>=9.1.21",
"mkdocs-minify-plugin>=0.7.1"
"mkdocs-material>=9.5.31",
"mkdocs-minify-plugin>=0.8.0"
]

[project.urls]
Expand Down
26 changes: 13 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ max-line-length = 88
extend-ignore = E203

[tox:tox]
min_version = 4.7.0
min_version = 4.17.1
env_list =
flake8
mypy
Expand All @@ -35,34 +35,34 @@ python =
setenv =
PYTHONPATH = {toxinidir}
deps =
pytest==7.4.0
pytest-mock==3.11.1
pytest==8.3.2
pytest-mock==3.14.0
whitelist_externals = pytest
commands = pytest --basetemp={envtmpdir}

[testenv:flake8]
basepython = python3.11
deps = flake8==6.1.0
basepython = python3.12
deps = flake8==7.1.1
whitelist_externals = flake8
commands = flake8 bepatient_db tests

[testenv:mypy]
basepython = python3.11
deps = mypy==1.4.1
basepython = python3.12
deps = mypy==1.11.1
whitelist_externals = mypy
commands = mypy --install-types --non-interactive bepatient_db tests

[testenv:pylint]
basepython = python3.11
basepython = python3.12
deps =
pylint==2.17.5
pytest==7.4.0
pytest-mock==3.11.1
pylint==3.2.6
pytest==8.3.2
pytest-mock==3.14.0
whitelist_externals = pylint
commands = pylint bepatient_db tests

[testenv:ruff]
basepython = python3.11
deps = ruff==0.0.282
basepython = python3.12
deps = ruff==0.5.7
whitelist_externals = ruff
commands = ruff check .
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __str__(self) -> str:
def prepare_data(self, data: Any, run_uuid: str | None = None) -> None:
"""mock"""

def check(self, data: Any) -> bool:
def check(self, data: Any, run_uuid: str) -> bool:
return True

checker = CheckerMocker(is_equal, "")
Expand All @@ -48,7 +48,7 @@ def __str__(self) -> str:
def prepare_data(self, data: Any, run_uuid: str | None = None) -> None:
"""mock"""

def check(self, data: Any) -> bool:
def check(self, data: Any, run_uuid: str) -> bool:
return False

return CheckerMocker(is_equal, "")
Expand Down
48 changes: 28 additions & 20 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_condition_not_met_without_error(

assert waiter.get_result() == result

def test_wait_for_value(
def test_wait_for_value_sqlite(
self,
sqlite_db: sqlite3.Cursor,
tmp_path: Path,
Expand All @@ -140,7 +140,7 @@ def insert_data():
logs = [
(
"bepatient.waiter_src.waiter",
10,
20,
"Checking whether the condition has been met. The 1 approach",
),
(
Expand All @@ -149,27 +149,28 @@ def insert_data():
"Query send to database: SELECT username FROM user WHERE id = 3",
),
(
"bepatient.waiter_src.checker",
20,
"Check uuid: SQLWaiter | Checker: SQLChecker | Comparer: is_equal | "
"Dictor_fallback: None | Expected_value: Jerry | Path: 0.username | "
"Search_query: None | Data: Jerry",
"bepatient.waiter_src.checkers.checker",
10,
"Check uuid: SQLWaiter | Checker: SQLChecker | Comparer: is_equal"
" | Dictor_fallback: None | Expected_value: Jerry | Path: 0.username"
" | Search_query: None | Data: Jerry",
),
("bepatient_db.sql_checkers", 20, "Check uuid: SQLWaiter | Data: []"),
(
"bepatient.waiter_src.checker",
10,
"Check uuid: SQLWaiter | Condition not met | Expected: Jerry"
" | Data: None",
"bepatient.waiter_src.checkers.checker",
20,
"Check uuid: SQLWaiter | Condition not met | Checker: SQLChecker"
" | Comparer: is_equal | Dictor_fallback: None | Expected_value: Jerry"
" | Path: 0.username | Search_query: None | Data: Jerry",
),
(
"bepatient.waiter_src.waiter",
10,
"The condition has not been met. Waiting: 2",
20,
"The condition has not been met. Waiting time: 2",
),
(
"bepatient.waiter_src.waiter",
10,
20,
"Checking whether the condition has been met. The 2 approach",
),
(
Expand All @@ -178,18 +179,25 @@ def insert_data():
"Query send to database: SELECT username FROM user WHERE id = 3",
),
(
"bepatient.waiter_src.checker",
20,
"Check uuid: SQLWaiter | Checker: SQLChecker | Comparer: is_equal | "
"Dictor_fallback: None | Expected_value: Jerry | Path: 0.username | "
"Search_query: None | Data: Jerry",
"bepatient.waiter_src.checkers.checker",
10,
"Check uuid: SQLWaiter | Checker: SQLChecker | Comparer: is_equal"
" | Dictor_fallback: None | Expected_value: Jerry | Path: 0.username"
" | Search_query: None | Data: Jerry",
),
(
"bepatient_db.sql_checkers",
20,
"Check uuid: SQLWaiter | Data: [{'username': 'Jerry'}]",
),
("bepatient.waiter_src.waiter", 10, "Condition met!"),
(
"bepatient.waiter_src.checkers.checker",
20,
"Check success! | uuid: SQLWaiter | Checker: SQLChecker"
" | Comparer: is_equal | Dictor_fallback: None | Expected_value: Jerry"
" | Path: 0.username | Search_query: None | Data: Jerry",
),
("bepatient.waiter_src.waiter", 20, "Condition met!"),
]

waiter = SQLWaiter(
Expand Down
Loading

0 comments on commit 5c23361

Please sign in to comment.