Skip to content

Commit

Permalink
Refactor tests in test_main.py for improved clarity and consistency
Browse files Browse the repository at this point in the history
- Simplified test function definitions by using ellipsis directly in the decorator.
- Updated datetime import to use `datetime.UTC` for better clarity.
- Added whitespace for improved readability in test cases.

These changes enhance the maintainability of the test suite and ensure consistent coding practices.
  • Loading branch information
leshchenko1979 committed Dec 19, 2024
1 parent 69bcf6b commit c2c1c33
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,21 @@ def test_typing(cache):
with pytest.raises(BeartypeCallHintParamViolation):

@cache(ttl=10)
def get_data():
...
def get_data(): ...

with pytest.raises(ViolationError):

@cache(ignore=["abc"])
def get_data():
...
def get_data(): ...

with pytest.raises(ViolationError):

@cache(ttl=dt.timedelta(days=-1))
def get_data():
...
def get_data(): ...


def test_class_method_with_params(cache):
from datetime import datetime, timedelta, UTC
from datetime import datetime, timedelta
from pathlib import Path
from perscache import Cache
from perscache.storage import LocalFileStorage
Expand All @@ -117,11 +114,12 @@ def cache_method(self, what: str, when: datetime):
return f"What: {what}, Timestamp: {when.isoformat()}"

pt = PerscacheTest()
pt.cache_method("This thing happened", datetime.now(tz=UTC))
pt.cache_method("This thing happened", datetime.now(tz=datetime.UTC))


def test_sync_class_method(cache):
"""Test that sync class methods work correctly with caching."""

class Calculator:
def __init__(self):
self.compute_count = 0
Expand All @@ -146,6 +144,7 @@ def add(self, a: int, b: int) -> int:

def test_sync_class_method_multiple_instances(cache):
"""Test that caches for different instances of the same class don't clash."""

class Counter:
def __init__(self, id: str):
self.id = id
Expand Down

0 comments on commit c2c1c33

Please sign in to comment.