Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collerek committed Feb 6, 2024
1 parent 68dbcf6 commit 644de37
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ormar/models/helpers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def serialize(
try:
return handler(children)
except ValueError as exc:
if not str(exc).startswith("Circular reference"):
if not str(exc).startswith("Circular reference"): # pragma: no cover
raise exc

result = []
Expand Down
8 changes: 4 additions & 4 deletions ormar/models/newbasemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def dict( # type: ignore # noqa A003
exclude_through_models: bool = False,
exclude_list: bool = False,
relation_map: Optional[Dict] = None,
) -> "DictStrAny": # noqa: A003'
) -> "DictStrAny": # noqa: A003 # pragma: no cover
warnings.warn(
"The `dict` method is deprecated; use `model_dump` instead.",
DeprecationWarning,
Expand Down Expand Up @@ -970,7 +970,7 @@ def json( # type: ignore # noqa A003
)
def construct(
cls: Type["T"], _fields_set: set[str] | None = None, **values: Any
) -> "T":
) -> "T": # pragma: no cover
warnings.warn(
"The `construct` method is deprecated; use `model_construct` instead.",
DeprecationWarning,
Expand All @@ -997,7 +997,7 @@ def model_construct(
_fields_set = set(values.keys())

_extra: dict[str, Any] | None = None
if cls.model_config.get("extra") == "allow":
if cls.model_config.get("extra") == "allow": # pragma: no cover
_extra = {}
for k, v in values.items():
_extra[k] = v
Expand All @@ -1010,7 +1010,7 @@ def model_construct(
if not cls.__pydantic_root_model__:
object.__setattr__(model, "__pydantic_extra__", _extra)

if cls.__pydantic_post_init__:
if cls.__pydantic_post_init__: # pragma: no cover
model.model_post_init(None)
elif not cls.__pydantic_root_model__:
# Note: if there are any private attributes,
Expand Down
14 changes: 9 additions & 5 deletions ormar/warnings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Adopted from pydantic
from typing import Optional, Tuple


class OrmarDeprecationWarning(DeprecationWarning):
"""A Pydantic specific deprecation warning.
Expand All @@ -12,15 +16,15 @@ class OrmarDeprecationWarning(DeprecationWarning):
"""

message: str
since: tuple[int, int]
expected_removal: tuple[int, int]
since: Tuple[int, int]
expected_removal: Tuple[int, int]

def __init__(
self,
message: str,
*args: object,
since: tuple[int, int],
expected_removal: tuple[int, int] | None = None,
since: Tuple[int, int],
expected_removal: Optional[Tuple[int, int]] = None,
) -> None:
super().__init__(message, *args)
self.message = message.rstrip(".")
Expand All @@ -29,7 +33,7 @@ def __init__(
expected_removal if expected_removal is not None else (since[0] + 1, 0)
)

def __str__(self) -> str:
def __str__(self) -> str: # pragma: no cover
message = (
f"{self.message}. Deprecated in Ormar V{self.since[0]}.{self.since[1]}"
f" to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}."
Expand Down

0 comments on commit 644de37

Please sign in to comment.