Skip to content

Commit

Permalink
Merge pull request #192 from hf-kklein/mypy-strict
Browse files Browse the repository at this point in the history
  • Loading branch information
mj0nez authored Dec 8, 2024
2 parents 8ccc1e9 + 17d13e9 commit 6c520c0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/bdew_datetimes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .calendar import create_bdew_calendar

GERMAN_TIME_ZONE = timezone("Europe/Berlin")
__all__ = ["GERMAN_TIME_ZONE", "create_bdew_calendar"]
7 changes: 4 additions & 3 deletions src/bdew_datetimes/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""

from datetime import date
from typing import Any

from holidays import HolidayBase, HolidaySum
from holidays.constants import APR, DEC
from holidays.constants import APR, DEC # type:ignore[attr-defined]
from holidays.countries.germany import Germany


Expand All @@ -21,10 +22,10 @@ class BdewDefinedHolidays(HolidayBase):
"""

def __init__(self, observed: bool = False, **kwargs):
def __init__(self, observed: bool = False, **kwargs: Any) -> None:
super().__init__(observed=observed, **kwargs)

def _populate(self, year):
def _populate(self, year: int) -> None:
self[date(year, DEC, 24)] = "Heiligabend"
self[date(year, DEC, 31)] = "Silvester"
if year == 2025:
Expand Down
2 changes: 1 addition & 1 deletion src/bdew_datetimes/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Literal, Optional, Union

from dateutil.relativedelta import relativedelta
from holidays import SAT, SUN
from holidays import SAT, SUN # type:ignore[attr-defined]

from bdew_datetimes import GERMAN_TIME_ZONE, create_bdew_calendar

Expand Down
12 changes: 7 additions & 5 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date, datetime

import pytest # type:ignore[import]
import pytest
from holidays import DateLike

from bdew_datetimes.calendar import BdewDefinedHolidays, create_bdew_calendar
Expand All @@ -15,7 +15,7 @@
pytest.param(date(2070, 12, 24), id="arbitrary Heiligabend"),
],
)
def test_bdew_holidays(expected_holiday: date):
def test_bdew_holidays(expected_holiday: date) -> None:
calendar = BdewDefinedHolidays()
assert expected_holiday in calendar

Expand All @@ -33,15 +33,17 @@ def test_bdew_holidays(expected_holiday: date):
pytest.param(date(2025, 4, 4), True, id="Sonderfeiertag 2025 (BDEW)"),
],
)
def test_create_bdew_calendar(test_date: date, expected_is_in_calendar: bool):
def test_create_bdew_calendar(
test_date: date, expected_is_in_calendar: bool
) -> None:
calendar = create_bdew_calendar()
if expected_is_in_calendar:
assert test_date in calendar
else:
assert test_date not in calendar


def test_holiday_calendar_obj():
def test_holiday_calendar_obj() -> None:
calendar = create_bdew_calendar()

assert not calendar.observed
Expand All @@ -62,6 +64,6 @@ def test_holiday_calendar_obj():
pytest.param(int(datetime(2022, 1, 1, 22, 16, 59).timestamp())),
],
)
def test_holiday_in_calendar(candidate: DateLike):
def test_holiday_in_calendar(candidate: DateLike) -> None:
calendar = create_bdew_calendar()
assert candidate in calendar
20 changes: 13 additions & 7 deletions tests/test_german_strom_and_gas_tag.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from datetime import datetime, timedelta, timezone

import pytest # type:ignore[import]
import pytest

from bdew_datetimes import GERMAN_TIME_ZONE
from bdew_datetimes.german_strom_and_gas_tag import (
GERMAN_TIME_ZONE,
Division,
has_no_utc_offset,
is_gastag_limit,
Expand Down Expand Up @@ -87,7 +87,7 @@
)
def test_stromtag(
dt: datetime, expected_is_start_or_end_of_german_stromtag: bool
):
) -> None:
actual = is_stromtag_limit(dt)
assert actual == expected_is_start_or_end_of_german_stromtag

Expand Down Expand Up @@ -153,7 +153,9 @@ def test_stromtag(
),
],
)
def test_gastag(dt: datetime, expected_is_start_or_end_of_german_gastag: bool):
def test_gastag(
dt: datetime, expected_is_start_or_end_of_german_gastag: bool
) -> None:
actual = is_gastag_limit(dt)
assert actual == expected_is_start_or_end_of_german_gastag

Expand All @@ -170,7 +172,9 @@ def test_gastag(dt: datetime, expected_is_start_or_end_of_german_gastag: bool):
),
],
)
def test_has_no_utc_offset(dt: datetime, expected_has_not_utc_offset: bool):
def test_has_no_utc_offset(
dt: datetime, expected_has_not_utc_offset: bool
) -> None:
actual = has_no_utc_offset(dt)
assert actual == expected_has_not_utc_offset

Expand All @@ -181,7 +185,7 @@ def test_has_no_utc_offset(dt: datetime, expected_has_not_utc_offset: bool):
pytest.param(datetime(2020, 1, 1, 0, 0, 0, tzinfo=timezone.utc), 0),
],
)
def test_is_xtag_limit_raises(dt: datetime, division: Division):
def test_is_xtag_limit_raises(dt: datetime, division: Division) -> None:
with pytest.raises(NotImplementedError):
is_xtag_limit(date_time=dt, division=division)

Expand Down Expand Up @@ -231,6 +235,8 @@ def test_is_xtag_limit_raises(dt: datetime, division: Division):
),
],
)
def test_is_xtag_limit(dt: datetime, division: Division, expected):
def test_is_xtag_limit(
dt: datetime, division: Division, expected: bool
) -> None:
actual = is_xtag_limit(dt, division)
assert actual == expected
20 changes: 10 additions & 10 deletions tests/test_period.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date

import pytest # type:ignore[import]
import pytest

from bdew_datetimes.periods import (
DayType,
Expand All @@ -15,13 +15,13 @@
)


def test_period_instantiation_with_enum():
def test_period_instantiation_with_enum() -> None:
period = Period(42, DayType.WORKING_DAY)
assert period.number_of_days == 42
assert period.day_type == DayType.WORKING_DAY


def test_period_instantiation_with_enum_and_inclusive_end():
def test_period_instantiation_with_enum_and_inclusive_end() -> None:
period = Period(
42, DayType.WORKING_DAY, end_date_type=EndDateType.INCLUSIVE
)
Expand All @@ -38,15 +38,15 @@ def test_period_instantiation_with_enum_and_inclusive_end():
)
def test_period_instantiation_with_str(
number_of_days: int, str_daytype: _DayTyp, expected: Period
):
) -> None:
actual = Period(number_of_days, str_daytype)
assert actual == expected


def test_instantiation_with_invalid_str():
def test_instantiation_with_invalid_str() -> None:
with pytest.raises(ValueError):
_ = Period(
42, "Foo" # type:ignore[argument] # literal is intentionally wrong
42, "Foo" # type:ignore[arg-type] # literal is intentionally wrong
)


Expand All @@ -72,7 +72,7 @@ def test_instantiation_with_invalid_str():
),
],
)
def test_get_next_working_day(start: date, expected: date):
def test_get_next_working_day(start: date, expected: date) -> None:
actual = get_next_working_day(start)
assert actual == expected

Expand All @@ -96,7 +96,7 @@ def test_get_next_working_day(start: date, expected: date):
),
],
)
def test_get_previous_working_day(start: date, expected: date):
def test_get_previous_working_day(start: date, expected: date) -> None:
actual = get_previous_working_day(start)
assert actual == expected

Expand Down Expand Up @@ -226,7 +226,7 @@ def test_get_previous_working_day(start: date, expected: date):
),
],
)
def test_add_frist(start: date, frist: Period, expected: date):
def test_add_frist(start: date, frist: Period, expected: date) -> None:
actual = add_frist(start, frist)
assert actual == expected

Expand Down Expand Up @@ -350,6 +350,6 @@ def test_add_frist(start: date, frist: Period, expected: date):
)
def test_get_nth_working_day_of_month(
number: int, start: date, month_type: MonthType, expected: date
):
) -> None:
actual = get_nth_working_day_of_month(number, month_type, start)
assert actual == expected
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ commands =
# the type_check environment checks the type hints using mypy
deps =
-r requirements.txt
.[tests]
.[type_check]
setenv = PYTHONPATH = {toxinidir}/src
commands =
mypy --show-error-codes src/bdew_datetimes
mypy --show-error-codes tests
mypy --show-error-codes --strict src/bdew_datetimes
mypy --show-error-codes --strict tests

[testenv:format]
# install isort and black and invoke them on the current folder
Expand Down

0 comments on commit 6c520c0

Please sign in to comment.