-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reset error and response in the retry context (#14)
- Loading branch information
Showing
7 changed files
with
356 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[tool.poetry] | ||
name = "meatie" | ||
version = "0.1.1" | ||
description = "Meatie is a Python metaprogramming library that eliminates the need for boilerplate code when integrating with REST APIs. The library generates code for calling a REST API based on method signatures annotated with type hints. Ribeye abstracts away mechanics related to HTTP communication, such as building URLs, encoding query parameters, parsing, and dumping Pydantic models. With some modest additional configuration effort, generated HTTP clients offer rate limiting, retries, and caching." | ||
description = "Meatie is a Python typed REST client library that eliminates the need for boilerplate code when integrating with external APIs. The library generates code for calling a REST API based on method signatures annotated with type hints. Ribeye abstracts away mechanics related to HTTP communication, such as building URLs, encoding query parameters, parsing, and dumping Pydantic models. With some modest additional configuration effort, generated HTTP clients offer rate limiting, retries, and caching." | ||
authors = ["pmateusz <[email protected]>"] | ||
readme = "README.md" | ||
keywords = ["http-client", "metaprogramming", "REST", "HTTP"] | ||
keywords = ["http-client", "metaprogramming", "REST", "HTTP", "API", "requests", "httpx", "aiohttp", "pydantic", "type-hints"] | ||
homepage = "https://github.com/pmateusz/meatie" | ||
repository = "https://github.com/pmateusz/meatie" | ||
license = "BSD-3-Clause" | ||
|
@@ -36,10 +36,11 @@ pytest = ">=7.4.3" | |
pytest-asyncio = ">=0.23.2" | ||
cryptography = ">=42.0.2" | ||
|
||
[tool.poetry.group.pre-commit] | ||
[tool.poetry.group.dev] | ||
optional = true | ||
|
||
[tool.poetry.group.pre-commit.dependencies] | ||
[tool.poetry.group.dev.dependencies] | ||
mypy = ">=1.9.0" | ||
pre-commit = ">=3.6.0" | ||
virtualenv = ">=20.25.0" | ||
|
||
|
@@ -55,8 +56,29 @@ log_cli = true | |
pythonpath = ["src", "tests/shared"] | ||
addopts = ["--import-mode=importlib"] | ||
|
||
|
||
[tool.mypy] | ||
mypy_path = ["$MYPY_CONFIG_FILE_DIR/src", "$MYPY_CONFIG_FILE_DIR/tests/shared"] | ||
cache_dir = "./.mypy" | ||
pretty = true | ||
allow_empty_bodies = true | ||
check_untyped_defs = true | ||
disallow_any_generics = true | ||
disallow_any_unimported = true | ||
disallow_incomplete_defs = true | ||
disallow_untyped_defs = true | ||
disallow_untyped_decorators = true | ||
disallow_untyped_calls = true | ||
explicit_package_bases = true | ||
local_partial_types = true | ||
no_warn_no_return = true | ||
no_implicit_reexport = true | ||
show_error_context = true | ||
strict_equality = true | ||
warn_unreachable = true | ||
warn_redundant_casts = true | ||
warn_unused_ignores = true | ||
warn_unused_configs = true | ||
|
||
[tool.coverage.run] | ||
branch = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2024 The Meatie Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
from unittest.mock import Mock | ||
|
||
from meatie import Context, has_exception_type, never, zero | ||
from meatie.option.retry_option import RetryOperator | ||
|
||
|
||
def test_exception_is_reset() -> None: | ||
# GIVEN | ||
successful_response = Mock() | ||
operator = RetryOperator( | ||
on=has_exception_type(RuntimeError), wait=zero, stop=never, sleep_func=Mock() | ||
) | ||
ctx = Mock(spec=Context) | ||
call_count = 0 | ||
|
||
def on_proceed() -> Mock: | ||
nonlocal call_count | ||
|
||
call_count += 1 | ||
if call_count == 1: | ||
raise RuntimeError() | ||
|
||
ctx.response = successful_response | ||
return ctx.response | ||
|
||
ctx.proceed = Mock(side_effect=on_proceed) | ||
|
||
# WHEN | ||
response = operator(ctx) | ||
|
||
# THEN | ||
assert ctx.proceed.call_count == 2 | ||
assert response is successful_response |