Skip to content

Commit 9800545

Browse files
committed
Add TagSpec read-name contract tests
1 parent 2058ca0 commit 9800545

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/unit/easydiffraction/io/cif/test_handler.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,47 @@ def test_tags_cif_name_uses_explicit_value():
3333
)
3434

3535
assert handler.cif_name == '_easydiffraction_calculator.type'
36+
37+
38+
def test_explicit_edi_name_overrides_first_and_leads_read_order():
39+
from easydiffraction.io.cif.handler import TagSpec
40+
41+
handler = TagSpec(edi_names=['_a.x', '_a.y'], edi_name='_a.z')
42+
43+
assert handler.edi_name == '_a.z'
44+
assert handler.edi_read_names == ['_a.z', '_a.x', '_a.y']
45+
46+
47+
def test_edi_read_names_remove_duplicates():
48+
from easydiffraction.io.cif.handler import TagSpec
49+
50+
handler = TagSpec(edi_names=['_a.x', '_a.x'])
51+
52+
assert handler.edi_read_names == ['_a.x']
53+
54+
55+
def test_cif_read_names_dedup_and_canonical_first():
56+
from easydiffraction.io.cif.handler import TagSpec
57+
58+
handler = TagSpec(edi_names=['_a.x'], cif_names=['_b.y', '_b.z', '_b.y'])
59+
60+
assert handler.cif_name == '_b.y'
61+
assert handler.cif_read_names == ['_b.y', '_b.z']
62+
63+
64+
def test_cif_names_default_to_edi_names():
65+
from easydiffraction.io.cif.handler import TagSpec
66+
67+
handler = TagSpec(edi_names=['_a.x'])
68+
69+
assert handler.cif_names == ['_a.x']
70+
assert handler.cif_name == '_a.x'
71+
72+
73+
def test_read_names_union_orders_edi_before_cif_and_dedupes():
74+
from easydiffraction.io.cif.handler import TagSpec
75+
76+
handler = TagSpec(edi_names=['_a.x'], cif_names=['_a.x', '_b.y'])
77+
78+
# Edi name first, then CIF-only aliases, with duplicates removed.
79+
assert handler.read_names == ['_a.x', '_b.y']

0 commit comments

Comments
 (0)