Skip to content

Commit

Permalink
Merge pull request #751 from natashamm/issue_698
Browse files Browse the repository at this point in the history
Improve coverage in 5 spots
  • Loading branch information
niccokunzmann authored Nov 27, 2024
2 parents c59966c + e86e6ff commit c1cfc62
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/icalendar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def _format_attendees(attendees):
:returns str: Formatted list of attendees.
"""
if isinstance(attendees, list):
return '\n'.join(map(lambda s: s.rjust(len(s) + 5), map(_format_name, attendees)))
return _format_name(attendees)
if isinstance(attendees, str):
attendees = [attendees]
return '\n'.join(map(lambda s: s.rjust(len(s) + 5), map(_format_name, attendees)))

def view(event):
"""Make a human readable summary of an iCalendar file.
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def __init__(self, dt):
self.params = Parameters({'value': 'DATE'})
elif isinstance(dt, time):
self.params = Parameters({'value': 'TIME'})
elif isinstance(dt, tuple):
else: # isinstance(dt, tuple)
self.params = Parameters({'value': 'PERIOD'})

tzid = tzid_from_dt(dt) if isinstance(dt, (datetime, time)) else None
Expand Down
2 changes: 0 additions & 2 deletions src/icalendar/tests/test_cli_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
BEGIN:VEVENT
ORGANIZER:organizer@test.test
ATTENDEE:attendee1@example.com
ATTENDEE:attendee2@test.test
SUMMARY:Test summary
DTSTART;TZID=Europe/Warsaw:20220820T200000
DTEND;TZID=Europe/Warsaw:20220820T203000
Expand Down Expand Up @@ -74,7 +73,6 @@ def local_datetime(dt):
Organizer: organizer <organizer@test.test>
Attendees:
attendee1 <attendee1@example.com>
attendee2 <attendee2@test.test>
Summary : Test summary
Starts : {secondstart}
End : {secondend}
Expand Down
17 changes: 16 additions & 1 deletion src/icalendar/tests/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest

from icalendar.prop import vDDDTypes
from icalendar.prop import vDDDTypes, vPeriod


@pytest.mark.parametrize(
Expand Down Expand Up @@ -95,3 +95,18 @@ def test_tzid_is_part_of_the_period_values(calendars, tzp):
datetime.datetime(2023, 12, 13, 12), "America/Vancouver"
)
assert end == tzp.localize(datetime.datetime(2023, 12, 13, 15), "America/Vancouver")


def test_period_overlaps():
# 30 minute increments
datetime_1 = datetime.datetime(2024, 11, 20, 12, 0) # 12:00
datetime_2 = datetime.datetime(2024, 11, 20, 12, 30) # 12:30
datetime_3 = datetime.datetime(2024, 11, 20, 13, 0) # 13:00

period_1 = vPeriod((datetime_1,datetime_2))
period_2 = vPeriod((datetime_1,datetime_3))
period_3 = vPeriod((datetime_2,datetime_3))

assert period_1.overlaps(period_2)
assert period_3.overlaps(period_2)
assert not period_1.overlaps(period_3)
2 changes: 2 additions & 0 deletions src/icalendar/tests/test_unit_caselessdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def test_CaselessDict(self):
self.assertEqual(ncd["key1"], "val1")
self.assertEqual(ncd["KEY1"], "val1")

assert ncd.has_key("key1")

ncd["KEY3"] = "val3"
self.assertEqual(ncd["key3"], "val3")

Expand Down
5 changes: 4 additions & 1 deletion src/icalendar/tests/test_unit_parser_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from icalendar.parser_tools import data_encode, to_unicode
from icalendar.parser_tools import data_encode, to_unicode, from_unicode


class TestParserTools(unittest.TestCase):
Expand All @@ -14,6 +14,9 @@ def test_parser_tools_to_unicode(self):
self.assertEqual(to_unicode(1), 1)
self.assertEqual(to_unicode(None), None)

def test_parser_tools_from_unicode(self):
self.assertEqual(from_unicode("\u01b5", encoding="ascii"), b"\xc6\xb5")

def test_parser_tools_data_encode(self):
data1 = {
"k1": "v1",
Expand Down

0 comments on commit c1cfc62

Please sign in to comment.