Skip to content

Commit

Permalink
tests: serde test
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Sep 13, 2024
1 parent 56b0e52 commit 2c470f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ Repository = "https://github.com/phi-friday/timeout-executor"

[project.optional-dependencies]
uvloop = ["uvloop; platform_system != 'Windows'"]
test = ["pytest>=8.0.2", "trio>=0.24.0"]
test = [
"httpx>=0.27.2",
"pytest>=8.0.2",
"trio>=0.24.0",
]

[tool.uv]
managed = true
Expand Down
3 changes: 1 addition & 2 deletions src/timeout_executor/serde.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import pickle
import sys
from collections import deque
from collections.abc import Mapping
Expand Down Expand Up @@ -78,7 +77,7 @@ def serialize_error(error: BaseException) -> SerializedError:
reduce_mapping[key] = serialize_error(value)
continue

with suppress(pickle.PicklingError):
with suppress(Exception):
reduce_mapping[key] = cloudpickle.dumps(value)

# TODO: ... __reduce_ex__ args[3:]
Expand Down
28 changes: 28 additions & 0 deletions tests/test_serde.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# pyright: reportUnknownParameterType=false
# pyright: reportMissingParameterType=false
# pyright: reportImplicitOverride=false
from __future__ import annotations

from typing import Any

import httpx

from timeout_executor import serde


def test_httpx_reduce_ex():
def f() -> Any:
try:
httpx.get("http:://invalid/")
except Exception as e: # noqa: BLE001
return e
return None

error = f()
assert isinstance(error, httpx.UnsupportedProtocol)

ser_error = serde.serialize_error(error)
de_error = serde.deserialize_error(ser_error)

assert isinstance(de_error, httpx.UnsupportedProtocol)
assert hasattr(de_error, "request")

0 comments on commit 2c470f8

Please sign in to comment.