fix type errors in tests

with mypy --strict
This commit is contained in:
Dmitry Belyaev 2022-06-04 18:51:43 +03:00
parent 787e9df642
commit c2c3a7a14d
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 18 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import datetime
from typing import Tuple
from typing import Tuple, Any
import pytest
from pytz import timezone, utc
@ -57,21 +57,21 @@ def ics_test_event(content: str) -> str:
return ics_test_cal("BEGIN:VEVENT\r\n{}END:VEVENT\r\n".format(content))
def test_empty_calendar():
def test_empty_calendar() -> None:
converter = CalendarConverter()
converter.loads(ics_test_cal(""))
evnts = converter.events_to_gcal()
assert evnts == []
def test_empty_event():
def test_empty_event() -> None:
converter = CalendarConverter()
converter.loads(ics_test_event(""))
with pytest.raises(KeyError):
converter.events_to_gcal()
def test_event_no_end():
def test_event_no_end() -> None:
converter = CalendarConverter()
converter.loads(ics_test_event(only_start_date))
with pytest.raises(ValueError):
@ -102,11 +102,11 @@ def test_event_no_end():
"datetime utc duration",
],
)
def param_events_start_end(request):
def param_events_start_end(request: Any) -> Any:
return request.param
def test_event_start_end(param_events_start_end: Tuple[str, str, str, str]):
def test_event_start_end(param_events_start_end: Tuple[str, str, str, str]) -> None:
(date_type, ics_str, start, end) = param_events_start_end
converter = CalendarConverter()
converter.loads(ics_str)
@ -117,7 +117,7 @@ def test_event_start_end(param_events_start_end: Tuple[str, str, str, str]):
assert event["end"] == {date_type: end}
def test_event_created_updated():
def test_event_created_updated() -> None:
converter = CalendarConverter()
converter.loads(ics_test_event(created_updated))
events = converter.events_to_gcal()
@ -142,5 +142,5 @@ def test_event_created_updated():
],
ids=["utc", "with timezone", "date"],
)
def test_format_datetime_utc(value: datetime.datetime, expected_str: str):
def test_format_datetime_utc(value: datetime.datetime, expected_str: str) -> None:
assert format_datetime_utc(value) == expected_str

View File

@ -64,8 +64,8 @@ def gen_events(
return result
def gen_list_to_compare(start: int, stop: int) -> List[Dict[str, str]]:
result: List[Dict[str, str]] = []
def gen_list_to_compare(start: int, stop: int) -> EventList:
result: EventList = []
for i in range(start, stop):
result.append({"iCalUID": "test{:06d}".format(i)})
return result
@ -88,8 +88,8 @@ def get_start_date(event: EventData) -> DateDateTime:
return result
def test_compare():
part_len = 20
def test_compare() -> None:
part_len: int = 20
# [1..2n]
lst_src = gen_list_to_compare(1, 1 + part_len * 2)
# [n..3n]
@ -117,7 +117,7 @@ def test_compare():
@pytest.mark.parametrize("no_time", [True, False], ids=["date", "dateTime"])
def test_filter_events_by_date(no_time: bool):
def test_filter_events_by_date(no_time: bool) -> None:
msk = timezone("Europe/Moscow")
now = utc.localize(datetime.datetime.utcnow())
msk_now = msk.normalize(now.astimezone(msk))
@ -150,7 +150,7 @@ def test_filter_events_by_date(no_time: bool):
assert get_start_date(event) < date_cmp
def test_filter_events_to_update():
def test_filter_events_to_update() -> None:
msk = timezone("Europe/Moscow")
now = utc.localize(datetime.datetime.utcnow())
msk_now = msk.normalize(now.astimezone(msk))
@ -162,11 +162,11 @@ def test_filter_events_to_update():
events_old = gen_events(1, 1 + count, msk_now)
events_new = gen_events(1, 1 + count, date_upd)
sync1 = CalendarSync(None, None)
sync1 = CalendarSync(None, None) # type: ignore
sync1.to_update = list(zip(events_new, events_old))
sync1._filter_events_to_update()
sync2 = CalendarSync(None, None)
sync2 = CalendarSync(None, None) # type: ignore
sync2.to_update = list(zip(events_old, events_new))
sync2._filter_events_to_update()
@ -174,7 +174,7 @@ def test_filter_events_to_update():
assert sync2.to_update == []
def test_filter_events_no_updated():
def test_filter_events_no_updated() -> None:
"""
test filtering events that not have 'updated' field
such events should always pass the filter
@ -195,7 +195,7 @@ def test_filter_events_no_updated():
del event["updated"]
i += 1
sync = CalendarSync(None, None)
sync = CalendarSync(None, None) # type: ignore
sync.to_update = list(zip(events_old, events_new))
sync._filter_events_to_update()
assert len(sync.to_update) == count // 2