Skip to content

Commit

Permalink
More cov for types
Browse files Browse the repository at this point in the history
  • Loading branch information
cutoffthetop committed Dec 15, 2023
1 parent 4befba1 commit 748b552
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions mex/common/types/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __eq__(self, other: Any) -> bool:
try:
other = self.validate(other)
except TypeError:
return NotImplemented
raise NotImplementedError()
return bool(
self.date_time == other.date_time and self.precision == other.precision
)
Expand All @@ -243,7 +243,7 @@ def __gt__(self, other: Any) -> bool:
try:
other = self.validate(other)
except TypeError:
return NotImplemented
raise NotImplementedError()
return bool(self.date_time > other.date_time)

def __str__(self) -> str:
Expand Down
7 changes: 1 addition & 6 deletions tests/types/test_link.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from pydantic import BaseModel, ValidationError
from pydantic import BaseModel

from mex.common.types import Link, LinkLanguage

Expand Down Expand Up @@ -40,10 +39,6 @@ class DummyModel(BaseModel):
}
}

# invalid data
with pytest.raises(ValidationError):
DummyModel.model_validate(["lists", "are", "not", "valid"])


def test_rendering_as_string() -> None:
# plain link
Expand Down
45 changes: 45 additions & 0 deletions tests/types/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any

import pytest
from pytz import timezone

from mex.common.types import CET, UTC, Timestamp

Expand Down Expand Up @@ -59,6 +60,11 @@ def test_timestamp_validation_errors(value: Any, message: str) -> None:
{},
"1999-01-20T21:00:00Z",
),
(
("2016-06-10T21:42:24.76073899Z",),
{},
"2016-06-10T21:42:24Z",
),
(
(date(2020, 3, 22),),
{},
Expand All @@ -69,6 +75,15 @@ def test_timestamp_validation_errors(value: Any, message: str) -> None:
{},
"2020-03-22T13:30:58Z",
),
(
(
datetime(
2020, 3, 22, 14, 30, 58, tzinfo=timezone("America/Los_Angeles")
),
),
{},
"2020-03-22T22:23:58Z",
),
(
(Timestamp(2004, 11),),
{},
Expand All @@ -86,8 +101,10 @@ def test_timestamp_validation_errors(value: Any, message: str) -> None:
"date string",
"time string",
"padded time",
"nano seconds",
"date",
"datetime",
"pacific time",
"timestamp",
],
)
Expand All @@ -96,3 +113,31 @@ def test_timestamp_parsing(
) -> None:
timestamp = Timestamp(*args, **kwargs)
assert str(timestamp) == expected


def test_timestamp_eq() -> None:
assert Timestamp(2004) == Timestamp("2004")
assert Timestamp(2004, 11) == Timestamp(2004, 11)
assert Timestamp(2004, 11, 2) == "2004-11-02"
assert Timestamp(2020, 3, 22, 14, 30, 58, 0) == datetime(2020, 3, 22, 14, 30, 58, 0)

with pytest.raises(NotImplementedError):
assert Timestamp(2005) == object()


def test_timestamp_gt() -> None:
assert Timestamp(2004) > Timestamp("2003")
assert Timestamp(2004, 11) < "2013-10-02"
assert Timestamp(2004, 11) <= Timestamp(2004, 12)
assert Timestamp(2020, 3, 22, 14, 30, 58) >= datetime(2020, 3, 22, 14, 29)

with pytest.raises(NotImplementedError):
assert Timestamp(2005) > object()


def test_timestamp_str() -> None:
assert str(Timestamp(2004, 11, 26)) == "2004-11-26"


def test_timestamp_repr() -> None:
assert repr(Timestamp(2018, 3, 2, 13, 0, 1)) == 'Timestamp("2018-03-02T12:00:01Z")'

0 comments on commit 748b552

Please sign in to comment.