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

Improved test coverage in 5 places for production code #696

Merged
merged 10 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
Minor changes:

- add ``__all__`` variable to each modules in ``icalendar`` package
- Improve test coverage.

Breaking changes:

Expand All @@ -20,6 +21,7 @@ Bug fixes:

- Fix link to stable release of tox in documentation.
- Fix a bad bytes replace in unescape_char.
- Handle ``ValueError`` in ``vBinary.from_ical``.

6.0.0a0 (2024-07-03)
--------------------
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def to_ical(self):
def from_ical(ical):
try:
return base64.b64decode(ical)
except UnicodeError:
except (ValueError, UnicodeError):
raise ValueError('Not valid base 64 encoding.')

def __eq__(self, other):
Expand Down
4 changes: 4 additions & 0 deletions src/icalendar/tests/prop/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def test_prop_vDDDLists(self):

dt_list = vDDDLists([datetime(2000, 1, 1), datetime(2000, 11, 11)])
self.assertEqual(dt_list.to_ical(), b'20000101T000000,20001111T000000')

instance = vDDDLists([])
self.assertFalse(instance == "value")

def test_prop_vDate(self):
from icalendar.prop import vDate
Expand Down Expand Up @@ -110,6 +113,7 @@ def test_prop_vFrequency(self):
self.assertRaises(ValueError, vFrequency, 'bad test')
self.assertEqual(vFrequency('daily').to_ical(), b'DAILY')
self.assertEqual(vFrequency('daily').from_ical('MONTHLY'), 'MONTHLY')
self.assertRaises(ValueError, vFrequency.from_ical, 234)

def test_prop_vRecur(self):
from icalendar.prop import vRecur
Expand Down
12 changes: 12 additions & 0 deletions src/icalendar/tests/prop/test_vBinary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Test vBinary"""
import pytest

from icalendar import vBinary
from icalendar.parser import Parameters

Expand Down Expand Up @@ -27,3 +29,13 @@ def test_long_data():
txt_ical = b'YWFh' * 33
assert (vBinary(txt).to_ical() == txt_ical)
assert (vBinary.from_ical(txt_ical) == txt)

def test_repr():
instance = vBinary("value")
assert repr(instance) == "vBinary('b'value'')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert repr(instance) == "vBinary('b'value'')"
assert repr(instance) == "vBinary(b'value')"


def test_from_ical():
with pytest.raises(ValueError, match='Not valid base 64 encoding.'):
vBinary.from_ical("value")
with pytest.raises(ValueError, match='Not valid base 64 encoding.'):
vBinary.from_ical("áèਮ")
5 changes: 5 additions & 0 deletions src/icalendar/tests/prop/test_vCalAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def test_params():

def test_from_ical():
assert vCalAddress.from_ical(txt) == 'MAILTO:maxm@mxm.dk'


def test_repr():
instance = vCalAddress("value")
assert repr(instance) == "vCalAddress('b'value'')"
niccokunzmann marked this conversation as resolved.
Show resolved Hide resolved