Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Apr 24, 2024
1 parent 2f314e6 commit 1fe1cc1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/aiidalab_qe/app/configuration/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, **kwargs):
value="moderate",
)
self.properties = {}
self.reminder_texts = {}
self.property_children = [
self.properties_title,
ipw.HTML("Select which properties to calculate:"),
Expand All @@ -97,19 +98,21 @@ def __init__(self, **kwargs):
setting_entries = get_entry_items("aiidalab_qe.properties", "setting")
for name, entry_point in entries.items():
self.properties[name] = entry_point()
reminder_text = ipw.HTML()
self.reminder_texts[name] = ipw.HTML()
self.property_children.append(
ipw.HBox([self.properties[name], reminder_text])
ipw.HBox([self.properties[name], self.reminder_texts[name]])
)

# observer change to update the reminder text
def update_reminder_text(change, reminder_text=reminder_text, name=name):
def update_reminder_text(change, name=name):
if change["new"]:
reminder_text.value = (
self.reminder_texts[
name
].value = (
f"""Customize {name} settings in the panel above if needed."""
)
else:
reminder_text.value = ""
self.reminder_texts[name].value = ""

if name in setting_entries:
self.properties[name].run.observe(update_reminder_text, "value")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@ def test_panel():
assert len(wg.tab.children) == 3
parameters = wg.get_configuration_parameters()
assert "bands" in parameters


def test_reminder_texts():
"""Dynamic add/remove the reminder text based on the workchain settings."""
from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

wg = ConfigureQeAppWorkChainStep()
assert wg.workchain_settings.reminder_texts["bands"].value == ""
wg.workchain_settings.properties["bands"].run.value = True
for name in wg.workchain_settings.reminder_texts:
if name == "bands":
assert (
wg.workchain_settings.reminder_texts["bands"].value
== "Customize bands settings in the panel above if needed."
)
else:
# all other reminder texts should be empty
assert wg.workchain_settings.reminder_texts[name].value == ""

0 comments on commit 1fe1cc1

Please sign in to comment.