Skip to content

Commit

Permalink
🩹 Fix AttributeError validating bad DOAS user definition (#1513)
Browse files Browse the repository at this point in the history
* 🧪 Add failing test reproducing the AttributeError validating a bad DOAS user definition

* 🩹 Fix AttributeError validating bad DOAS user definition

* 🚧📚 Added change to changelog

* 👌 Fixed some typos

* 🩹 Also fix typos in implementation

---------

Co-authored-by: Joris Snellenburg <[email protected]>
  • Loading branch information
s-weigand and jsnel authored Aug 23, 2024
1 parent e53fcd5 commit 96bb57d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### 🩹 Bug fixes

- 🩹 Fix ordering bug in MatrixProvider class (#1512)
- 🩹 Fix AttributeError validating bad DOAS user definition (#1513)

### 🚧 Maintenance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

class OscillationParameterIssue(ItemIssue):
def __init__(self, label: str, len_labels: int, len_frequencies: int, len_rates: int):
self._label = label
self._len_labels = len_labels
self._len_frequencies = len_frequencies
self._len_rates = len_rates
self.label = label
self.len_labels = len_labels
self.len_frequencies = len_frequencies
self.len_rates = len_rates

def to_string(self) -> str:
return (
f"Size of labels ({self.len_labels}), frequencies ({self.len_frequencies}) "
f"The size of labels ({self.len_labels}), frequencies ({self.len_frequencies}), "
f"and rates ({self.len_rates}) does not match for damped oscillation "
f"megacomplex '{self.label}'."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,19 @@ def test_doas_model(suite):
assert "damped_oscillation_sin" in resultdata
assert "damped_oscillation_associated_spectra" in resultdata
assert "damped_oscillation_phase" in resultdata


def test_doas_model_validate():
"""An ``OscillationParameterIssue`` should be raised if there is a list length mismatch.
List values are: ``labels``, ``frequencies``, ``rates``.
"""
model_data = OneOscillation.sim_model.as_dict()
model_data["megacomplex"]["m1"]["labels"].append("extra-label")
model = DampedOscillationsModel(**model_data)
validation_msg = model.validate()
assert (
validation_msg == "Your model has 1 problem:\n\n"
" * The size of labels (2), frequencies (1), and rates (1) does not match for damped "
"oscillation megacomplex 'm1'."
)

0 comments on commit 96bb57d

Please sign in to comment.