Skip to content

Commit

Permalink
Merge pull request #696 from mtr-d3v/fix_issue_629
Browse files Browse the repository at this point in the history
Improved test coverage in 5 places for production code
  • Loading branch information
niccokunzmann committed Jul 25, 2024
2 parents 1b145d6 + ed0cec4 commit 6d94f5b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
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.
- Adapt ``test_with_doctest.py`` to correctly run on Windows.

Breaking changes:
Expand All @@ -21,6 +22,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
6 changes: 3 additions & 3 deletions src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, obj):
self.params = Parameters(encoding='BASE64', value="BINARY")

def __repr__(self):
return f"vBinary('{self.to_ical()}')"
return f"vBinary({self.to_ical()})"

def to_ical(self):
return binascii.b2a_base64(self.obj.encode('utf-8'))[:-1]
Expand All @@ -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 Expand Up @@ -160,7 +160,7 @@ def __new__(cls, value, encoding=DEFAULT_ENCODING):
return self

def __repr__(self):
return f"vCalAddress('{self.to_ical()}')"
return f"vCalAddress('{self}')"

def to_ical(self):
return self.encode(DEFAULT_ENCODING)
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'dmFsdWU=')"

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:[email protected]'


def test_repr():
instance = vCalAddress("value")
assert repr(instance) == "vCalAddress('value')"

0 comments on commit 6d94f5b

Please sign in to comment.