From 50b413c8cc4d1be7758b98c4bdbd9e563d791097 Mon Sep 17 00:00:00 2001 From: satoru Date: Sat, 14 Nov 2026 21:52:38 +0900 Subject: [PATCH 1/2] Add tests for uncovered vAdr and vN branches Cover equality and invalid field counts in serialized input. Refs #698. AI disclosure: OpenAI Codex (GPT-6) identified uncovered paths, drafted the tests and news entry, and helped review and check the changes. --- news/698.chore.4 | 1 + .../tests/rfc_6350_vcard/test_vAdr.py | 29 ++++++++++++++ src/icalendar/tests/rfc_6350_vcard/test_vN.py | 38 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 news/698.chore.4 diff --git a/news/698.chore.4 b/news/698.chore.4 new file mode 100644 index 000000000..283c5e9a2 --- /dev/null +++ b/news/698.chore.4 @@ -0,0 +1 @@ +Added tests for equality and invalid field counts in :class:`~icalendar.prop.adr.vAdr` and :class:`~icalendar.prop.n.vN`. Drafted with OpenAI Codex (GPT-6). @Satorino01 diff --git a/src/icalendar/tests/rfc_6350_vcard/test_vAdr.py b/src/icalendar/tests/rfc_6350_vcard/test_vAdr.py index 044f4b396..22db22d96 100644 --- a/src/icalendar/tests/rfc_6350_vcard/test_vAdr.py +++ b/src/icalendar/tests/rfc_6350_vcard/test_vAdr.py @@ -59,6 +59,23 @@ def test_adr_named_field_access(self): assert adr.fields.country == "USA" +class TestVAdrEquality: + """Test vAdr equality.""" + + @pytest.mark.parametrize( + ("other", "expected"), + [ + (vAdr(";;123 Main St;Springfield;IL;62701;USA"), True), + (vAdr(";;456 Main St;Springfield;IL;62701;USA"), False), + (";;123 Main St;Springfield;IL;62701;USA", False), + ], + ) + def test_adr_equality(self, other, expected): + """Only addresses with matching fields compare equal.""" + adr = vAdr(("", "", "123 Main St", "Springfield", "IL", "62701", "USA")) + assert (adr == other) is expected + + class TestVAdrSerialization: """Test vAdr to_ical and from_ical.""" @@ -76,6 +93,18 @@ def test_adr_from_ical(self): "", "", "123 Main St", "Springfield", "IL", "62701", "USA" ) + @pytest.mark.parametrize( + "ical", + [ + ";;123 Main St;Springfield;IL;62701", + ";;123 Main St;Springfield;IL;62701;USA;extra", + ], + ) + def test_adr_from_ical_requires_7_fields(self, ical): + """Reject addresses with too few or too many fields.""" + with pytest.raises(ValueError, match="ADR must have exactly 7 fields"): + vAdr.from_ical(ical) + def test_adr_round_trip(self): """ADR survives round-trip through to_ical and from_ical.""" original = AdrFields("", "", "123 Main St", "Springfield", "IL", "62701", "USA") diff --git a/src/icalendar/tests/rfc_6350_vcard/test_vN.py b/src/icalendar/tests/rfc_6350_vcard/test_vN.py index 03be4c1de..c6f49726d 100644 --- a/src/icalendar/tests/rfc_6350_vcard/test_vN.py +++ b/src/icalendar/tests/rfc_6350_vcard/test_vN.py @@ -4,6 +4,7 @@ import pytest +from icalendar.error import JCalParsingError from icalendar.prop import vN from icalendar.prop.n import NFields @@ -54,8 +55,25 @@ def test_n_named_field_access(self): assert n.fields.suffix == "Jr." +class TestVNEquality: + """Test vN equality.""" + + @pytest.mark.parametrize( + ("other", "expected"), + [ + (vN("Doe;John;M.;Dr.;Jr."), True), + (vN("Roe;John;M.;Dr.;Jr."), False), + ("Doe;John;M.;Dr.;Jr.", False), + ], + ) + def test_n_equality(self, other, expected): + """Only names with matching fields compare equal.""" + n = vN(("Doe", "John", "M.", "Dr.", "Jr.")) + assert (n == other) is expected + + class TestVNSerialization: - """Test vN to_ical and from_ical.""" + """Test vN serialization.""" def test_n_to_ical(self): """N to_ical generates semicolon-separated format.""" @@ -69,6 +87,24 @@ def test_n_from_ical(self): assert isinstance(result, NFields) assert result == NFields("Doe", "John", "M.", "Dr.", "Jr.") + @pytest.mark.parametrize("ical", ["Doe;John;M.;Dr.", "Doe;John;M.;Dr.;Jr.;extra"]) + def test_n_from_ical_requires_5_fields(self, ical): + """Reject names with too few or too many fields.""" + with pytest.raises(ValueError, match="N must have exactly 5 fields"): + vN.from_ical(ical) + + @pytest.mark.parametrize( + "fields", + [ + ["Doe", "John", "M.", "Dr."], + ["Doe", "John", "M.", "Dr.", "Jr.", "extra"], + ], + ) + def test_n_from_jcal_requires_5_fields(self, fields): + """Reject jCal names with too few or too many fields.""" + with pytest.raises(JCalParsingError, match="N must have 8 elements"): + vN.from_jcal(["n", {}, "text", *fields]) + def test_n_round_trip(self): """N survives round-trip through to_ical and from_ical.""" original = NFields("Doe", "John", "Michael", "Dr.", "Jr.") From 8e4e4f30343942f92b5c303360080e55a0fb970c Mon Sep 17 00:00:00 2001 From: satoru Date: Mon, 23 Nov 2026 20:18:45 +0900 Subject: [PATCH 2/2] Fix changelog fragment name and attribution AI disclosure: OpenAI Codex (GPT-6) helped apply the review feedback to the changelog fragment. --- news/{698.chore.4 => 698.chore} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename news/{698.chore.4 => 698.chore} (72%) diff --git a/news/698.chore.4 b/news/698.chore similarity index 72% rename from news/698.chore.4 rename to news/698.chore index 283c5e9a2..14ddfde28 100644 --- a/news/698.chore.4 +++ b/news/698.chore @@ -1 +1 @@ -Added tests for equality and invalid field counts in :class:`~icalendar.prop.adr.vAdr` and :class:`~icalendar.prop.n.vN`. Drafted with OpenAI Codex (GPT-6). @Satorino01 +Added tests for equality and invalid field counts in :class:`~icalendar.prop.adr.vAdr` and :class:`~icalendar.prop.n.vN`. Drafted with OpenAI Codex (GPT-6). :user:`Satorino01`