Skip to content

Commit

Permalink
Fix reminder_info and add test (#683)
Browse files Browse the repository at this point in the history
* only update the reminder_info if there is a setting panel
* add test
  • Loading branch information
superstar54 authored Apr 25, 2024
1 parent 038d30f commit cbc0023
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
17 changes: 10 additions & 7 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_info = {}
self.property_children = [
self.properties_title,
ipw.HTML("Select which properties to calculate:"),
Expand All @@ -97,22 +98,24 @@ 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()
if name in setting_entries:
reminder_text = ipw.HTML()
self.reminder_info[name] = ipw.HTML()
self.property_children.append(
ipw.HBox([self.properties[name], reminder_text])
ipw.HBox([self.properties[name], self.reminder_info[name]])
)

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

self.properties[name].run.observe(update_reminder_text, "value")
if name in setting_entries:
self.properties[name].run.observe(update_reminder_info, "value")

self.property_children.append(self.properties_help)
self.children = [
Expand Down
22 changes: 22 additions & 0 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,25 @@ def test_panel():
assert len(wg.tab.children) == 3
parameters = wg.get_configuration_parameters()
assert "bands" in parameters


def test_reminder_info():
"""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_info["bands"].value == ""
# select bands
wg.workchain_settings.properties["bands"].run.value = True
for name in wg.workchain_settings.reminder_info:
if name == "bands":
assert (
wg.workchain_settings.reminder_info["bands"].value
== "Customize bands settings in the panel above if needed."
)
else:
# all other reminder texts should be empty
assert wg.workchain_settings.reminder_info[name].value == ""
# unselect bands
wg.workchain_settings.properties["bands"].run.value = False
assert wg.workchain_settings.reminder_info["bands"].value == ""

0 comments on commit cbc0023

Please sign in to comment.