Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions news/698.chore
Original file line number Diff line number Diff line change
@@ -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). :user:`Satorino01`
29 changes: 29 additions & 0 deletions src/icalendar/tests/rfc_6350_vcard/test_vAdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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")
Expand Down
38 changes: 37 additions & 1 deletion src/icalendar/tests/rfc_6350_vcard/test_vN.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from icalendar.error import JCalParsingError
from icalendar.prop import vN
from icalendar.prop.n import NFields

Expand Down Expand Up @@ -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."""
Expand All @@ -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.")
Expand Down