mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2025-02-01 12:28:29 +00:00
fix type errors in tests
with mypy --strict
This commit is contained in:
parent
787e9df642
commit
c2c3a7a14d
@ -1,5 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Tuple
|
from typing import Tuple, Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytz import timezone, utc
|
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))
|
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 = CalendarConverter()
|
||||||
converter.loads(ics_test_cal(""))
|
converter.loads(ics_test_cal(""))
|
||||||
evnts = converter.events_to_gcal()
|
evnts = converter.events_to_gcal()
|
||||||
assert evnts == []
|
assert evnts == []
|
||||||
|
|
||||||
|
|
||||||
def test_empty_event():
|
def test_empty_event() -> None:
|
||||||
converter = CalendarConverter()
|
converter = CalendarConverter()
|
||||||
converter.loads(ics_test_event(""))
|
converter.loads(ics_test_event(""))
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
converter.events_to_gcal()
|
converter.events_to_gcal()
|
||||||
|
|
||||||
|
|
||||||
def test_event_no_end():
|
def test_event_no_end() -> None:
|
||||||
converter = CalendarConverter()
|
converter = CalendarConverter()
|
||||||
converter.loads(ics_test_event(only_start_date))
|
converter.loads(ics_test_event(only_start_date))
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
@ -102,11 +102,11 @@ def test_event_no_end():
|
|||||||
"datetime utc duration",
|
"datetime utc duration",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def param_events_start_end(request):
|
def param_events_start_end(request: Any) -> Any:
|
||||||
return request.param
|
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
|
(date_type, ics_str, start, end) = param_events_start_end
|
||||||
converter = CalendarConverter()
|
converter = CalendarConverter()
|
||||||
converter.loads(ics_str)
|
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}
|
assert event["end"] == {date_type: end}
|
||||||
|
|
||||||
|
|
||||||
def test_event_created_updated():
|
def test_event_created_updated() -> None:
|
||||||
converter = CalendarConverter()
|
converter = CalendarConverter()
|
||||||
converter.loads(ics_test_event(created_updated))
|
converter.loads(ics_test_event(created_updated))
|
||||||
events = converter.events_to_gcal()
|
events = converter.events_to_gcal()
|
||||||
@ -142,5 +142,5 @@ def test_event_created_updated():
|
|||||||
],
|
],
|
||||||
ids=["utc", "with timezone", "date"],
|
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
|
assert format_datetime_utc(value) == expected_str
|
||||||
|
@ -64,8 +64,8 @@ def gen_events(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def gen_list_to_compare(start: int, stop: int) -> List[Dict[str, str]]:
|
def gen_list_to_compare(start: int, stop: int) -> EventList:
|
||||||
result: List[Dict[str, str]] = []
|
result: EventList = []
|
||||||
for i in range(start, stop):
|
for i in range(start, stop):
|
||||||
result.append({"iCalUID": "test{:06d}".format(i)})
|
result.append({"iCalUID": "test{:06d}".format(i)})
|
||||||
return result
|
return result
|
||||||
@ -88,8 +88,8 @@ def get_start_date(event: EventData) -> DateDateTime:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def test_compare():
|
def test_compare() -> None:
|
||||||
part_len = 20
|
part_len: int = 20
|
||||||
# [1..2n]
|
# [1..2n]
|
||||||
lst_src = gen_list_to_compare(1, 1 + part_len * 2)
|
lst_src = gen_list_to_compare(1, 1 + part_len * 2)
|
||||||
# [n..3n]
|
# [n..3n]
|
||||||
@ -117,7 +117,7 @@ def test_compare():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("no_time", [True, False], ids=["date", "dateTime"])
|
@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")
|
msk = timezone("Europe/Moscow")
|
||||||
now = utc.localize(datetime.datetime.utcnow())
|
now = utc.localize(datetime.datetime.utcnow())
|
||||||
msk_now = msk.normalize(now.astimezone(msk))
|
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
|
assert get_start_date(event) < date_cmp
|
||||||
|
|
||||||
|
|
||||||
def test_filter_events_to_update():
|
def test_filter_events_to_update() -> None:
|
||||||
msk = timezone("Europe/Moscow")
|
msk = timezone("Europe/Moscow")
|
||||||
now = utc.localize(datetime.datetime.utcnow())
|
now = utc.localize(datetime.datetime.utcnow())
|
||||||
msk_now = msk.normalize(now.astimezone(msk))
|
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_old = gen_events(1, 1 + count, msk_now)
|
||||||
events_new = gen_events(1, 1 + count, date_upd)
|
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.to_update = list(zip(events_new, events_old))
|
||||||
sync1._filter_events_to_update()
|
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.to_update = list(zip(events_old, events_new))
|
||||||
sync2._filter_events_to_update()
|
sync2._filter_events_to_update()
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ def test_filter_events_to_update():
|
|||||||
assert sync2.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
|
test filtering events that not have 'updated' field
|
||||||
such events should always pass the filter
|
such events should always pass the filter
|
||||||
@ -195,7 +195,7 @@ def test_filter_events_no_updated():
|
|||||||
del event["updated"]
|
del event["updated"]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
sync = CalendarSync(None, None)
|
sync = CalendarSync(None, None) # type: ignore
|
||||||
sync.to_update = list(zip(events_old, events_new))
|
sync.to_update = list(zip(events_old, events_new))
|
||||||
sync._filter_events_to_update()
|
sync._filter_events_to_update()
|
||||||
assert len(sync.to_update) == count // 2
|
assert len(sync.to_update) == count // 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user