Skip to content

Commit c36fd88

Browse files
committed
add tests for ccd and prd readers
1 parent 99cc7f6 commit c36fd88

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

pdbeccdutils/tests/test_ccd_reader.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,68 @@ def test_read_pdb_components_file_parses_all_for_empty_include(tmp_path):
2626
assert list(result) == ["00O", "007"]
2727

2828

29+
def test_read_pdb_components_file_uses_include_order_and_skips_missing(
30+
tmp_path, caplog
31+
):
32+
path = _components_cif(tmp_path)
33+
34+
with caplog.at_level(logging.WARNING):
35+
result = ccd_reader.read_pdb_components_file(
36+
str(path), sanitize=False, include=["007", "MISSING", "00O", "007"]
37+
)
38+
39+
assert list(result) == ["007", "00O"]
40+
assert "Data block MISSING not found" in caplog.text
41+
42+
43+
def test_parse_pdb_bonds_uses_atom_id_lookup():
44+
block = cif.read_string(
45+
"""
46+
data_TST
47+
loop_
48+
_chem_comp_atom.atom_id
49+
A
50+
B
51+
loop_
52+
_chem_comp_bond.atom_id_1
53+
_chem_comp_bond.atom_id_2
54+
_chem_comp_bond.value_order
55+
A B SING
56+
"""
57+
).sole_block()
58+
mol = Chem.RWMol()
59+
mol.AddAtom(Chem.Atom("C"))
60+
mol.AddAtom(Chem.Atom("O"))
61+
errors = []
62+
63+
ccd_reader._parse_pdb_bonds(mol, block, errors)
64+
65+
assert errors == []
66+
assert mol.GetNumBonds() == 1
67+
assert mol.GetBondBetweenAtoms(0, 1) is not None
68+
69+
70+
def test_parse_pdb_bonds_missing_atom_1_does_not_mask_error():
71+
block = cif.read_string(
72+
"""
73+
data_TST
74+
loop_
75+
_chem_comp_atom.atom_id
76+
A
77+
loop_
78+
_chem_comp_bond.atom_id_1
79+
_chem_comp_bond.atom_id_2
80+
_chem_comp_bond.value_order
81+
? A SING
82+
"""
83+
).sole_block()
84+
mol = Chem.RWMol()
85+
mol.AddAtom(Chem.Atom("C"))
86+
errors = []
87+
88+
ccd_reader._parse_pdb_bonds(mol, block, errors)
89+
90+
assert errors == [
91+
f"Missing atom in 0 entry in _chem_comp_bond"
92+
]
93+
assert mol.GetNumBonds() == 0

pdbeccdutils/tests/test_prd_reader.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ def test_read_prd_components_file_parses_all_for_empty_include():
1313
)
1414

1515
assert list(result) == ["PRD_000103"]
16+
17+
def test_read_prd_components_file_uses_include_order_and_skips_missing(caplog):
18+
path = prd_cif_filename("PRDCC_000103")
19+
20+
with caplog.at_level(logging.WARNING):
21+
result = prd_reader.read_pdb_components_file(
22+
path,
23+
sanitize=False,
24+
include=["PRD_000103", "MISSING", "PRD_000103"],
25+
)
26+
27+
assert list(result) == ["PRD_000103"]
28+
assert "Data block MISSING not found" in caplog.text

0 commit comments

Comments
 (0)