Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code readability #149

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions icalevents/icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def create_event(component, strict):
event.last_modified = event.created

# sequence can be 0 - test for None instead
if not component.get("sequence") is None:
if component.get("sequence") is not None:
event.sequence = component.get("sequence")

if component.get("categories"):
Expand Down Expand Up @@ -360,7 +360,7 @@ def is_not_exception(date):
e = create_event(component, strict)

# make rule.between happy and provide from, to points in time that have the same format as dtstart
if type(e.start) is date and e.recurring == False:
if type(e.start) is date and not e.recurring:
f, t = date(start.year, start.month, start.day), date(
end.year, end.month, end.day
)
Expand Down
74 changes: 34 additions & 40 deletions test/test_icalevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_events_rrule_until_all_day_ms(self):
self.assertEqual(
ev_0.start, datetime(2021, 3, 19, 00, 0, 0, tzinfo=gettz("Europe/Berlin"))
)
self.assertEqual(ev_0.recurring, True, "Recurring all day event")
self.assertTrue(ev_0.recurring, "Recurring all day event")
self.assertEqual(ev_0.summary, "Away")

def test_events_rrule_until_all_day_google(self):
Expand All @@ -155,7 +155,7 @@ def test_events_rrule_until_all_day_google(self):
self.assertEqual(
ev.start, datetime(2021, 3, 24, 00, 0, 0, tzinfo=gettz("Europe/Zurich"))
)
self.assertEqual(ev.all_day, True, "All day event")
self.assertTrue(ev.all_day, "All day event")
self.assertEqual(ev.summary, "Busy")

def test_events_rrule_until_only_date(self):
Expand All @@ -181,9 +181,9 @@ def test_events_rrule_until(self):
evs = icalevents.events(file=ical, start=start, end=end)

self.assertEqual(len(evs), 2)
self.assertEqual(evs[0].recurring, True)
self.assertTrue(evs[0].recurring)
self.assertEqual(evs[0].summary, "Recurring All-day Event")
self.assertEqual(evs[1].recurring, True)
self.assertTrue(evs[1].recurring)
self.assertEqual(evs[1].summary, "Daily lunch event")

def test_event_attributes(self):
Expand All @@ -203,9 +203,7 @@ def test_event_recurring_attribute(self):
end = date(2017, 7, 13)

ev = icalevents.events(url=None, file=ical, start=start, end=end)[0]
self.assertEqual(
ev.recurring, False, "check recurring=False for non recurring event"
)
self.assertFalse(ev.recurring, "check recurring=False for non recurring event")

ical = "test/test_data/recurring.ics"
start = date(2018, 10, 15)
Expand All @@ -215,12 +213,8 @@ def test_event_recurring_attribute(self):

e1 = evs[1]
e2 = evs[2]
self.assertEqual(
e1.recurring, True, "check recurring=True for recurring event (1)"
)
self.assertEqual(
e2.recurring, True, "check recurring=True for recurring event (2)"
)
self.assertTrue(e1.recurring, "check recurring=True for recurring event (1)")
self.assertTrue(e2.recurring, "check recurring=True for recurring event (2)")

def test_events_async_url(self):
url = "https://raw.githubusercontent.com/jazzband/icalevents/master/test/test_data/basic.ics"
Expand Down Expand Up @@ -297,9 +291,9 @@ def test_events_no_description(self):

e1 = icalevents.events(file=ical, start=start, end=end)[0]

self.assertEqual(e1.description, None)
self.assertEqual(e1.summary, None)
self.assertEqual(e1.location, None)
self.assertIsNone(e1.description)
self.assertIsNone(e1.summary)
self.assertIsNone(e1.location)

def test_event_created_last_modified(self):
ical = "test/test_data/created_last_modified.ics"
Expand All @@ -318,8 +312,8 @@ def test_event_created_last_modified(self):
events[1].last_modified, datetime(2017, 1, 4, 8, 4, 1, tzinfo=UTC)
)

self.assertEqual(events[2].created, None)
self.assertEqual(events[2].last_modified, None)
self.assertIsNone(events[2].created)
self.assertIsNone(events[2].last_modified)

def test_event_categories(self):
ical = "test/test_data/categories_test.ics"
Expand Down Expand Up @@ -568,8 +562,8 @@ def test_transparent(self):

[e1, e2] = icalevents.events(file=ical, start=start, end=end)

self.assertEqual(e1.transparent, True, "respect transparency")
self.assertEqual(e2.transparent, False, "respect opaqueness")
self.assertTrue(e1.transparent, "respect transparency")
self.assertFalse(e2.transparent, "respect opaqueness")

def test_status_and_url(self):
ical = "test/test_data/status_and_url.ics"
Expand All @@ -578,12 +572,12 @@ def test_status_and_url(self):

[ev1, ev2, ev3, ev4, ev5] = icalevents.events(file=ical, start=start, end=end)
self.assertEqual(ev1.status, "TENTATIVE")
self.assertEqual(ev1.url, None)
self.assertIsNone(ev1.url)
self.assertEqual(ev2.status, "CONFIRMED")
self.assertEqual(ev2.url, "https://example.com/")
self.assertEqual(ev3.status, "CANCELLED")
self.assertEqual(ev4.status, "CANCELLED")
self.assertEqual(ev5.status, None)
self.assertIsNone(ev5.status)

def test_recurrence_tz(self):
ical = "test/test_data/recurrence_tz.ics"
Expand Down Expand Up @@ -632,16 +626,16 @@ def test_floating(self):

[e1, e2] = icalevents.events(file=ical, start=start, end=end)

