Skip to content

Commit

Permalink
OPT: add Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Oct 24, 2024
1 parent e51cf94 commit ec42541
Show file tree
Hide file tree
Showing 8 changed files with 848 additions and 775 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- '3.10'
- '3.11'
- '3.12'
- '3.13'

services:
redis:
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SRC := cachetory tests
DJANGO_SETTINGS_MODULE := tests.backends.django.settings
SRC = cachetory tests

.PHONY: all
all: install lint test build docs
Expand Down Expand Up @@ -37,7 +36,7 @@ format/ruff:

.PHONY: test
test:
poetry run pytest tests
DJANGO_SETTINGS_MODULE=tests.backends.django.settings poetry run pytest tests

.PHONY: build
build:
Expand Down
1,593 changes: 832 additions & 761 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP",
"Typing :: Typed",
]
Expand All @@ -35,7 +36,7 @@ build-backend = "poetry_dynamic_versioning.backend"
[tool.poetry.dependencies]
django = {version = "^4.0.0 || ^5.0.0", optional = true}
ormsgpack = {version = "^1.4.0", optional = true, markers = "platform_python_implementation == 'CPython'"}
pydantic = ">2.0.0.0, <3.0.0.0"
pydantic = "^2.0.0"
python = "^3.9.0"
redis = {version = "^4.4.2 || ^5.0.0", optional = true}
typing-extensions = "^4.4.0"
Expand Down Expand Up @@ -144,6 +145,7 @@ strict = true
[tool.pytest.ini_options]
addopts = "--cov=./ --cov-report=xml"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.coverage.run]
source = ["cachetory"]
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/async_/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pytest.fixture
async def backend() -> AsyncIterable[DjangoBackend[int]]:
async with DjangoBackend[int].from_url("django://default") as backend:
backend.clear()
await backend.clear()
try:
yield backend
finally:
Expand Down
1 change: 1 addition & 0 deletions tests/backends/django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
"LOCATION": "unique-snowflake",
},
}
USE_TZ = True
6 changes: 3 additions & 3 deletions tests/decorators/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ async def ttl(key: str) -> timedelta:
async def expensive_function(**kwargs: Any) -> int:
return 1

with mock.patch.object(cache, "set", wraps=cache.set) as m_set:
with mock.patch.object(Cache, "set", wraps=cache.set) as set_mock:
assert await expensive_function(a="a") == 1

m_set.assert_called_with(mock.ANY, mock.ANY, time_to_live=timedelta(seconds=42), if_not_exists=mock.ANY)
set_mock.assert_called_with(mock.ANY, mock.ANY, time_to_live=timedelta(seconds=42), if_not_exists=mock.ANY)


async def test_exclude(cache: Cache[int, int]) -> None:
@cached(
cache,
make_key=lambda _, arg: str(arg),
exclude=lambda key_, value_: int(key_) + value_ < 40,
exclude=lambda key, _: key == "5",
)
async def power_function(arg: int) -> int:
return arg**2
Expand Down
11 changes: 5 additions & 6 deletions tests/decorators/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,23 @@ def ttl(key: str) -> timedelta:
def expensive_function(**kwargs: Any) -> int:
return 1

with mock.patch.object(cache, "set", wraps=cache.set) as m_set:
with mock.patch.object(Cache, "set", wraps=cache.set) as set_mock:
assert expensive_function(a="a") == 1

m_set.assert_called_with(mock.ANY, mock.ANY, time_to_live=timedelta(seconds=42), if_not_exists=mock.ANY)
set_mock.assert_called_with(mock.ANY, mock.ANY, time_to_live=timedelta(seconds=42), if_not_exists=mock.ANY)


def test_exclude(cache: Cache[int, int]) -> None:
@cached(
cache,
make_key=lambda _, arg: str(arg),
exclude=lambda key_, value_: int(key_) + value_ < 40,
exclude=lambda key, _: key == "5",
)
def power_function(arg: int) -> int:
return arg**2

with mock.patch.object(cache, "set", wraps=cache.set):
assert power_function(5) == 25
assert power_function(6) == 36
assert power_function(5) == 25
assert power_function(6) == 36

assert cache.get("5") is None
assert cache.get("6") == 36
Expand Down

0 comments on commit ec42541

Please sign in to comment.