Skip to content

Commit

Permalink
Remove warnings in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Sep 6, 2023
1 parent aec8f87 commit 6ed3e6f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v2
Expand Down
5 changes: 4 additions & 1 deletion aiidalab_widgets_base/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def __init__(self, value=0, description="Select functional group", **kwargs):
self.style = {"description_width": "initial"}
self.layout = {"width": "initial"}
super().__init__(
value=value, description=description, options=FUNCTIONAL_GROUPS, **kwargs
value=value,
description=description,
options=[(key, value) for key, value in FUNCTIONAL_GROUPS.items()],
**kwargs,
)

def rotate(self, align_to=(0, 0, 1), remove_anchor=False):
Expand Down
2 changes: 1 addition & 1 deletion aiidalab_widgets_base/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class OpenAiidaNodeInAppWidget(ipw.VBox):

def __init__(self, path_to_root="../", **kwargs):
self.path_to_root = path_to_root
self.tab = ipw.Tab(style={"description_width": "initial"})
self.tab = ipw.Tab()
self.tab_selection = ipw.RadioButtons(
options=[],
description="",
Expand Down
11 changes: 5 additions & 6 deletions aiidalab_widgets_base/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def follow(self, detach=False):

if self._monitor is None:
self._monitor = ProcessMonitor(
process=self.process,
value=self.process.uuid,
callbacks=[self.update],
on_sealed=self._run_after_completed,
timeout=self.update_interval,
Expand Down Expand Up @@ -415,7 +415,6 @@ def __init__(self, title="Progress Bar", **kwargs):
value=0,
min=0,
max=2,
step=1,
description="Progress:",
bar_style="warning", # 'success', 'info', 'warning', 'danger' or ''
orientation="horizontal",
Expand Down Expand Up @@ -538,7 +537,7 @@ def __init__(self, title="Running Job Output", **kwargs):
self.title = title
self.selection = ipw.Dropdown(
description="Select calculation:",
options={p.id: p for p in get_running_calcs(self.process)},
options=[(p.id, p) for p in get_running_calcs(self.process)],
style={"description_width": "initial"},
)
self.output = CalcJobOutputWidget()
Expand All @@ -551,9 +550,9 @@ def update(self):
return
with self.hold_trait_notifications():
old_label = self.selection.label
self.selection.options = {
str(p.id): p for p in get_running_calcs(self.process)
}
self.selection.options = [
(str(p.id), p) for p in get_running_calcs(self.process)
]
# If the selection remains the same.
if old_label in self.selection.options:
self.label = old_label # After changing options trait, the label and value traits might change as well.
Expand Down
12 changes: 7 additions & 5 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io
import pathlib
import tempfile
from collections import OrderedDict

import ase
import ipywidgets as ipw
Expand Down Expand Up @@ -98,7 +97,10 @@ def __init__(

# Store format selector.
data_format = ipw.RadioButtons(
options=self.SUPPORTED_DATA_FORMATS, description="Data type:"
options=[
(key, value) for key, value in self.SUPPORTED_DATA_FORMATS.items()
],
description="Data type:",
)
tl.link((data_format, "label"), (self, "node_class"))

Expand Down Expand Up @@ -658,8 +660,8 @@ def search(self, _=None):
matches = {n[0] for n in qbuild.iterall()}
matches = sorted(matches, reverse=True, key=lambda n: n.ctime)

options = OrderedDict()
options[f"Select a Structure ({len(matches)} found)"] = False
options = []
options.append((f"Select a Structure ({len(matches)} found)", False))

for mch in matches:
label = f"PK: {mch.pk}"
Expand All @@ -668,7 +670,7 @@ def search(self, _=None):
label += " | " + mch.node_type.split(".")[-2]
label += " | " + mch.label
label += " | " + mch.description
options[label] = mch
options.append((label, mch))

self.results.options = options

Expand Down
25 changes: 7 additions & 18 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,22 @@ def registration_decorator(widget):
return registration_decorator


def viewer(obj, downloadable=True, **kwargs):
def viewer(obj, **kwargs):
"""Display AiiDA data types in Jupyter notebooks.
:param downloadable: If True, add link/button to download the content of displayed AiiDA object.
:type downloadable: bool
Returns the object itself if the viewer wasn't found."""
if not isinstance(obj, orm.Node): # only working with AiiDA nodes
warnings.warn(
f"This viewer works only with AiiDA objects, got {type(obj)}", stacklevel=2
)
return obj

try:
if obj.node_type in AIIDA_VIEWER_MAPPING:
_viewer = AIIDA_VIEWER_MAPPING[obj.node_type]
except KeyError as exc:
if obj.node_type in str(exc):
warnings.warn(
f"Did not find an appropriate viewer for the {type(obj)} object. Returning the object "
"itself.",
stacklevel=2,
)
return obj
raise
return _viewer(obj, **kwargs)
else:
return _viewer(obj, downloadable=downloadable, **kwargs)
# No viewer registered for this type, return object itself
return obj


class AiidaNodeViewWidget(ipw.VBox):
Expand Down Expand Up @@ -294,12 +284,11 @@ def change_supercell(_=None):

# 3. Camera switcher
camera_type = ipw.ToggleButtons(
options={"Orthographic": "orthographic", "Perspective": "perspective"},
options=[("Orthographic", "orthographic"), ("Perspective", "perspective")],
description="Camera type:",
value=self._viewer.camera,
layout={"align_self": "flex-start"},
style={"button_width": "115.5px"},
orientation="vertical",
)

def change_camera(change):
Expand Down Expand Up @@ -482,7 +471,7 @@ def _download_tab(self):
)

# 4. Render a high quality image
self.render_btn = ipw.Button(description="Render", icon="fa-paint-brush")
self.render_btn = ipw.Button(description="Render", icon="paint-brush")
self.render_btn.on_click(self._render_structure)
self.render_box = ipw.VBox(
children=[ipw.Label("Render an image with POVRAY:"), self.render_btn]
Expand Down
5 changes: 4 additions & 1 deletion tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def test_cod_query_widget():
# Run the query.
widget._on_click_query()

# Select on of the results.
# Select one of the results.
# TODO: Select a different structure to get rid of the ASE warning:
# "ase/io/cif.py:401: UserWarning: crystal system 'cubic' is not interpreted
# for space group 'Pm-3m'. This may result in wrong setting!"
widget.drop_structure.label = "NiTi (id: 1100132)"

# Check that the structure was loaded.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def test_running_calcjob_output_widget(generate_calc_job_node):
}
)

# Test the widget can be instantiated with a process
RunningCalcJobOutputWidget(calculation=process)
widget = RunningCalcJobOutputWidget()
widget.process = process


@pytest.mark.usefixtures("aiida_profile_clean")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_several_data_viewers(


@pytest.mark.usefixtures("aiida_profile_clean")
def test_structure_data_viwer(structure_data_object):
def test_structure_data_viewer(structure_data_object):
v = viewers.viewer(structure_data_object)
assert isinstance(v, viewers.StructureDataViewer)

Expand Down

0 comments on commit 6ed3e6f

Please sign in to comment.