From 5c233614c8276008875d717a545dca6cd47f1667 Mon Sep 17 00:00:00 2001 From: Dawid Szaniawski <98256512+dawid-szaniawski@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:17:51 +0200 Subject: [PATCH] feat: bump bepatient version and fix tests --- .github/workflows/codecov.yml | 4 +- .github/workflows/pypi-publish.yml | 4 +- .github/workflows/tox.yml | 10 ++-- bepatient_db/__init__.py | 2 +- bepatient_db/api.py | 6 +-- bepatient_db/sql_checkers.py | 2 +- bepatient_db/sql_executor.py | 8 +++- pyproject.toml | 32 ++++++------- setup.cfg | 26 +++++----- tests/conftest.py | 4 +- tests/test_api.py | 48 +++++++++++-------- tests/test_sql_checker.py | 77 +++++++++++++++++------------- tests/test_sql_executor.py | 2 +- 13 files changed, 125 insertions(+), 100 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 5f5aae0..8b2286a 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -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 diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 4524e0e..2308f29 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -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 diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index a801988..112b0ab 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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 @@ -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 diff --git a/bepatient_db/__init__.py b/bepatient_db/__init__.py index 3056c9c..b929da9 100644 --- a/bepatient_db/__init__.py +++ b/bepatient_db/__init__.py @@ -3,7 +3,7 @@ from bepatient_db.api import SQLWaiter -__version__ = "0.3.0" +__version__ = "0.4.0" __all__ = [ "SQLWaiter", ] diff --git a/bepatient_db/api.py b/bepatient_db/api.py index 1a5cb34..38c982a 100644 --- a/bepatient_db/api.py +++ b/bepatient_db/api.py @@ -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 @@ -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, ): @@ -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, diff --git a/bepatient_db/sql_checkers.py b/bepatient_db/sql_checkers.py index 71fb2f7..4d24481 100644 --- a/bepatient_db/sql_checkers.py +++ b/bepatient_db/sql_checkers.py @@ -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__) diff --git a/bepatient_db/sql_executor.py b/bepatient_db/sql_executor.py index eb7b4ff..b8c7132 100644 --- a/bepatient_db/sql_executor.py +++ b/bepatient_db/sql_executor.py @@ -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 @@ -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: diff --git a/pyproject.toml b/pyproject.toml index c5bfd89..9dbd19a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,10 +11,10 @@ requires-python = ">=3.10" authors = [{ name = "Dawid Szaniawski", email = "webluduspl@gmail.com" }] 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", @@ -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] diff --git a/setup.cfg b/setup.cfg index 7b674ac..1eeacfd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -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 . diff --git a/tests/conftest.py b/tests/conftest.py index d344fbf..4b95916 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, "") @@ -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, "") diff --git a/tests/test_api.py b/tests/test_api.py index b676ea3..c7717af 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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, @@ -140,7 +140,7 @@ def insert_data(): logs = [ ( "bepatient.waiter_src.waiter", - 10, + 20, "Checking whether the condition has been met. The 1 approach", ), ( @@ -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", ), ( @@ -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( diff --git a/tests/test_sql_checker.py b/tests/test_sql_checker.py index 4cdaf7a..5da9671 100644 --- a/tests/test_sql_checker.py +++ b/tests/test_sql_checker.py @@ -11,8 +11,8 @@ class TestSQLChecker: def test_str(self, is_equal: Callable[[Any, Any], bool]): checker = SQLChecker(is_equal, 5) msg = ( - "Checker: SQLChecker | Comparer: comparer | Dictor_fallback: None | " - "Expected_value: 5 | Path: None | Search_query: None | Data: None" + "Checker: SQLChecker | Comparer: comparer | Dictor_fallback: None" + " | Expected_value: 5 | Path: None | Search_query: None | Data: None" ) assert str(checker) == msg @@ -76,7 +76,7 @@ def test_check( checker = SQLChecker(is_equal, [{"id": 1, "username": "WebLudus"}]) checker_data = sqlite_db.execute("SELECT * FROM user WHERE id = 1").fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True def test_condition_not_met( self, @@ -87,7 +87,7 @@ def test_condition_not_met( checker = SQLChecker(is_equal, "TEST") checker_data = sqlite_db.execute(select_all_from_user_query).fetchall() - assert checker.check(checker_data) is False + assert checker.check(checker_data, "TEST") is False def test_missing_key( self, @@ -103,7 +103,7 @@ def test_missing_key( ) checker_data = sqlite_db.execute(select_all_from_user_query).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True def test_missing_key_in_search_query( self, @@ -119,28 +119,33 @@ def test_missing_key_in_search_query( ) checker_data = sqlite_db.execute(select_all_from_user_query).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True def test_null_value( self, sqlite_db: sqlite3.Cursor, is_equal: Callable[[Any, Any], bool], caplog: LogCaptureFixture, - monkeypatch: pytest.MonkeyPatch, ): - monkeypatch.setattr("uuid.uuid4", lambda: "TestSQLChecker") logs = [ ( - "bepatient.waiter_src.checker", - 20, - "Check uuid: TestSQLChecker | Checker: SQLChecker | Comparer: comparer" + "bepatient.waiter_src.checkers.checker", + 10, + "Check uuid: TEST | Checker: SQLChecker | Comparer: comparer" " | Dictor_fallback: missing | Expected_value: None" " | Path: 0.description | Search_query: None | Data: None", ), ( "bepatient_db.sql_checkers", 20, - "Check uuid: TestSQLChecker | Data: [{'description': None}]", + "Check uuid: TEST | Data: [{'description': None}]", + ), + ( + "bepatient.waiter_src.checkers.checker", + 20, + "Check success! | uuid: TEST | Checker: SQLChecker | Comparer: comparer" + " | Dictor_fallback: missing | Expected_value: None" + " | Path: 0.description | Search_query: None | Data: None", ), ] checker = SQLChecker( @@ -153,7 +158,7 @@ def test_null_value( "SELECT description from tests WHERE id = 1" ).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True assert caplog.record_tuples == logs def test_empty_string_value( @@ -161,21 +166,26 @@ def test_empty_string_value( sqlite_db: sqlite3.Cursor, is_equal: Callable[[Any, Any], bool], caplog: LogCaptureFixture, - monkeypatch: pytest.MonkeyPatch, ): - monkeypatch.setattr("uuid.uuid4", lambda: "TestSQLChecker") logs = [ ( - "bepatient.waiter_src.checker", - 20, - "Check uuid: TestSQLChecker | Checker: SQLChecker | Comparer: comparer" - " | Dictor_fallback: missing | Expected_value: " - " | Path: 0.description | Search_query: None | Data: ", + "bepatient.waiter_src.checkers.checker", + 10, + "Check uuid: TEST | Checker: SQLChecker | Comparer: comparer" + " | Dictor_fallback: missing | Expected_value: | Path: 0.description" + " | Search_query: None | Data: ", ), ( "bepatient_db.sql_checkers", 20, - "Check uuid: TestSQLChecker | Data: [{'description': ''}]", + "Check uuid: TEST | Data: [{'description': ''}]", + ), + ( + "bepatient.waiter_src.checkers.checker", + 20, + "Check success! | uuid: TEST | Checker: SQLChecker | Comparer: comparer" + " | Dictor_fallback: missing | Expected_value: | Path: 0.description" + " | Search_query: None | Data: ", ), ] checker = SQLChecker( @@ -188,7 +198,7 @@ def test_empty_string_value( "SELECT description from tests WHERE id = 2" ).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True assert caplog.record_tuples == logs @pytest.mark.xfail(reason="The dictor library bug") @@ -196,9 +206,7 @@ def test_search_for_null_value( self, sqlite_db: sqlite3.Cursor, is_equal: Callable[[Any, Any], bool], - monkeypatch: pytest.MonkeyPatch, ): - monkeypatch.setattr("uuid.uuid4", lambda: "TestSQLChecker") checker = SQLChecker( comparer=is_equal, expected_value=[None], @@ -209,28 +217,33 @@ def test_search_for_null_value( "SELECT description from tests WHERE id = 1" ).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True def test_search_for_empty_string_value( self, sqlite_db: sqlite3.Cursor, is_equal: Callable[[Any, Any], bool], caplog: LogCaptureFixture, - monkeypatch: pytest.MonkeyPatch, ): - monkeypatch.setattr("uuid.uuid4", lambda: "TestSQLChecker") logs = [ ( - "bepatient.waiter_src.checker", - 20, - "Check uuid: TestSQLChecker | Checker: SQLChecker | Comparer: comparer" + "bepatient.waiter_src.checkers.checker", + 10, + "Check uuid: TEST | Checker: SQLChecker | Comparer: comparer" " | Dictor_fallback: missing | Expected_value: [''] | Path: None" " | Search_query: description | Data: ['']", ), ( "bepatient_db.sql_checkers", 20, - "Check uuid: TestSQLChecker | Data: [{'description': ''}]", + "Check uuid: TEST | Data: [{'description': ''}]", + ), + ( + "bepatient.waiter_src.checkers.checker", + 20, + "Check success! | uuid: TEST | Checker: SQLChecker | Comparer: comparer" + " | Dictor_fallback: missing | Expected_value: [''] | Path: None" + " | Search_query: description | Data: ['']", ), ] checker = SQLChecker( @@ -243,5 +256,5 @@ def test_search_for_empty_string_value( "SELECT description from tests WHERE id = 2" ).fetchall() - assert checker.check(checker_data) is True + assert checker.check(checker_data, "TEST") is True assert caplog.record_tuples == logs diff --git a/tests/test_sql_executor.py b/tests/test_sql_executor.py index c14bdfd..a1cefea 100644 --- a/tests/test_sql_executor.py +++ b/tests/test_sql_executor.py @@ -2,7 +2,7 @@ import pytest from _pytest.logging import LogCaptureFixture -from bepatient.waiter_src.checker import Checker +from bepatient.waiter_src.checkers.checker import Checker from bepatient.waiter_src.exceptions.executor_exceptions import ExecutorIsNotReady from bepatient_db.sql_executor import SQLExecutor