From 91a53dad11a897b431337ac6a6596fea2c1e1690 Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:55:37 +0200 Subject: [PATCH 1/4] enable `pytest` formatting with Ruff's PT (#234) * enable pytes formating with Ruff's PT * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixing * Apply suggestions from code review * fixing --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pyproject.toml | 1 + tests/test_defaults.py | 2 +- tests/test_general.py | 4 ++-- tests/test_memory_core.py | 24 ++++++++++++------------ tests/test_mongo_core.py | 29 +++++++++++++++-------------- tests/test_pickle_core.py | 32 ++++++++++++++++---------------- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6ee78d36..8347a40c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,6 +92,7 @@ lint.extend-select = [ "A", # see: https://pypi.org/project/flake8-builtins "B", # see: https://pypi.org/project/flake8-bugbear "C4", # see: https://pypi.org/project/flake8-comprehensions + "PT", # see: https://pypi.org/project/flake8-pytest-style ] lint.ignore = [ "C901", diff --git a/tests/test_defaults.py b/tests/test_defaults.py index 3e548046..06a05073 100644 --- a/tests/test_defaults.py +++ b/tests/test_defaults.py @@ -64,7 +64,7 @@ def global_test_2(): assert global_test_2.cache_dpath() is not None -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongetter_default_param(): cachier.set_default_params(mongetter=_test_mongetter) diff --git a/tests/test_general.py b/tests/test_general.py index 9d5d47a0..caca0170 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -154,7 +154,7 @@ def _calls_wait_for_calc_timeout_slow(res_queue): @pytest.mark.parametrize( - "mongetter,backend", + ("mongetter", "backend"), [ pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo), (None, "memory"), @@ -176,7 +176,7 @@ def dummy_func(arg_1, arg_2): @pytest.mark.parametrize( - "mongetter,backend", + ("mongetter", "backend"), [ pytest.param(_test_mongetter, "mongo", marks=pytest.mark.mongo), (None, "memory"), diff --git a/tests/test_memory_core.py b/tests/test_memory_core.py index 14e7e935..a81a213f 100644 --- a/tests/test_memory_core.py +++ b/tests/test_memory_core.py @@ -19,7 +19,7 @@ def _takes_2_seconds(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.memory +@pytest.mark.memory() def test_memory_core(): """Basic memory core functionality.""" _takes_2_seconds.clear_cache() @@ -31,7 +31,7 @@ def test_memory_core(): _takes_2_seconds.clear_cache() -@pytest.mark.memory +@pytest.mark.memory() def test_memory_core_keywords(): """Basic memory core functionality with keyword arguments.""" _takes_2_seconds.clear_cache() @@ -53,7 +53,7 @@ def _stale_after_seconds(arg_1, arg_2): return random() -@pytest.mark.memory +@pytest.mark.memory() def test_stale_after(): """Testing the stale_after functionality.""" _stale_after_seconds.clear_cache() @@ -74,7 +74,7 @@ def _stale_after_next_time(arg_1, arg_2): return random() -@pytest.mark.memory +@pytest.mark.memory() def test_stale_after_next_time(): """Testing the stale_after with next_time functionality.""" _stale_after_next_time.clear_cache() @@ -103,7 +103,7 @@ def _random_num_with_arg(a): return random() -@pytest.mark.memory +@pytest.mark.memory() def test_overwrite_cache(): """Tests that the overwrite feature works correctly.""" _random_num.clear_cache() @@ -127,7 +127,7 @@ def test_overwrite_cache(): _random_num_with_arg.clear_cache() -@pytest.mark.memory +@pytest.mark.memory() def test_ignore_cache(): """Tests that the ignore_cache feature works correctly.""" _random_num.clear_cache() @@ -165,7 +165,7 @@ def _calls_takes_time(res_queue): res_queue.put(res) -@pytest.mark.memory +@pytest.mark.memory() def test_memory_being_calculated(): """Testing memory core handling of being calculated scenarios.""" _takes_time.clear_cache() @@ -199,7 +199,7 @@ def _calls_being_calc_next_time(res_queue): res_queue.put(res) -@pytest.mark.memory +@pytest.mark.memory() def test_being_calc_next_time(): """Testing memory core handling of being calculated scenarios.""" _takes_time.clear_cache() @@ -241,7 +241,7 @@ def _delete_cache(arg_1, arg_2): return random() + arg_1 + arg_2 -@pytest.mark.memory +@pytest.mark.memory() def test_clear_being_calculated(): """Test memory core clear `being calculated` functionality.""" _takes_time.clear_cache() @@ -264,7 +264,7 @@ def test_clear_being_calculated(): assert res1 != res2 -@pytest.mark.memory +@pytest.mark.memory() def test_clear_being_calculated_with_empty_cache(): """Test memory core clear `being calculated` functionality.""" _takes_time.clear_cache() @@ -281,7 +281,7 @@ def _error_throwing_func(arg1): return 7 -@pytest.mark.memory +@pytest.mark.memory() def test_error_throwing_func(): # with res1 = _error_throwing_func(4) @@ -290,7 +290,7 @@ def test_error_throwing_func(): assert res1 == res2 -@pytest.mark.memory +@pytest.mark.memory() def test_callable_hash_param(): def _hash_func(args, kwargs): def _hash(obj): diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index c7afac14..c83aae2c 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -77,13 +77,13 @@ def _test_mongetter(): # === Mongo core tests === -@pytest.mark.mongo +@pytest.mark.mongo() def test_information(): print("\npymongo version: ", end="") print(pymongo.__version__) -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_index_creation(): """Basic Mongo core functionality.""" @@ -100,7 +100,7 @@ def _test_mongo_caching(arg_1, arg_2): assert _MongoCore._INDEX_NAME in collection.index_information() -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_core(): """Basic Mongo core functionality.""" @@ -123,7 +123,7 @@ def _test_mongo_caching(arg_1, arg_2): assert val6 == val5 -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_core_keywords(): """Basic Mongo core functionality with keyword arguments.""" @@ -150,7 +150,7 @@ def _test_mongo_caching(arg_1, arg_2): MONGO_DELTA_LONG = timedelta(seconds=10) -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_stale_after(): """Testing MongoDB core stale_after functionality.""" @@ -181,7 +181,7 @@ def _takes_time(arg_1, arg_2): res_queue.put(res) -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_being_calculated(): """Testing MongoDB core handling of being calculated scenarios.""" @@ -231,7 +231,7 @@ def _bad_mongetter(): return _BadMongoCollection(_test_mongetter) -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_write_failure(): """Testing MongoDB core handling of writing failure scenarios.""" @@ -241,12 +241,13 @@ def _func_w_bad_mongo(arg_1, arg_2): return random() + arg_1 + arg_2 with pytest.raises(OperationFailure): - val1 = _func_w_bad_mongo(1, 2) - val2 = _func_w_bad_mongo(1, 2) - assert val1 == val2 + _func_w_bad_mongo(1, 2) + with pytest.raises(OperationFailure): + _func_w_bad_mongo(1, 2) + # assert val1 == val2 -@pytest.mark.mongo +@pytest.mark.mongo() def test_mongo_clear_being_calculated(): """Testing MongoDB core clear_being_calculated.""" @@ -258,7 +259,7 @@ def _func_w_bad_mongo(arg_1, arg_2): _func_w_bad_mongo.clear_being_calculated() -@pytest.mark.mongo +@pytest.mark.mongo() def test_stalled_mongo_db_cache(): @cachier(mongetter=_test_mongetter) def _stalled_func(): @@ -271,7 +272,7 @@ def _stalled_func(): core.wait_on_entry_calc(key=None) -@pytest.mark.mongo +@pytest.mark.mongo() def test_stalled_mong_db_core(monkeypatch): def mock_get_entry(self, args, kwargs): return "key", {"being_calculated": True} @@ -327,7 +328,7 @@ def _stalled_func_3(): assert res == 1 -@pytest.mark.mongo +@pytest.mark.mongo() def test_callable_hash_param(): def _hash_func(args, kwargs): def _hash(obj): diff --git a/tests/test_pickle_core.py b/tests/test_pickle_core.py index 71298d12..831b82e7 100644 --- a/tests/test_pickle_core.py +++ b/tests/test_pickle_core.py @@ -47,7 +47,7 @@ def _takes_2_seconds(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("reload", [True, False]) @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core(reload, separate_files): @@ -67,7 +67,7 @@ def test_pickle_core(reload, separate_files): _takes_2_seconds_decorated.clear_cache() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core_keywords(separate_files): """Basic Pickle core functionality with keyword arguments.""" @@ -92,7 +92,7 @@ def _stale_after_seconds(arg_1, arg_2): return random() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_stale_after(separate_files): """Testing the stale_after functionality.""" @@ -119,7 +119,7 @@ def _stale_after_next_time(arg_1, arg_2): return random() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_stale_after_next_time(separate_files): """Testing the stale_after with next_time functionality.""" @@ -153,7 +153,7 @@ def _random_num_with_arg(a): return random() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_overwrite_cache(separate_files): """Tests that the overwrite feature works correctly.""" @@ -184,7 +184,7 @@ def test_overwrite_cache(separate_files): _random_num_with_arg_decorated.clear_cache() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_ignore_cache(separate_files): """Tests that the ignore_cache feature works correctly.""" @@ -228,7 +228,7 @@ def _calls_takes_time(takes_time_func, res_queue): res_queue.put(res) -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_being_calculated(separate_files): """Testing pickle core handling of being calculated scenarios.""" @@ -275,7 +275,7 @@ def _calls_being_calc_next_time(being_calc_func, res_queue): res_queue.put(res) -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_being_calc_next_time(separate_files): """Testing pickle core handling of being calculated scenarios.""" @@ -393,8 +393,8 @@ def _helper_bad_cache_file(sleeptime, separate_files): # we want this to succeed at least once -@pytest.mark.pickle -@pytest.mark.xfail +@pytest.mark.pickle() +@pytest.mark.xfail() @pytest.mark.parametrize("separate_files", [True, False]) def test_bad_cache_file(separate_files): """Test pickle core handling of bad cache files.""" @@ -484,8 +484,8 @@ def _helper_delete_cache_file(sleeptime, separate_files): return isinstance(res2, KeyError) or (res2 is None) -@pytest.mark.pickle -@pytest.mark.xfail +@pytest.mark.pickle() +@pytest.mark.xfail() @pytest.mark.parametrize("separate_files", [False, True]) def test_delete_cache_file(separate_files): """Test pickle core handling of missing cache files.""" @@ -497,7 +497,7 @@ def test_delete_cache_file(separate_files): raise AssertionError() -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [False, True]) def test_clear_being_calculated(separate_files): """Test pickle core clear `being calculated` functionality.""" @@ -516,7 +516,7 @@ def _error_throwing_func(arg1): return 7 -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_error_throwing_func(separate_files): # with @@ -546,7 +546,7 @@ def _takes_2_seconds_custom_dir(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core_custom_cache_dir(separate_files): """Basic Pickle core functionality.""" @@ -567,7 +567,7 @@ def test_pickle_core_custom_cache_dir(separate_files): assert path2test == EXPANDED_CUSTOM_DIR -@pytest.mark.pickle +@pytest.mark.pickle() @pytest.mark.parametrize("separate_files", [True, False]) def test_callable_hash_param(separate_files): def _hash_func(args, kwargs): From 074e5ab987200fcaabc9a4416d5fe742cef88b47 Mon Sep 17 00:00:00 2001 From: Jirka Borovec <6035284+Borda@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:03:31 +0200 Subject: [PATCH 2/4] ci/test: speed_eval (#232) --- .github/workflows/ci-test.yml | 4 +++- tests/test_defaults.py | 3 ++- tests/test_general.py | 4 +++- tests/test_mongo_core.py | 9 +++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 9a873cd4..ec403077 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -78,8 +78,10 @@ jobs: - name: Unit tests (DB) if: matrix.backend == 'db' run: pytest -m "mongo" + - name: Speed eval + run: python tests/speed_eval.py - - name: "Upload coverage to Codecov" + - name: Upload coverage to Codecov continue-on-error: true uses: codecov/codecov-action@v4 with: diff --git a/tests/test_defaults.py b/tests/test_defaults.py index 06a05073..26bd6959 100644 --- a/tests/test_defaults.py +++ b/tests/test_defaults.py @@ -8,8 +8,9 @@ import cachier import pytest -from tests.test_mongo_core import MONGO_DELTA, _test_mongetter +from tests.test_mongo_core import _test_mongetter +MONGO_DELTA = datetime.timedelta(seconds=3) _default_params = cachier.get_default_params().copy() diff --git a/tests/test_general.py b/tests/test_general.py index caca0170..3e8b8ec4 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1,5 +1,6 @@ """Non-core-specific tests for cachier.""" +import datetime import functools import os import queue @@ -20,10 +21,11 @@ ) from tests.test_mongo_core import ( - MONGO_DELTA_LONG, _test_mongetter, ) +MONGO_DELTA_LONG = datetime.timedelta(seconds=10) + def test_information(): print("\ncachier version: ", end="") diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index c83aae2c..36673cbc 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -6,7 +6,6 @@ import queue import sys import threading -from datetime import timedelta from random import random from time import sleep from urllib.parse import quote_plus @@ -146,16 +145,14 @@ def _test_mongo_caching(arg_1, arg_2): assert val6 == val5 -MONGO_DELTA = timedelta(seconds=3) -MONGO_DELTA_LONG = timedelta(seconds=10) - - @pytest.mark.mongo() def test_mongo_stale_after(): """Testing MongoDB core stale_after functionality.""" @cachier( - mongetter=_test_mongetter, stale_after=MONGO_DELTA, next_time=False + mongetter=_test_mongetter, + stale_after=datetime.timedelta(seconds=3), + next_time=False, ) def _stale_after_mongo(arg_1, arg_2): """Some function.""" From 84768d95b01dc7cccd404b78f202bf32be240bb5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:16:03 +0200 Subject: [PATCH 3/4] build(deps): bump pypa/gh-action-pypi-publish from 1.10.0 to 1.10.2 (#235) Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.10.0 to 1.10.2. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.10.0...v1.10.2) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13242680..a343390e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: name: cachier_dist path: dist - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@v1.10.0 + uses: pypa/gh-action-pypi-publish@v1.10.2 with: user: __token__ password: ${{ secrets.pypi_password }} From 5f5dd228c6fd473c89ee1abe344632742e953d1a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:01:23 +0300 Subject: [PATCH 4/4] [pre-commit.ci] pre-commit suggestions (#236) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit suggestions updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/crate-ci/typos: v1.22.9 → v1.26.0](https://github.com/crate-ci/typos/compare/v1.22.9...v1.26.0) - [github.com/pre-commit/mirrors-prettier: v3.1.0 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v3.1.0...v4.0.0-alpha.8) - [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.6.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.0...v0.6.9) - [github.com/tox-dev/pyproject-fmt: 2.1.3 → 2.2.4](https://github.com/tox-dev/pyproject-fmt/compare/2.1.3...2.2.4) - [github.com/abravalheri/validate-pyproject: v0.18 → v0.20.2](https://github.com/abravalheri/validate-pyproject/compare/v0.18...v0.20.2) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 12 ++++++------ tests/test_core_lookup.py | 1 + tests/test_defaults.py | 4 ++-- tests/test_general.py | 4 ++-- tests/test_memory_core.py | 25 +++++++++++++------------ tests/test_mongo_core.py | 29 +++++++++++++++-------------- tests/test_pickle_core.py | 33 +++++++++++++++++---------------- 7 files changed, 56 insertions(+), 52 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2d842f9..2cb41af9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -23,7 +23,7 @@ repos: - id: detect-private-key - repo: https://github.com/crate-ci/typos - rev: v1.22.9 + rev: v1.26.0 hooks: - id: typos # empty to do not write fixes @@ -47,7 +47,7 @@ repos: args: ["--number"] - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 + rev: v4.0.0-alpha.8 hooks: - id: prettier files: \.(json|yml|yaml|toml) @@ -60,7 +60,7 @@ repos: # - id: mypy - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 + rev: v0.6.9 hooks: # use black formatting - id: ruff-format @@ -71,11 +71,11 @@ repos: args: ["--fix"] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.1.3 + rev: 2.2.4 hooks: - id: pyproject-fmt additional_dependencies: [tox] - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.18 + rev: v0.20.2 hooks: - id: validate-pyproject diff --git a/tests/test_core_lookup.py b/tests/test_core_lookup.py index 39297d05..16ae7f81 100644 --- a/tests/test_core_lookup.py +++ b/tests/test_core_lookup.py @@ -1,6 +1,7 @@ """Testing a few basic cachier interfaces.""" import pytest + from cachier import cachier, get_default_params from cachier.cores.mongo import MissingMongetter diff --git a/tests/test_defaults.py b/tests/test_defaults.py index 26bd6959..5451d26c 100644 --- a/tests/test_defaults.py +++ b/tests/test_defaults.py @@ -5,9 +5,9 @@ import threading import time -import cachier import pytest +import cachier from tests.test_mongo_core import _test_mongetter MONGO_DELTA = datetime.timedelta(seconds=3) @@ -65,7 +65,7 @@ def global_test_2(): assert global_test_2.cache_dpath() is not None -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongetter_default_param(): cachier.set_default_params(mongetter=_test_mongetter) diff --git a/tests/test_general.py b/tests/test_general.py index 3e8b8ec4..81eb1ec2 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -10,8 +10,9 @@ from random import random from time import sleep, time -import cachier import pytest + +import cachier from cachier.core import ( DEFAULT_MAX_WORKERS, MAX_WORKERS_ENVAR_NAME, @@ -19,7 +20,6 @@ _max_workers, _set_max_workers, ) - from tests.test_mongo_core import ( _test_mongetter, ) diff --git a/tests/test_memory_core.py b/tests/test_memory_core.py index a81a213f..7e302046 100644 --- a/tests/test_memory_core.py +++ b/tests/test_memory_core.py @@ -9,6 +9,7 @@ import pandas as pd import pytest + from cachier import cachier @@ -19,7 +20,7 @@ def _takes_2_seconds(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.memory() +@pytest.mark.memory def test_memory_core(): """Basic memory core functionality.""" _takes_2_seconds.clear_cache() @@ -31,7 +32,7 @@ def test_memory_core(): _takes_2_seconds.clear_cache() -@pytest.mark.memory() +@pytest.mark.memory def test_memory_core_keywords(): """Basic memory core functionality with keyword arguments.""" _takes_2_seconds.clear_cache() @@ -53,7 +54,7 @@ def _stale_after_seconds(arg_1, arg_2): return random() -@pytest.mark.memory() +@pytest.mark.memory def test_stale_after(): """Testing the stale_after functionality.""" _stale_after_seconds.clear_cache() @@ -74,7 +75,7 @@ def _stale_after_next_time(arg_1, arg_2): return random() -@pytest.mark.memory() +@pytest.mark.memory def test_stale_after_next_time(): """Testing the stale_after with next_time functionality.""" _stale_after_next_time.clear_cache() @@ -103,7 +104,7 @@ def _random_num_with_arg(a): return random() -@pytest.mark.memory() +@pytest.mark.memory def test_overwrite_cache(): """Tests that the overwrite feature works correctly.""" _random_num.clear_cache() @@ -127,7 +128,7 @@ def test_overwrite_cache(): _random_num_with_arg.clear_cache() -@pytest.mark.memory() +@pytest.mark.memory def test_ignore_cache(): """Tests that the ignore_cache feature works correctly.""" _random_num.clear_cache() @@ -165,7 +166,7 @@ def _calls_takes_time(res_queue): res_queue.put(res) -@pytest.mark.memory() +@pytest.mark.memory def test_memory_being_calculated(): """Testing memory core handling of being calculated scenarios.""" _takes_time.clear_cache() @@ -199,7 +200,7 @@ def _calls_being_calc_next_time(res_queue): res_queue.put(res) -@pytest.mark.memory() +@pytest.mark.memory def test_being_calc_next_time(): """Testing memory core handling of being calculated scenarios.""" _takes_time.clear_cache() @@ -241,7 +242,7 @@ def _delete_cache(arg_1, arg_2): return random() + arg_1 + arg_2 -@pytest.mark.memory() +@pytest.mark.memory def test_clear_being_calculated(): """Test memory core clear `being calculated` functionality.""" _takes_time.clear_cache() @@ -264,7 +265,7 @@ def test_clear_being_calculated(): assert res1 != res2 -@pytest.mark.memory() +@pytest.mark.memory def test_clear_being_calculated_with_empty_cache(): """Test memory core clear `being calculated` functionality.""" _takes_time.clear_cache() @@ -281,7 +282,7 @@ def _error_throwing_func(arg1): return 7 -@pytest.mark.memory() +@pytest.mark.memory def test_error_throwing_func(): # with res1 = _error_throwing_func(4) @@ -290,7 +291,7 @@ def test_error_throwing_func(): assert res1 == res2 -@pytest.mark.memory() +@pytest.mark.memory def test_callable_hash_param(): def _hash_func(args, kwargs): def _hash(obj): diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index 36673cbc..26870571 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -14,13 +14,14 @@ import pymongo import pytest from birch import Birch # type: ignore[import-not-found] -from cachier import cachier -from cachier.cores.base import RecalculationNeeded -from cachier.cores.mongo import _MongoCore from pymongo.errors import OperationFailure from pymongo.mongo_client import MongoClient from pymongo_inmemory import MongoClient as InMemoryMongoClient +from cachier import cachier +from cachier.cores.base import RecalculationNeeded +from cachier.cores.mongo import _MongoCore + # === Enables testing vs a real MongoDB instance === @@ -76,13 +77,13 @@ def _test_mongetter(): # === Mongo core tests === -@pytest.mark.mongo() +@pytest.mark.mongo def test_information(): print("\npymongo version: ", end="") print(pymongo.__version__) -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_index_creation(): """Basic Mongo core functionality.""" @@ -99,7 +100,7 @@ def _test_mongo_caching(arg_1, arg_2): assert _MongoCore._INDEX_NAME in collection.index_information() -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_core(): """Basic Mongo core functionality.""" @@ -122,7 +123,7 @@ def _test_mongo_caching(arg_1, arg_2): assert val6 == val5 -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_core_keywords(): """Basic Mongo core functionality with keyword arguments.""" @@ -145,7 +146,7 @@ def _test_mongo_caching(arg_1, arg_2): assert val6 == val5 -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_stale_after(): """Testing MongoDB core stale_after functionality.""" @@ -178,7 +179,7 @@ def _takes_time(arg_1, arg_2): res_queue.put(res) -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_being_calculated(): """Testing MongoDB core handling of being calculated scenarios.""" @@ -228,7 +229,7 @@ def _bad_mongetter(): return _BadMongoCollection(_test_mongetter) -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_write_failure(): """Testing MongoDB core handling of writing failure scenarios.""" @@ -244,7 +245,7 @@ def _func_w_bad_mongo(arg_1, arg_2): # assert val1 == val2 -@pytest.mark.mongo() +@pytest.mark.mongo def test_mongo_clear_being_calculated(): """Testing MongoDB core clear_being_calculated.""" @@ -256,7 +257,7 @@ def _func_w_bad_mongo(arg_1, arg_2): _func_w_bad_mongo.clear_being_calculated() -@pytest.mark.mongo() +@pytest.mark.mongo def test_stalled_mongo_db_cache(): @cachier(mongetter=_test_mongetter) def _stalled_func(): @@ -269,7 +270,7 @@ def _stalled_func(): core.wait_on_entry_calc(key=None) -@pytest.mark.mongo() +@pytest.mark.mongo def test_stalled_mong_db_core(monkeypatch): def mock_get_entry(self, args, kwargs): return "key", {"being_calculated": True} @@ -325,7 +326,7 @@ def _stalled_func_3(): assert res == 1 -@pytest.mark.mongo() +@pytest.mark.mongo def test_callable_hash_param(): def _hash_func(args, kwargs): def _hash(obj): diff --git a/tests/test_pickle_core.py b/tests/test_pickle_core.py index 831b82e7..7bb67947 100644 --- a/tests/test_pickle_core.py +++ b/tests/test_pickle_core.py @@ -28,6 +28,7 @@ import hashlib import pandas as pd + from cachier import cachier from cachier.core import _default_params @@ -47,7 +48,7 @@ def _takes_2_seconds(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("reload", [True, False]) @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core(reload, separate_files): @@ -67,7 +68,7 @@ def test_pickle_core(reload, separate_files): _takes_2_seconds_decorated.clear_cache() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core_keywords(separate_files): """Basic Pickle core functionality with keyword arguments.""" @@ -92,7 +93,7 @@ def _stale_after_seconds(arg_1, arg_2): return random() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_stale_after(separate_files): """Testing the stale_after functionality.""" @@ -119,7 +120,7 @@ def _stale_after_next_time(arg_1, arg_2): return random() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_stale_after_next_time(separate_files): """Testing the stale_after with next_time functionality.""" @@ -153,7 +154,7 @@ def _random_num_with_arg(a): return random() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_overwrite_cache(separate_files): """Tests that the overwrite feature works correctly.""" @@ -184,7 +185,7 @@ def test_overwrite_cache(separate_files): _random_num_with_arg_decorated.clear_cache() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_ignore_cache(separate_files): """Tests that the ignore_cache feature works correctly.""" @@ -228,7 +229,7 @@ def _calls_takes_time(takes_time_func, res_queue): res_queue.put(res) -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_being_calculated(separate_files): """Testing pickle core handling of being calculated scenarios.""" @@ -275,7 +276,7 @@ def _calls_being_calc_next_time(being_calc_func, res_queue): res_queue.put(res) -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_being_calc_next_time(separate_files): """Testing pickle core handling of being calculated scenarios.""" @@ -393,8 +394,8 @@ def _helper_bad_cache_file(sleeptime, separate_files): # we want this to succeed at least once -@pytest.mark.pickle() -@pytest.mark.xfail() +@pytest.mark.pickle +@pytest.mark.xfail @pytest.mark.parametrize("separate_files", [True, False]) def test_bad_cache_file(separate_files): """Test pickle core handling of bad cache files.""" @@ -484,8 +485,8 @@ def _helper_delete_cache_file(sleeptime, separate_files): return isinstance(res2, KeyError) or (res2 is None) -@pytest.mark.pickle() -@pytest.mark.xfail() +@pytest.mark.pickle +@pytest.mark.xfail @pytest.mark.parametrize("separate_files", [False, True]) def test_delete_cache_file(separate_files): """Test pickle core handling of missing cache files.""" @@ -497,7 +498,7 @@ def test_delete_cache_file(separate_files): raise AssertionError() -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [False, True]) def test_clear_being_calculated(separate_files): """Test pickle core clear `being calculated` functionality.""" @@ -516,7 +517,7 @@ def _error_throwing_func(arg1): return 7 -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_error_throwing_func(separate_files): # with @@ -546,7 +547,7 @@ def _takes_2_seconds_custom_dir(arg_1, arg_2): return f"arg_1:{arg_1}, arg_2:{arg_2}" -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_pickle_core_custom_cache_dir(separate_files): """Basic Pickle core functionality.""" @@ -567,7 +568,7 @@ def test_pickle_core_custom_cache_dir(separate_files): assert path2test == EXPANDED_CUSTOM_DIR -@pytest.mark.pickle() +@pytest.mark.pickle @pytest.mark.parametrize("separate_files", [True, False]) def test_callable_hash_param(separate_files): def _hash_func(args, kwargs):