From 953201e771224cae4e781584622221774db92530 Mon Sep 17 00:00:00 2001 From: MTR Date: Wed, 24 Jul 2024 17:52:52 +0500 Subject: [PATCH 1/8] fixed two problems --- src/icalendar/prop.py | 2 +- src/icalendar/tests/prop/test_vBinary.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index 509179ec..362e8b74 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -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): diff --git a/src/icalendar/tests/prop/test_vBinary.py b/src/icalendar/tests/prop/test_vBinary.py index 7fde7579..f4cb0958 100644 --- a/src/icalendar/tests/prop/test_vBinary.py +++ b/src/icalendar/tests/prop/test_vBinary.py @@ -1,4 +1,6 @@ """Test vBinary""" +import pytest + from icalendar import vBinary from icalendar.parser import Parameters @@ -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("áèਮ") \ No newline at end of file From 446a74c9a7cb69ecdd15e37efa7bfcc92ad5bd1f Mon Sep 17 00:00:00 2001 From: MTR Date: Thu, 25 Jul 2024 16:28:31 +0500 Subject: [PATCH 2/8] tested --- src/icalendar/tests/prop/test_unit.py | 3 +++ src/icalendar/tests/prop/test_vCalAddress.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/icalendar/tests/prop/test_unit.py b/src/icalendar/tests/prop/test_unit.py index 57a6ed62..527f6335 100644 --- a/src/icalendar/tests/prop/test_unit.py +++ b/src/icalendar/tests/prop/test_unit.py @@ -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 diff --git a/src/icalendar/tests/prop/test_vCalAddress.py b/src/icalendar/tests/prop/test_vCalAddress.py index 6a8ff803..62ea0e9f 100644 --- a/src/icalendar/tests/prop/test_vCalAddress.py +++ b/src/icalendar/tests/prop/test_vCalAddress.py @@ -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'')" \ No newline at end of file From 63c66dd99c8d0a5b8ac4ddb7cc43094878942b01 Mon Sep 17 00:00:00 2001 From: MTR Date: Thu, 25 Jul 2024 16:53:41 +0500 Subject: [PATCH 3/8] Tested --- src/icalendar/tests/prop/test_unit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/icalendar/tests/prop/test_unit.py b/src/icalendar/tests/prop/test_unit.py index 527f6335..9240036e 100644 --- a/src/icalendar/tests/prop/test_unit.py +++ b/src/icalendar/tests/prop/test_unit.py @@ -113,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 From 3b04a5661cca3f2851c6096cae69815045ddd48a Mon Sep 17 00:00:00 2001 From: MTR Date: Thu, 25 Jul 2024 17:36:53 +0500 Subject: [PATCH 4/8] Changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 6572279e..af38f2db 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,7 @@ Changelog Minor changes: - add ``__all__`` variable to each modules in ``icalendar`` package +- Improve test coverage. Breaking changes: @@ -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) -------------------- From 66f897c181309dada16520fce16f21742710d992 Mon Sep 17 00:00:00 2001 From: MTR Date: Thu, 25 Jul 2024 19:14:50 +0500 Subject: [PATCH 5/8] All fixed --- src/icalendar/tests/prop/test_vBinary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/tests/prop/test_vBinary.py b/src/icalendar/tests/prop/test_vBinary.py index f4cb0958..429c6e84 100644 --- a/src/icalendar/tests/prop/test_vBinary.py +++ b/src/icalendar/tests/prop/test_vBinary.py @@ -32,7 +32,7 @@ def test_long_data(): def test_repr(): instance = vBinary("value") - assert repr(instance) == "vBinary('b'dmFsdWU='')" + assert repr(instance) == "vBinary('b'value'')" def test_from_ical(): with pytest.raises(ValueError, match='Not valid base 64 encoding.'): From 9eaf95c585bf81b0096c5927d39d475aab0cf9c5 Mon Sep 17 00:00:00 2001 From: MTR Date: Thu, 25 Jul 2024 20:24:26 +0500 Subject: [PATCH 6/8] fixed --- src/icalendar/tests/prop/test_vBinary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/tests/prop/test_vBinary.py b/src/icalendar/tests/prop/test_vBinary.py index 429c6e84..8566d7b5 100644 --- a/src/icalendar/tests/prop/test_vBinary.py +++ b/src/icalendar/tests/prop/test_vBinary.py @@ -32,7 +32,7 @@ def test_long_data(): def test_repr(): instance = vBinary("value") - 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.'): From 8b13fc5e96f3d9cae41abfaf3ce62dd0d683666c Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Thu, 25 Jul 2024 18:50:19 +0100 Subject: [PATCH 7/8] Update src/icalendar/tests/prop/test_vCalAddress.py --- src/icalendar/tests/prop/test_vCalAddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/tests/prop/test_vCalAddress.py b/src/icalendar/tests/prop/test_vCalAddress.py index 62ea0e9f..b8e1f789 100644 --- a/src/icalendar/tests/prop/test_vCalAddress.py +++ b/src/icalendar/tests/prop/test_vCalAddress.py @@ -21,4 +21,4 @@ def test_from_ical(): def test_repr(): instance = vCalAddress("value") - assert repr(instance) == "vCalAddress('b'value'')" \ No newline at end of file + assert repr(instance) == "vCalAddress('value')" \ No newline at end of file From 4375aea9f19cff78f5f3fd3cc84bdec150b3a80e Mon Sep 17 00:00:00 2001 From: MTR Date: Fri, 26 Jul 2024 00:37:53 +0500 Subject: [PATCH 8/8] Fixed __repr__ for vBinary and vCalAddress. --- src/icalendar/prop.py | 4 ++-- src/icalendar/tests/prop/test_vBinary.py | 2 +- src/icalendar/tests/prop/test_vCalAddress.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index 362e8b74..e7f58aba 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -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] @@ -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) diff --git a/src/icalendar/tests/prop/test_vBinary.py b/src/icalendar/tests/prop/test_vBinary.py index 8566d7b5..d3a44893 100644 --- a/src/icalendar/tests/prop/test_vBinary.py +++ b/src/icalendar/tests/prop/test_vBinary.py @@ -32,7 +32,7 @@ def test_long_data(): def test_repr(): instance = vBinary("value") - assert repr(instance) == "vBinary(b'value')" + assert repr(instance) == "vBinary(b'dmFsdWU=')" def test_from_ical(): with pytest.raises(ValueError, match='Not valid base 64 encoding.'): diff --git a/src/icalendar/tests/prop/test_vCalAddress.py b/src/icalendar/tests/prop/test_vCalAddress.py index 62ea0e9f..b8e1f789 100644 --- a/src/icalendar/tests/prop/test_vCalAddress.py +++ b/src/icalendar/tests/prop/test_vCalAddress.py @@ -21,4 +21,4 @@ def test_from_ical(): def test_repr(): instance = vCalAddress("value") - assert repr(instance) == "vCalAddress('b'value'')" \ No newline at end of file + assert repr(instance) == "vCalAddress('value')" \ No newline at end of file