From 3997a00b232e181e7952777d4bc6acabb9c35ede Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Mon, 25 Sep 2023 12:48:20 +0100 Subject: [PATCH] test and fix When.first feature --- pyproject.toml | 2 +- src/ibek/render.py | 4 ++-- tests/samples/outputs/all.st.cmd | 1 + tests/samples/outputs/objects.st.cmd | 1 + tests/samples/yaml/objects.ibek.support.yaml | 3 +++ tests/test_render.py | 4 +++- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 85d561e08..f92688f1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ addopts = """ --cov=ibek --cov-report term --cov-report xml:cov.xml """ # https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings -filterwarnings = "error" +filterwarnings = ["error", "ignore::pytest_cov.plugin.CovDisabledWarning"] # Doctest python code in docs, python code in src docstrings, test functions in tests testpaths = "docs src tests" diff --git a/src/ibek/render.py b/src/ibek/render.py index bde45a684..0c427dac3 100644 --- a/src/ibek/render.py +++ b/src/ibek/render.py @@ -35,13 +35,13 @@ def render_text( Entity has more than one element to render once (e.g. functions) """ - if when == When.first: + if when == When.first.value: name = instance.__definition__.name + suffix if name not in self.once_done: self.once_done.append(name) else: return "" - elif when == When.last: + elif when == When.last.value: raise NotImplementedError("When.last not yet implemented") # Render Jinja entries in the text diff --git a/tests/samples/outputs/all.st.cmd b/tests/samples/outputs/all.st.cmd index b91b3322e..582369a24 100644 --- a/tests/samples/outputs/all.st.cmd +++ b/tests/samples/outputs/all.st.cmd @@ -7,6 +7,7 @@ epicsEnvSet REF_OBJECT_NAME Ref1 dbLoadDatabase dbd/ioc.dbd ioc_registerRecordDeviceDriver pdbbase +# This line should appear once only in the pre_init section # TestValues testValue TestValues Ref1.127.0.0.1 # this is a comment diff --git a/tests/samples/outputs/objects.st.cmd b/tests/samples/outputs/objects.st.cmd index e98d901ba..044537129 100644 --- a/tests/samples/outputs/objects.st.cmd +++ b/tests/samples/outputs/objects.st.cmd @@ -8,6 +8,7 @@ epicsEnvSet REF_OBJECT_NAME AsynPort2 dbLoadDatabase dbd/ioc.dbd ioc_registerRecordDeviceDriver pdbbase +# This line should appear once only in the pre_init section # TestValues testValue TestValues AsynPort1.127.0.0.1 # TestValues testValue diff --git a/tests/samples/yaml/objects.ibek.support.yaml b/tests/samples/yaml/objects.ibek.support.yaml index fe886aa91..83a6eb7c0 100644 --- a/tests/samples/yaml/objects.ibek.support.yaml +++ b/tests/samples/yaml/objects.ibek.support.yaml @@ -29,6 +29,9 @@ defs: value: "{{ name }}" pre_init: + - when: first + value: | + # This line should appear once only in the pre_init section - value: | # TestValues testValue TestValues {{ test_value }} diff --git a/tests/test_render.py b/tests/test_render.py index 02ddcb274..fd0ad15c3 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -26,7 +26,9 @@ def test_pre_init_script(objects_classes): render = Render() script_txt = render.render_script(my_ref, my_ref.__definition__.pre_init) assert script_txt == ( - "# TestValues testValue\n" "TestValues test_ref_object.127.0.0.1\n" + "# This line should appear once only in the pre_init section\n" + "# TestValues testValue\n" + "TestValues test_ref_object.127.0.0.1\n" )