Skip to content

Commit

Permalink
test and fix When.first feature
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 25, 2023
1 parent 44c4045 commit 3997a00
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/ibek/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/samples/outputs/all.st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/samples/outputs/objects.st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/samples/yaml/objects.ibek.support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down

0 comments on commit 3997a00

Please sign in to comment.