From baf28872e35724521e9a2972319fde0d5dd49c7c Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 15:59:44 +0200 Subject: [PATCH 01/10] update event.py and test_event.py Initial commit --- gcsa/event.py | 12 ++++++++++++ tests/test_event.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/gcsa/event.py b/gcsa/event.py index b6c547b..ca2382f 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -1,4 +1,5 @@ from functools import total_ordering +import logging from typing import List, Union from beautiful_date import BeautifulDate @@ -13,6 +14,7 @@ from .reminders import PopupReminder, EmailReminder, Reminder from .util.date_time_util import ensure_localisation +log = logging.getLogger(__name__) class Visibility: """Possible values of the event visibility. @@ -159,6 +161,11 @@ def ensure_list(obj): if isinstance(self.start, datetime) and isinstance(self.end, datetime): self.start = ensure_localisation(self.start, timezone) self.end = ensure_localisation(self.end, timezone) + + if self.start.microsecond != 0 or self.end.microsecond: + log.warn( + "Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." + ) elif isinstance(self.start, datetime) or isinstance(self.end, datetime): raise TypeError('Start and end must either both be date or both be datetime.') @@ -186,6 +193,11 @@ def ensure_date(d): self.event_id = event_id self.summary = summary + if self.summary == "": + log.warning( + f"Summary is empty in {self}. Note that if the event is loaded from Google Calendar, its summary will be `None`" + ) + self.description = description self.location = location self.recurrence = ensure_list(recurrence) diff --git a/tests/test_event.py b/tests/test_event.py index 786e464..13aacd1 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -1,4 +1,5 @@ from datetime import time +import datetime from unittest import TestCase from beautiful_date import Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Dec, hours, days, Nov @@ -67,6 +68,36 @@ def test_init_no_end(self): event = Event('Lunch', start, timezone=TEST_TIMEZONE) self.assertEqual(event.end, start + 1 * hours) + def test_init_with_microseconds(self): + with self.assertLogs("gcsa.event", level="WARNING") as cm: + Event( + "Test", + start=datetime.datetime( + year=1979, month=1, day=1, hour=1, minute=1, second=1, microsecond=1 + ), + ) + self.assertEqual( + cm.output, + [ + "WARNING:gcsa.event:Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." + ], + ) + + def test_init_without_title(self): + with self.assertLogs("gcsa.event", level="WARNING") as cm: + Event( + "", + start=datetime.datetime( + year=1979, month=1, day=1, hour=1, minute=1, second=1, microsecond=0 + ), + ) + self.assertEqual( + cm.output, + [ + "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+01:00 - . Note that if the event is loaded from Google Calendar, its summary will be `None`" + ], + ) + def test_init_no_start_or_end(self): event = Event('Good day', start=None, timezone=TEST_TIMEZONE) self.assertIsNone(event.start) From b468b3f09d95fb6b984da2395314747f486f5e9e Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 16:00:09 +0200 Subject: [PATCH 02/10] update event.py --- gcsa/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcsa/event.py b/gcsa/event.py index ca2382f..ef566dd 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -163,7 +163,7 @@ def ensure_list(obj): self.end = ensure_localisation(self.end, timezone) if self.start.microsecond != 0 or self.end.microsecond: - log.warn( + log.warning( "Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." ) elif isinstance(self.start, datetime) or isinstance(self.end, datetime): From a47ff3fd10cdddd51225f303b194e9a69b453f19 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 16:01:22 +0200 Subject: [PATCH 03/10] update event.py --- gcsa/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcsa/event.py b/gcsa/event.py index ef566dd..dbd8d67 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -46,7 +46,7 @@ class Transparency: class Event(Resource): def __init__( self, - summary: str, + summary: str | None, start: Union[date, datetime, BeautifulDate], end: Union[date, datetime, BeautifulDate] = None, *, From 37f7bb5595fd61ab5d0bfe0d4844ff79ab901455 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 17:26:08 +0200 Subject: [PATCH 04/10] update .gitignore and event.py update event.py --- .gitignore | 3 ++- gcsa/event.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fd8db29..fe8872b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ example.py coverage.xml .coverage .DS_Store -.tox \ No newline at end of file +.tox +.vscode \ No newline at end of file diff --git a/gcsa/event.py b/gcsa/event.py index dbd8d67..1fbd6b4 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -1,6 +1,6 @@ from functools import total_ordering import logging -from typing import List, Union +from typing import List, Optional, Union from beautiful_date import BeautifulDate from tzlocal import get_localzone_name @@ -46,7 +46,7 @@ class Transparency: class Event(Resource): def __init__( self, - summary: str | None, + summary: Optional[str] | None, start: Union[date, datetime, BeautifulDate], end: Union[date, datetime, BeautifulDate] = None, *, @@ -162,7 +162,7 @@ def ensure_list(obj): self.start = ensure_localisation(self.start, timezone) self.end = ensure_localisation(self.end, timezone) - if self.start.microsecond != 0 or self.end.microsecond: + if self.start.microsecond != 0 or self.end.microsecond != 0: log.warning( "Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." ) From 48ebb85816ad5b91636283b9166886110846942b Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 17:26:34 +0200 Subject: [PATCH 05/10] chore: update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fe8872b..9169049 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ coverage.xml .coverage .DS_Store .tox -.vscode \ No newline at end of file +.vscode From e8f7f5f16692bfb72b0403474b5fa82629232567 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 17:26:54 +0200 Subject: [PATCH 06/10] update event.py --- gcsa/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcsa/event.py b/gcsa/event.py index 1fbd6b4..5f88539 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -46,7 +46,7 @@ class Transparency: class Event(Resource): def __init__( self, - summary: Optional[str] | None, + summary: Optional[str], start: Union[date, datetime, BeautifulDate], end: Union[date, datetime, BeautifulDate] = None, *, From c27431d4befa31a623d51c8ccc52ceb119410566 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 17:43:18 +0200 Subject: [PATCH 07/10] test: update test_event.py --- tests/test_event.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_event.py b/tests/test_event.py index 13aacd1..96af56d 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -59,7 +59,7 @@ def test_init(self): self.assertTrue(event.guests_can_modify) self.assertFalse(event.guests_can_see_other_guests) - def test_init_no_end(self): + def test_init_no_end(self | None): start = 1 / Jun / 2019 event = Event('Good day', start, timezone=TEST_TIMEZONE) self.assertEqual(event.end, start + 1 * days) @@ -90,11 +90,12 @@ def test_init_without_title(self): start=datetime.datetime( year=1979, month=1, day=1, hour=1, minute=1, second=1, microsecond=0 ), + timezone=TEST_TIMEZONE, ) self.assertEqual( cm.output, [ - "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+01:00 - . Note that if the event is loaded from Google Calendar, its summary will be `None`" + "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+12:00 - . Note that if the event is loaded from Google Calendar, its summary will be `None`" ], ) From 3d0f0e10bef2abc7daf4c1c9216d0f748ff22b94 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 17:44:03 +0200 Subject: [PATCH 08/10] test: update test_event.py --- tests/test_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_event.py b/tests/test_event.py index 96af56d..6c36dbe 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -59,7 +59,7 @@ def test_init(self): self.assertTrue(event.guests_can_modify) self.assertFalse(event.guests_can_see_other_guests) - def test_init_no_end(self | None): + def test_init_no_end(self): start = 1 / Jun / 2019 event = Event('Good day', start, timezone=TEST_TIMEZONE) self.assertEqual(event.end, start + 1 * days) From bb47595c7e7b1c4c8872b854c0743f47077b3523 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 18:01:56 +0200 Subject: [PATCH 09/10] update event.py and test_event.py --- gcsa/event.py | 8 ++++++-- tests/test_event.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gcsa/event.py b/gcsa/event.py index 5f88539..283439e 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -16,6 +16,7 @@ log = logging.getLogger(__name__) + class Visibility: """Possible values of the event visibility. @@ -164,7 +165,9 @@ def ensure_list(obj): if self.start.microsecond != 0 or self.end.microsecond != 0: log.warning( - "Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." + "Microseconds are used in start/end," + + "but are not supported in the Google Calendar API" + + "and will be dropped on submission." ) elif isinstance(self.start, datetime) or isinstance(self.end, datetime): raise TypeError('Start and end must either both be date or both be datetime.') @@ -195,7 +198,8 @@ def ensure_date(d): self.summary = summary if self.summary == "": log.warning( - f"Summary is empty in {self}. Note that if the event is loaded from Google Calendar, its summary will be `None`" + f"Summary is empty in {self}. Note that if the event is loaded" + + "from Google Calendar, its summary will be `None`" ) self.description = description diff --git a/tests/test_event.py b/tests/test_event.py index 6c36dbe..fd3a7af 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -79,7 +79,9 @@ def test_init_with_microseconds(self): self.assertEqual( cm.output, [ - "WARNING:gcsa.event:Microseconds are used in start/end, but are not supported in Google Calendar API, and will be dropped on submission." + "WARNING:gcsa.event:Microseconds are used in start/end," + + "but are not supported in Google Calendar API" + + ", and will be dropped on submission." ], ) @@ -95,7 +97,9 @@ def test_init_without_title(self): self.assertEqual( cm.output, [ - "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+12:00 - . Note that if the event is loaded from Google Calendar, its summary will be `None`" + "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+12:00 - ." + "Note that if the event is loaded from Google Calendar," + +" its summary will be `None`" ], ) From 16e2427b89769fedbd94f5d7e95081bb0c5354a0 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 26 May 2024 18:08:16 +0200 Subject: [PATCH 10/10] update event.py and test_event.py --- gcsa/event.py | 8 ++++---- tests/test_event.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gcsa/event.py b/gcsa/event.py index 283439e..36f0d05 100644 --- a/gcsa/event.py +++ b/gcsa/event.py @@ -165,9 +165,9 @@ def ensure_list(obj): if self.start.microsecond != 0 or self.end.microsecond != 0: log.warning( - "Microseconds are used in start/end," - + "but are not supported in the Google Calendar API" - + "and will be dropped on submission." + "Microseconds are used in start/end, " + + "but are not supported in the Google Calendar API " + + "and will be dropped on submission." ) elif isinstance(self.start, datetime) or isinstance(self.end, datetime): raise TypeError('Start and end must either both be date or both be datetime.') @@ -198,7 +198,7 @@ def ensure_date(d): self.summary = summary if self.summary == "": log.warning( - f"Summary is empty in {self}. Note that if the event is loaded" + f"Summary is empty in {self}. Note that if the event is loaded " + "from Google Calendar, its summary will be `None`" ) diff --git a/tests/test_event.py b/tests/test_event.py index fd3a7af..3444b54 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -79,9 +79,9 @@ def test_init_with_microseconds(self): self.assertEqual( cm.output, [ - "WARNING:gcsa.event:Microseconds are used in start/end," + - "but are not supported in Google Calendar API" + - ", and will be dropped on submission." + "WARNING:gcsa.event:Microseconds are used in start/end, " + + "but are not supported in the Google Calendar API " + + "and will be dropped on submission." ], ) @@ -97,9 +97,9 @@ def test_init_without_title(self): self.assertEqual( cm.output, [ - "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+12:00 - ." - "Note that if the event is loaded from Google Calendar," - +" its summary will be `None`" + "WARNING:gcsa.event:Summary is empty in 1979-01-01 01:01:01+12:00 - . " + + "Note that if the event is loaded from Google Calendar, " + + "its summary will be `None`" ], )