diff --git a/src/bdew_datetimes/__init__.py b/src/bdew_datetimes/__init__.py index e1d038c..516b4dc 100644 --- a/src/bdew_datetimes/__init__.py +++ b/src/bdew_datetimes/__init__.py @@ -7,3 +7,4 @@ from .calendar import create_bdew_calendar GERMAN_TIME_ZONE = timezone("Europe/Berlin") +__all__ = ["GERMAN_TIME_ZONE", "create_bdew_calendar"] diff --git a/src/bdew_datetimes/calendar.py b/src/bdew_datetimes/calendar.py index b3acd58..e0229d2 100644 --- a/src/bdew_datetimes/calendar.py +++ b/src/bdew_datetimes/calendar.py @@ -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 @@ -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: diff --git a/src/bdew_datetimes/periods.py b/src/bdew_datetimes/periods.py index cdcc351..94013b8 100644 --- a/src/bdew_datetimes/periods.py +++ b/src/bdew_datetimes/periods.py @@ -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 diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 9b7d8c4..4f55d1c 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -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 @@ -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 @@ -33,7 +33,9 @@ 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 @@ -41,7 +43,7 @@ def test_create_bdew_calendar(test_date: date, expected_is_in_calendar: bool): 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 @@ -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 diff --git a/tests/test_german_strom_and_gas_tag.py b/tests/test_german_strom_and_gas_tag.py index 18af61c..375297c 100644 --- a/tests/test_german_strom_and_gas_tag.py +++ b/tests/test_german_strom_and_gas_tag.py @@ -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, @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/tests/test_period.py b/tests/test_period.py index c8ce385..bae512a 100644 --- a/tests/test_period.py +++ b/tests/test_period.py @@ -1,6 +1,6 @@ from datetime import date -import pytest # type:ignore[import] +import pytest from bdew_datetimes.periods import ( DayType, @@ -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 ) @@ -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 ) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tox.ini b/tox.ini index 1402759..08c6e35 100644 --- a/tox.ini +++ b/tox.ini @@ -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