From b3b8b8760c0fdd0c1d9f5cb9eea014b162567e2b Mon Sep 17 00:00:00 2001 From: Sebastian Weigand Date: Wed, 17 Nov 2021 09:14:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20'dataset=5Fgroups'=20not?= =?UTF-8?q?=20shown=20in=20model=20markdown=20(#906)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🧪 Added failing test case showinf the expected output of Model.markdown * 🩹 Change Model.markdown to satisfy the test --- glotaran/model/model.py | 9 ++++ glotaran/model/test/test_model.py | 75 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/glotaran/model/model.py b/glotaran/model/model.py index 59f1f0111..1189baa8d 100644 --- a/glotaran/model/model.py +++ b/glotaran/model/model.py @@ -422,6 +422,15 @@ def markdown( string += ", ".join(self._megacomplex_types) string += "\n\n" + string += f"{base_heading}# Dataset Groups\n\n" + for group_name, group in self.dataset_group_models.items(): + string += f"* **{group_name}**:\n" + string += f" * *Label*: {group_name}\n" + for item_name, item_value in asdict(group).items(): + string += f" * *{item_name}*: {item_value}\n" + + string += "\n" + for name in self.model_items: items = getattr(self, name) if not items: diff --git a/glotaran/model/test/test_model.py b/glotaran/model/test/test_model.py index be38c5abf..5998fc516 100644 --- a/glotaran/model/test/test_model.py +++ b/glotaran/model/test/test_model.py @@ -1,5 +1,6 @@ from math import inf from math import nan +from textwrap import dedent from typing import Dict from typing import List from typing import Tuple @@ -22,6 +23,7 @@ from glotaran.model.weight import Weight from glotaran.parameter import Parameter from glotaran.parameter import ParameterGroup +from glotaran.testing.model_generators import SimpleModelGenerator @model_item( @@ -485,3 +487,76 @@ def test_only_constraint(): assert not oc2.applies(650) assert oc2.applies(701) assert oc2.target == "spectra2" + + +def test_model_markdown(): + """Full markdown string is as expected.""" + model = SimpleModelGenerator( + rates=[501e-3, 202e-4, 105e-5, {"non-negative": True}], + irf={"center": 1.3, "width": 7.8}, + k_matrix="sequential", + ) + expected = dedent( + """\ + # Model + + _Megacomplex Types_: decay + + ## Dataset Groups + + * **default**: + * *Label*: default + * *residual_function*: variable_projection + * *link_clp*: None + + ## K Matrix + + * **k1**: + * *Label*: k1 + * *Matrix*: + * *('s2', 's1')*: rates.1: **5.01000e-01** *(StdErr: 0e+00)* + * *('s3', 's2')*: rates.2: **2.02000e-02** *(StdErr: 0e+00)* + * *('s3', 's3')*: rates.3: **1.05000e-03** *(StdErr: 0e+00)* + + + ## Initial Concentration + + * **j1**: + * *Label*: j1 + * *Compartments*: ['s1', 's2', 's3'] + * *Parameters*: [inputs.1: **1.00000e+00** *(fixed)*, inputs.0: **0.00000e+00** *(fixed)*, inputs.0: **0.00000e+00** *(fixed)*] + * *Exclude From Normalize*: [] + + ## Irf + + * **irf1** (multi-gaussian): + * *Label*: irf1 + * *Type*: multi-gaussian + * *Center*: [irf.center: **1.30000e+00** *(StdErr: 0e+00)*] + * *Width*: [irf.width: **7.80000e+00** *(StdErr: 0e+00)*] + * *Normalize*: True + * *Backsweep*: False + + ## Megacomplex + + * **mc1** (None): + * *Label*: mc1 + * *Dimension*: time + * *K Matrix*: ['k1'] + + ## Dataset + + * **dataset1**: + * *Label*: dataset1 + * *Group*: default + * *Megacomplex*: ['mc1'] + * *Initial Concentration*: j1 + * *Irf*: irf1 + + """ # noqa: E501 + ) + + # Preprocessing to remove trailing whitespace after '* *Matrix*:' + result = "\n".join([line.rstrip(" ") for line in str(model.markdown()).split("\n")]) + + assert result == expected