From 520d3f7ad80cfb577ccf2372d6e0db78a850ad30 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Tue, 16 Nov 2021 22:05:42 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Added=20failing=20test=20cas?= =?UTF-8?q?e=20showinf=20the=20expected=20output=20of=20Model.markdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- glotaran/model/test/test_model.py | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) 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 From d313129abbb0cc1c1abede203488028423dc6526 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Tue, 16 Nov 2021 22:06:43 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A9=B9=20Change=20Model.markdown=20to?= =?UTF-8?q?=20satisfy=20the=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- glotaran/model/model.py | 9 +++++++++ 1 file changed, 9 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: