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

enable pytest formatting with Ruff's PT #234

Merged
merged 5 commits into from
Sep 19, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
24 changes: 12 additions & 12 deletions tests/test_memory_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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):
Expand Down
29 changes: 15 additions & 14 deletions tests/test_mongo_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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."""

Expand All @@ -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."""

Expand All @@ -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."""

Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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."""

Expand All @@ -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."""

Expand All @@ -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():
Expand All @@ -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}
Expand Down Expand Up @@ -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):
Expand Down
32 changes: 16 additions & 16 deletions tests/test_pickle_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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):
Expand Down
Loading