Skip to content

Commit

Permalink
add test case for unit prop
Browse files Browse the repository at this point in the history
  • Loading branch information
raffifu committed Jun 12, 2024
1 parent 3a54fe7 commit d3e432d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Minor changes:
- Update windows to olson conversion for Greenland Standard Time
- Extend examples in Usage with alarm and recurrence
- Document how to serve the built documentation to view with the browser
- Improve test coverage

Breaking changes:

Expand Down
28 changes: 28 additions & 0 deletions src/icalendar/tests/test_unit_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def test_prop_vBoolean(self):
self.assertEqual(vBoolean.from_ical(vBoolean(True).to_ical()), True)
self.assertEqual(vBoolean.from_ical('true'), True)

# Error: key not exists
self.assertRaises(ValueError, vBoolean.from_ical, 'ture')

def test_prop_vCalAddress(self):
from ..prop import vCalAddress
txt = b'MAILTO:[email protected]'
Expand All @@ -65,6 +68,7 @@ def test_prop_vFloat(self):
self.assertEqual(vFloat(1.0).to_ical(), b'1.0')
self.assertEqual(vFloat.from_ical('42'), 42.0)
self.assertEqual(vFloat(42).to_ical(), b'42.0')
self.assertRaises(ValueError, vFloat.from_ical, '1s3')

def test_prop_vInt(self):
from ..prop import vInt
Expand Down Expand Up @@ -107,10 +111,16 @@ def test_prop_vDDDTypes(self):

self.assertTrue(isinstance(vDDDTypes.from_ical('20010101'), date))

self.assertEqual(vDDDTypes.from_ical('123000'), time(12, 30))
self.assertIsInstance(vDDDTypes.from_ical('123000'), time)

self.assertEqual(vDDDTypes.from_ical('P31D'), timedelta(31))

self.assertEqual(vDDDTypes.from_ical('-P31D'), timedelta(-31))

invalid_period = (datetime(2000, 1, 1), datetime(2000, 1, 2), datetime(2000, 1, 2))
self.assertRaises(ValueError, vDDDTypes(invalid_period).to_ical)

# Bad input
self.assertRaises(ValueError, vDDDTypes, 42)

Expand All @@ -123,6 +133,7 @@ def test_prop_vDate(self):
self.assertEqual(vDate.from_ical('20010102'), date(2001, 1, 2))

self.assertRaises(ValueError, vDate, 'd')
self.assertRaises(ValueError, vDate.from_ical, '200102')

def test_prop_vDatetime(self):
from ..prop import vDatetime
Expand Down Expand Up @@ -205,6 +216,17 @@ def test_prop_vPeriod(self):
self.assertEqual(vPeriod(per).to_ical(),
b'20000101T000000/20000102T000000')

# Error: one of the params is not instance of date/datetime
per = ('20000101T000000', datetime(2000, 1, 2))
self.assertRaises(ValueError, vPeriod, per)

per = (datetime(2000, 1, 1), '20000102T000000')
self.assertRaises(ValueError, vPeriod, per)

# Error: first params > second params
per = (datetime(2000, 1, 2), datetime(2000, 1, 1))
self.assertRaises(ValueError, vPeriod, per)

per = (datetime(2000, 1, 1), timedelta(days=31))
self.assertEqual(vPeriod(per).to_ical(), b'20000101T000000/P31D')

Expand Down Expand Up @@ -397,6 +419,8 @@ def test_prop_vTime(self):
# We should also fail, right?
self.assertRaises(ValueError, vTime.from_ical, '263000')

self.assertRaises(ValueError, vTime, '263000')

def test_prop_vUri(self):
from ..prop import vUri

Expand All @@ -420,6 +444,7 @@ def test_prop_vGeo(self):
self.assertEqual(vGeo(g).to_ical(), '37.386013;-122.082932')

self.assertRaises(ValueError, vGeo, 'g')
self.assertRaises(ValueError, vGeo.from_ical, '1s3;1s3')

def test_prop_vUTCOffset(self):
from ..prop import vUTCOffset
Expand Down Expand Up @@ -461,10 +486,13 @@ def test_prop_vUTCOffset(self):

self.assertRaises(ValueError, vUTCOffset.from_ical, '+2400')

self.assertRaises(ValueError, vUTCOffset, '0:00:00')

def test_prop_vInline(self):
from ..prop import vInline

self.assertEqual(vInline('Some text'), 'Some text')
self.assertEqual(vInline('Some text').to_ical(), b'Some text')
self.assertEqual(vInline.from_ical('Some text'), 'Some text')

t2 = vInline('other text')
Expand Down

0 comments on commit d3e432d

Please sign in to comment.