Skip to content

Commit 71127da

Browse files
committed
starting testing for rearranged functions
1 parent 0ae99c0 commit 71127da

6 files changed

Lines changed: 464 additions & 537 deletions

File tree

‎CodeEntropy/dihedral_tools.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def _get_dihedrals(self, data_container, level):
220220
)
221221
atom4 = data_container.select_atoms(atom_string)
222222

223-
atom_groups.append(atom1 + atom2 + atom3 + atom4)
223+
atom_group = atom1 + atom2 + atom3 + atom4
224+
atom_groups.append(atom_group)
224225

225226
logger.debug(f"Level: {level}, Dihedrals: {atom_groups}")
226227

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from unittest.mock import MagicMock
2+
3+
from CodeEntropy.dihedral_tools import DihedralAnalysis
4+
from tests.test_CodeEntropy.test_base import BaseTestCase
5+
6+
7+
class TestDihedralAnalysis(BaseTestCase):
8+
"""
9+
Unit tests for DihedralAnalysis.
10+
"""
11+
12+
def setUp(self):
13+
super().setUp()
14+
15+
def test_get_dihedrals_united_atom(self):
16+
"""
17+
Test `get_dihedrals` for 'united_atom' level.
18+
Ensures it returns the dihedrals directly from the data container.
19+
"""
20+
data_container = MagicMock()
21+
mock_dihedrals = ["d1", "d2", "d3"]
22+
data_container.dihedrals = mock_dihedrals
23+
24+
result = DihedralAnalysis._get_dihedrals(data_container, level="united_atom")
25+
self.assertEqual(result, mock_dihedrals)
26+
27+
def test_get_dihedrals_residue(self):
28+
"""
29+
Test `get_dihedrals` for 'residue' level with 5 residues.
30+
Mocks bonded atom selections and verifies that dihedrals are constructed.
31+
"""
32+
data_container = MagicMock()
33+
data_container.residues = [0, 1, 2, 3, 4] # 5 residues
34+
35+
# Mock select_atoms to return atom groups with .dihedral
36+
mock_dihedral = MagicMock()
37+
mock_atom_group = MagicMock()
38+
mock_atom_group.__add__.return_value = mock_atom_group
39+
mock_atom_group.dihedral = mock_dihedral
40+
data_container.select_atoms.return_value = mock_atom_group
41+
42+
result = DihedralAnalysis._get_dihedrals(data_container, level="residue")
43+
44+
# Should create 2 dihedrals for 5 residues (residues 0–3 and 1–4)
45+
self.assertEqual(len(result), 2)
46+
self.assertTrue(all(d == mock_dihedral for d in result))
47+
48+
def test_get_dihedrals_no_residue(self):
49+
"""
50+
Test `get_dihedrals` for 'residue' level with 3 residues.
51+
Mocks bonded atom selections and verifies that dihedrals are constructed.
52+
"""
53+
54+
data_container = MagicMock()
55+
data_container.residues = [0, 1, 2] # 3 residues
56+
57+
# Mock select_atoms to return atom groups with .dihedral
58+
mock_dihedral = MagicMock()
59+
mock_atom_group = MagicMock()
60+
mock_atom_group.__add__.return_value = mock_atom_group
61+
mock_atom_group.dihedral = mock_dihedral
62+
data_container.select_atoms.return_value = mock_atom_group
63+
64+
result = DihedralAnalysis._get_dihedrals(data_container, level="residue")
65+
66+
# Should result in no residue dihedrals
67+
self.assertEqual(result, [])

0 commit comments

Comments
 (0)