self.assertEqual(e1.transparent, False, "respect transparency")
self.assertFalse(e1.transparent, "respect transparency")
self.assertEqual(e1.start.hour, 6, "check start of the day")
self.assertEqual(e1.end.hour, 14, "check end of the day")
self.assertEqual(e1.floating, False, "respect floating time")
self.assertFalse(e1.floating, "respect floating time")
self.assertEqual(e1.start.tzinfo, UTC, "check tz as default utc")

self.assertEqual(e2.transparent, True, "respect transparency")
self.assertTrue(e2.transparent, "respect transparency")
self.assertEqual(e2.start.hour, 0, "check start of the day")
self.assertEqual(e2.end.hour, 0, "check end of the day")
self.assertEqual(e2.floating, True, "respect floating time")
self.assertTrue(e2.floating, "respect floating time")
self.assertEqual(e2.start.tzinfo, UTC, "check tz as default utc")

def test_floating_strict(self):
Expand All @@ -651,18 +645,18 @@ def test_floating_strict(self):

[e1, e2] = icalevents.events(file=ical, start=start, end=end, strict=True)

self.assertEqual(e1.transparent, False, "respect transparency")
self.assertFalse(e1.transparent, "respect transparency")
self.assertEqual(
e1.start.astimezone(pytz.utc).hour, 6, "check start of the day"
)
self.assertEqual(e1.end.astimezone(pytz.utc).hour, 14, "check end of the day")
self.assertEqual(e1.floating, False, "respect floating time")
self.assertFalse(e1.floating, "respect floating time")
self.assertEqual(e1.start.tzname(), "CEST", "check tz as specified in calendar")

self.assertEqual(e2.transparent, True, "respect transparency")
self.assertTrue(e2.transparent, "respect transparency")
self.assertEqual(e2.start, date(2021, 10, 13), "check start of the day")
self.assertEqual(e2.end, date(2021, 10, 14), "check end of the day")
self.assertEqual(e2.floating, False, "dates are not floating floating time")
self.assertFalse(e2.floating, "dates are not floating floating time")

def test_non_floating(self):
ical = "test/test_data/non_floating.ics"
Expand All @@ -671,18 +665,18 @@ def test_non_floating(self):

[e1, e2] = icalevents.events(file=ical, start=start, end=end)

self.assertEqual(e1.transparent, False, "respect transparency")
self.assertFalse(e1.transparent, "respect transparency")
self.assertEqual(e1.start.hour, 8, "check start of the day")
self.assertEqual(e1.end.hour, 16, "check end of the day")
self.assertEqual(e1.floating, False, "respect floating time")
self.assertFalse(e1.floating, "respect floating time")
self.assertEqual(
e1.start.tzinfo, gettz("Europe/Zurich"), "check tz as specified in calendar"
)

self.assertEqual(e2.transparent, True, "respect transparency")
self.assertTrue(e2.transparent, "respect transparency")
self.assertEqual(e2.start.hour, 0, "check start of the day")
self.assertEqual(e2.end.hour, 0, "check end of the day")
self.assertEqual(e2.floating, True, "respect floating time")
self.assertTrue(e2.floating, "respect floating time")
self.assertEqual(
e2.start.tzinfo, gettz("Europe/Zurich"), "check tz as specified in calendar"
)
Expand All @@ -694,15 +688,15 @@ def test_non_floating_strict(self):

[e1, e2] = icalevents.events(file=ical, start=start, end=end, strict=True)

self.assertEqual(e1.transparent, False, "respect transparency")
self.assertFalse(e1.transparent, "respect transparency")
self.assertEqual(e1.start.hour, 8, "check start of the day")
self.assertEqual(e1.end.hour, 16, "check end of the day")
self.assertEqual(e1.floating, False, "respect floating time")
self.assertFalse(e1.floating, "respect floating time")
self.assertEqual(e1.start.tzname(), "CEST", "check tz as specified in calendar")

self.assertEqual(e2.transparent, True, "respect transparency")
self.assertEqual(e2.floating, False, "respect floating time")
self.assertEqual(e2.all_day, True, "it is an all day event")
self.assertTrue(e2.transparent, "respect transparency")
self.assertFalse(e2.floating, "respect floating time")
self.assertTrue(e2.all_day, "it is an all day event")
self.assertEqual(e2.start, date(2021, 10, 13), "it is an all day event")
self.assertEqual(e2.end, date(2021, 10, 14), "it is an all day event")

Expand Down Expand Up @@ -846,7 +840,7 @@ def test_google_2024(self):

self.assertEqual(e1.start.astimezone(pytz.utc).hour, 6, "starts at 6 utc")
self.assertEqual(e1.end.astimezone(pytz.utc).hour, 7, "ends at 7 utc")
self.assertEqual(e1.floating, False, "respect floating time")
self.assertFalse(e1.floating, "respect floating time")
self.assertEqual(e1.start.tzname(), "CET", "check tz as specified in calendar")

self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions test/test_icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def setUp(self):
def test_now(self):
n = icalevents.icalparser.now()

self.assertTrue(type(n) == datetime, "result of now has type datetime")
self.assertEqual(type(n), datetime, "result of now has type datetime")
self.assertTrue(n.tzinfo, "result of now has a timezone info")

def test_time_left(self):
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_event_copy_to(self):
self.assertEqual(eventD.description, eventC.description, "copy to: description")

def test_event_order(self):
self.assertTrue(self.eventA > self.eventB, "order of events")
self.assertGreater(self.eventA, self.eventB, "order of events")

def test_attendee(self):
self.assertIsInstance(self.eventA.attendee, str)
Expand Down
Loading