Skip to content

Commit a06e379

Browse files
committed
removing redundant tests
1 parent 6c984e6 commit a06e379

4 files changed

Lines changed: 6 additions & 180 deletions

File tree

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,12 @@
1-
import logging
2-
from types import SimpleNamespace
3-
from unittest.mock import MagicMock
4-
5-
import numpy as np
6-
import pytest
7-
81
from CodeEntropy.entropy.configurational import ConformationalEntropy
92

103

11-
def test_validate_assignment_config_step_must_be_positive():
12-
ce = ConformationalEntropy()
13-
with pytest.raises(ValueError):
14-
ce.assign_conformation(
15-
data_container=SimpleNamespace(trajectory=list(range(5))),
16-
dihedral=MagicMock(value=lambda: 10.0),
17-
number_frames=5,
18-
bin_width=30,
19-
start=0,
20-
end=5,
21-
step=0,
22-
)
23-
24-
25-
def test_validate_assignment_config_bin_width_out_of_range():
26-
ce = ConformationalEntropy()
27-
with pytest.raises(ValueError):
28-
ce.assign_conformation(
29-
data_container=SimpleNamespace(trajectory=list(range(5))),
30-
dihedral=MagicMock(value=lambda: 10.0),
31-
number_frames=5,
32-
bin_width=0,
33-
start=0,
34-
end=5,
35-
step=1,
36-
)
37-
38-
39-
def test_validate_assignment_config_warns_when_bin_width_not_dividing_360(caplog):
40-
ce = ConformationalEntropy()
41-
caplog.set_level(logging.WARNING)
42-
43-
data_container = SimpleNamespace(trajectory=list(range(5)))
44-
dihedral = MagicMock()
45-
dihedral.value.return_value = 10.0
46-
47-
ce.assign_conformation(
48-
data_container=data_container,
49-
dihedral=dihedral,
50-
number_frames=5,
51-
bin_width=7,
52-
start=0,
53-
end=5,
54-
step=1,
55-
)
56-
57-
assert any("does not evenly divide 360" in r.message for r in caplog.records)
58-
59-
60-
def test_collect_dihedral_angles_normalizes_negative_values():
61-
ce = ConformationalEntropy()
62-
63-
traj_slice = list(range(3))
64-
dihedral = MagicMock()
65-
dihedral.value.side_effect = [-10.0, 0.0, 10.0]
66-
67-
phi = ce._collect_dihedral_angles(traj_slice, dihedral)
68-
69-
assert phi[0] == pytest.approx(350.0)
70-
71-
724
def test_to_1d_array_returns_none_for_non_iterable_state_input():
735
ce = ConformationalEntropy()
746
# int is not iterable -> list(states) raises TypeError -> returns None
757
assert ce._to_1d_array(123) is None
768

779

78-
def test_find_histogram_peaks_skips_zero_population_bins():
79-
ce = ConformationalEntropy()
80-
81-
phi = np.zeros(50, dtype=float)
82-
83-
peaks = ce._find_histogram_peaks(phi, bin_width=30)
84-
85-
assert peaks.size >= 1
86-
87-
8810
def test_to_1d_array_returns_none_when_states_is_none():
8911
ce = ConformationalEntropy()
9012
assert ce._to_1d_array(None) is None
Lines changed: 3 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,17 @@
1-
from types import SimpleNamespace
2-
from unittest.mock import MagicMock
3-
41
import numpy as np
52
import pytest
63

74
from CodeEntropy.entropy.configurational import ConformationalEntropy
85

96

10-
def test_find_histogram_peaks_empty_histogram_returns_empty():
11-
ce = ConformationalEntropy()
12-
phi = np.zeros(100, dtype=float)
13-
14-
peaks = ce._find_histogram_peaks(phi, bin_width=30)
15-
16-
assert isinstance(peaks, np.ndarray)
17-
assert peaks.dtype == float
18-
19-
20-
def test_find_histogram_peaks_returns_empty_for_empty_phi():
21-
ce = ConformationalEntropy()
22-
phi = np.array([], dtype=float)
23-
24-
peaks = ce._find_histogram_peaks(phi, bin_width=30)
25-
26-
assert isinstance(peaks, np.ndarray)
27-
assert peaks.size == 0
28-
29-
30-
def test_assign_nearest_peaks_with_single_peak_assigns_all_zero():
31-
ce = ConformationalEntropy()
32-
phi = np.array([0.0, 10.0, 20.0], dtype=float)
33-
peak_values = np.array([15.0], dtype=float)
34-
35-
states = ce._assign_nearest_peaks(phi, peak_values)
36-
37-
assert np.all(states == 0)
38-
39-
40-
def test_assign_conformation_no_peaks_returns_all_zero():
41-
ce = ConformationalEntropy()
42-
43-
data_container = SimpleNamespace(trajectory=[])
44-
dihedral = MagicMock()
45-
46-
states = ce.assign_conformation(
47-
data_container=data_container,
48-
dihedral=dihedral,
49-
number_frames=0,
50-
bin_width=30,
51-
start=0,
52-
end=0,
53-
step=1,
54-
)
55-
56-
assert states.size == 0
57-
58-
59-
def test_assign_conformation_fallback_when_peak_finder_returns_empty(monkeypatch):
60-
ce = ConformationalEntropy()
61-
data_container = SimpleNamespace(trajectory=list(range(5)))
62-
dihedral = MagicMock()
63-
dihedral.value.return_value = 10.0
64-
65-
monkeypatch.setattr(
66-
ce, "_find_histogram_peaks", lambda phi, bw: np.array([], dtype=float)
67-
)
68-
69-
states = ce.assign_conformation(
70-
data_container=data_container,
71-
dihedral=dihedral,
72-
number_frames=5,
73-
bin_width=30,
74-
start=0,
75-
end=5,
76-
step=1,
77-
)
78-
assert np.all(states == 0)
79-
80-
81-
def test_assign_conformation_detects_multiple_states():
82-
ce = ConformationalEntropy()
83-
84-
values = [0.0] * 50 + [180.0] * 50
85-
data_container = SimpleNamespace(trajectory=list(range(len(values))))
86-
dihedral = MagicMock()
87-
dihedral.value.side_effect = values
88-
89-
states = ce.assign_conformation(
90-
data_container=data_container,
91-
dihedral=dihedral,
92-
number_frames=len(values),
93-
bin_width=30,
94-
start=0,
95-
end=len(values),
96-
step=1,
97-
)
98-
99-
assert len(np.unique(states)) >= 2
100-
101-
1027
def test_conformational_entropy_empty_returns_zero():
1038
ce = ConformationalEntropy()
104-
assert ce.conformational_entropy_calculation([], number_frames=10) == 0.0
9+
assert ce.conformational_entropy_calculation([]) == 0.0
10510

10611

10712
def test_conformational_entropy_single_state_returns_zero():
10813
ce = ConformationalEntropy()
109-
assert ce.conformational_entropy_calculation([0, 0, 0], number_frames=3) == 0.0
14+
assert ce.conformational_entropy_calculation([0, 0, 0]) == 0.0
11015

11116

11217
def test_conformational_entropy_known_distribution_matches_expected():
@@ -116,5 +21,5 @@ def test_conformational_entropy_known_distribution_matches_expected():
11621
probs = np.array([2 / 6, 3 / 6, 1 / 6], dtype=float)
11722
expected = -ce._GAS_CONST * float(np.sum(probs * np.log(probs)))
11823

119-
got = ce.conformational_entropy_calculation(states, number_frames=6)
24+
got = ce.conformational_entropy_calculation(states)
12025
assert got == pytest.approx(expected)

tests/unit/CodeEntropy/entropy/test_orientational_entropy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
def test_orientational_negative_count_raises():
99
oe = OrientationalEntropy(_GAS_CONST)
1010
with pytest.raises(ValueError):
11-
oe.calculate_orientational(-1, 1, False)
11+
oe.calculate(-1, 1, False)
1212

1313

1414
def test_orientational_zero_count_contributes_zero():
1515
oe = OrientationalEntropy(_GAS_CONST)
16-
assert oe.calculate_orientational(0, 1, False) == 0.0
16+
assert oe.calculate(0, 1, False) == 0.0
1717

1818

1919
def test_omega_linear():

tests/unit/CodeEntropy/results/test_reporter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ def fake_resolve(self):
329329

330330
assert ResultsReporter._try_get_git_sha() == "sha"
331331
_args, kwargs = mock_run.call_args
332-
assert "stdout" in kwargs
333-
assert "stderr" in kwargs
332+
assert "capture_output" in kwargs
334333
assert kwargs.get("text") is True
335334

336335

0 commit comments

Comments
 (0)