Skip to content

Commit

Permalink
chore(tests): add new test http
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainmouquet committed Sep 26, 2024
1 parent 6509809 commit ea04add
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ lint:
uv run ruff format
uv run ruff format --check

# Update dependencies
.PHONY: update
update:
uv sync

# Check for outdated dependencies
.PHONY: check-deps
check-deps:
uv pip list

# Display all available commands
.PHONY: help
help:
Expand All @@ -62,4 +72,6 @@ help:
@echo " install-local - Install the build locally"
@echo " test - Run tests"
@echo " lint - Run linter"
@echo " update - Update dependencies"
@echo " check-deps - Check for outdated dependencies"
@echo " help - Display this help message"
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
]
license = { text = "MIT" }
url = "https://github.com/sylvainmouquet/reattempt"
keywords = ["retry", "decorator", "python", "exponential backoff", "exception handling"]
keywords = ["retry", "decorator", "python", "exponential backoff", "exception handling", "sync", "async", "generator", "async gen"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand All @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Libraries :: Python Modules"
]

[project.urls]
Expand All @@ -40,8 +40,12 @@ dev-dependencies = [
"pytest-mock>=3.14.0",
"pytest>=8.3.3",
"ruff>=0.6.7",
"reattempt>=0.0.1"
"reattempt>=0.0.1",
"aiohttp>=3.10.6",
]

[tool.uv.sources]
reattempt = { path = "reattempt" }

[tool.hatch.build.targets.wheel]
packages = ["reattempt"]
1 change: 0 additions & 1 deletion reattempt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,3 @@ async def retry_async_gen_func(*args, **kwargs):
if func:
return decorator(func)
return decorator

36 changes: 36 additions & 0 deletions test/test_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from reattempt import reattempt
from test.conftest import MAX_ATTEMPTS, MIN_TIME, MAX_TIME
import pytest
import aiohttp


@reattempt(max_retries=MAX_ATTEMPTS, min_time=MIN_TIME, max_time=MAX_TIME)
async def async_aiohttp_call(status: int):
async_aiohttp_call.counter += 1

async with aiohttp.ClientSession() as session:
async with session.get(
f"https://httpbin.org/status/{status}", ssl=False
) as response:
response.raise_for_status()
return "OK"


@pytest.mark.asyncio
async def test_retry_http_200():
async_aiohttp_call.counter = 0 # type: ignore

await async_aiohttp_call(200)
assert async_aiohttp_call.counter == 1 # type: ignore


@pytest.mark.asyncio
async def test_retry_http_500():
async_aiohttp_call.counter = 0 # type: ignore

try:
await async_aiohttp_call(500)
pytest.fail("Must not come here")
except Exception:
print("Success")
assert async_aiohttp_call.counter == MAX_ATTEMPTS # type: ignore
Loading

0 comments on commit ea04add

Please sign in to comment.