From d44761fa5196efacb2060e54b0afc657aa0b277b Mon Sep 17 00:00:00 2001 From: viseshrp Date: Mon, 10 Jul 2023 10:00:29 -0400 Subject: [PATCH 1/2] add set_comments API --- .../dynamicreporting/core/utils/report_objects.py | 12 ++++++++++++ tests/test_report_objects.py | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ansys/dynamicreporting/core/utils/report_objects.py b/src/ansys/dynamicreporting/core/utils/report_objects.py index db549896a..9ce0e827d 100644 --- a/src/ansys/dynamicreporting/core/utils/report_objects.py +++ b/src/ansys/dynamicreporting/core/utils/report_objects.py @@ -1634,6 +1634,18 @@ def set_html(self, value=""): else: raise ValueError(f"Error: HTML not supported on the report type {self.report_type}") + def set_comments(self, value=""): + if "Layout:" in self.report_type: + if isinstance(value, str): + d = json.loads(self.params) + d["comments"] = value + self.params = json.dumps(d) + return + else: + raise ValueError("Error: input needs to be a string") + else: + raise ValueError(f"Error: HTML not supported on the report type {self.report_type}") + def get_transpose(self): if "Layout:" in self.report_type: if "transpose" in json.loads(self.params): diff --git a/tests/test_report_objects.py b/tests/test_report_objects.py index 12b13e352..a49badf2c 100755 --- a/tests/test_report_objects.py +++ b/tests/test_report_objects.py @@ -366,6 +366,17 @@ def test_layout_html() -> bool: assert success +def test_set_comments() -> None: + a = ro.LayoutREST() + a.set_comments(value="lololol") + success = False + try: + a.set_comments(value=4) + except ValueError as e: + success = "input needs to be a string" in str(e) + assert success + + def test_layout_transport() -> bool: a = ro.LayoutREST() zero = a.get_transpose() From 18ceeadf8a4653cd5e0604176e1eae43043246de Mon Sep 17 00:00:00 2001 From: viseshrp Date: Mon, 10 Jul 2023 10:13:45 -0400 Subject: [PATCH 2/2] fix exception string --- src/ansys/dynamicreporting/core/utils/report_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_objects.py b/src/ansys/dynamicreporting/core/utils/report_objects.py index 9ce0e827d..d8e5e4ba3 100644 --- a/src/ansys/dynamicreporting/core/utils/report_objects.py +++ b/src/ansys/dynamicreporting/core/utils/report_objects.py @@ -1644,7 +1644,7 @@ def set_comments(self, value=""): else: raise ValueError("Error: input needs to be a string") else: - raise ValueError(f"Error: HTML not supported on the report type {self.report_type}") + raise ValueError(f"Error: Comments not supported on the report type {self.report_type}") def get_transpose(self): if "Layout:" in self.report_type: