|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | from copy import deepcopy |
| 6 | +from types import SimpleNamespace |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 | from glotaran.testing.simulated_data.parallel_spectral_decay import SCHEME as SCHEME_PAR |
@@ -119,16 +120,23 @@ def test_invalid_megacomplex_raises_value_error(self) -> None: |
119 | 120 | with pytest.raises(ValueError, match="not found"): |
120 | 121 | extract_transitions("nonexistent_mc", SCHEME_SEQ.model, SCHEME_SEQ.parameters) |
121 | 122 |
|
122 | | - def test_non_decay_megacomplex_raises_type_error(self) -> None: |
| 123 | + def test_non_decay_megacomplex_raises_type_error( |
| 124 | + self, monkeypatch: pytest.MonkeyPatch |
| 125 | + ) -> None: |
123 | 126 | """Non-decay megacomplex without get_k_matrix raises TypeError.""" |
124 | | - # Create a model that has a coherent-artifact megacomplex |
125 | | - # For now, we test with a mock approach |
126 | | - # The sequential model only has decay megacomplexes, so we test |
127 | | - # that valid ones don't raise |
128 | | - transitions = extract_transitions( |
129 | | - "megacomplex_sequential_decay", SCHEME_SEQ.model, SCHEME_SEQ.parameters |
| 127 | + model = deepcopy(SCHEME_SEQ.model) |
| 128 | + mc_label = "megacomplex_coherent_artifact" |
| 129 | + model.megacomplex[mc_label] = SimpleNamespace(type="coherent-artifact") |
| 130 | + |
| 131 | + # Simulate filling a non-decay megacomplex object that does not expose |
| 132 | + # get_k_matrix, which should trigger the TypeError path. |
| 133 | + monkeypatch.setattr( |
| 134 | + "pyglotaran_extras.inspect.kinetic_scheme._k_matrix_parser.fill_item", |
| 135 | + lambda *_args, **_kwargs: SimpleNamespace(), |
130 | 136 | ) |
131 | | - assert len(transitions) > 0 |
| 137 | + |
| 138 | + with pytest.raises(TypeError, match="does not support k-matrix extraction"): |
| 139 | + extract_transitions(mc_label, model, SCHEME_SEQ.parameters) |
132 | 140 |
|
133 | 141 |
|
134 | 142 | class TestExtractTransitionsFiltering: |
|
0 commit comments