Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: Test new aiida pytest fixtures #582

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- main
pull_request:

env:
FORCE_COLOR: '1'

# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
Expand Down Expand Up @@ -84,7 +86,8 @@ jobs:
matrix:
python-version: ['3.9', '3.10']
# Test on the latest and oldest supported version
aiida-core-version: [2.2.2, 2.4.3]
aiida-core-version:
- git+https://github.com/sphuber/aiida-core@feature/improved-profile-fixtures
fail-fast: false

runs-on: ubuntu-latest
Expand All @@ -108,7 +111,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install uv
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.27/uv-installer.sh | sh
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.31/uv-installer.sh | sh

- name: Install package
# NOTE: uv (unlike pip) does not compile python to bytecode after install.
Expand All @@ -117,7 +120,7 @@ jobs:
# Ideally, these would be fixed, but vapory is largely unmaintained,
# so here we simply keep the pip behaviour with the --compile flag.
# See https://github.com/astral-sh/uv/issues/1928#issuecomment-1968857514
run: uv pip install --compile --system .[dev,smiles,optimade] aiida-core==${{ matrix.aiida-core-version }}
run: uv pip install --compile --system .[dev,smiles,optimade] ${{ matrix.aiida-core-version }}

- name: Run pytest
run: pytest -v tests --cov
Expand Down
5 changes: 2 additions & 3 deletions aiidalab_widgets_base/elns.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ def _observe_node(self, _=None):
if self.node is None or self.eln is None:
return

if "eln" in self.node.extras:
info = self.node.extras["eln"]
else:
info = self.node.base.extras.get("eln", {})
if not info:
try:
q = orm.QueryBuilder().append(
orm.Node,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
filterwarnings = [
'error',
#'error',
'ignore::DeprecationWarning:bokeh.core.property.primitive',
'ignore:Creating AiiDA configuration:UserWarning:aiida',
'ignore:crystal system:UserWarning:ase.io.cif',
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ optimade =
ipyoptimade~=0.1
smiles =
rdkit>=2021.09.2
scikit-learn~=1.0.0
scikit-learn~=1.0
docs =
sphinx
sphinx-design
Expand Down
19 changes: 10 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
import pytest
from aiida import engine, orm, plugins

pytest_plugins = ["aiida.manage.tests.pytest_fixtures"]
pytest_plugins = ["aiida.tools.pytest_fixtures"]


@pytest.fixture
def fixture_localhost(aiida_localhost):
def localhost(aiida_localhost):
"""Return a localhost `Computer`."""
localhost = aiida_localhost
localhost.set_default_mpiprocs_per_machine(1)
return localhost
aiida_localhost.set_default_mpiprocs_per_machine(1)
return aiida_localhost


@pytest.fixture
def generate_calc_job_node(fixture_localhost):
def generate_calc_job_node(localhost):
"""Fixture to generate a mock `CalcJobNode` for testing parsers."""

def flatten_inputs(inputs, prefix=""):
Expand Down Expand Up @@ -60,7 +59,7 @@ def _generate_calc_job_node(
from plumpy import ProcessState

if computer is None:
computer = fixture_localhost
computer = localhost

filepath_folder = None

Expand Down Expand Up @@ -275,9 +274,11 @@ def folder_data_object():


@pytest.fixture
def aiida_local_code_bash(aiida_local_code_factory):
def aiida_local_code_bash(aiida_code_installed):
"""Return a `Code` configured for the bash executable."""
return aiida_local_code_factory(executable="bash", entry_point="bash")
return aiida_code_installed(
filepath_executable="/bin/bash", default_calc_job_plugin="bash"
)


@pytest.fixture
Expand Down
34 changes: 5 additions & 29 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,28 @@ def test_process_outputs_widget(multiply_add_completed_workchain):


@pytest.mark.usefixtures("aiida_profile_clean")
def test_process_follower_widget(multiply_add_process_builder_ready, daemon_client):
def test_process_follower_widget(multiply_add_process_builder_ready):
"""Test ProcessFollowerWidget with a simple `WorkChainNode`"""
# Test the widget can be instantiated with empty inputs
widget = awb.ProcessFollowerWidget()

if daemon_client.is_daemon_running:
daemon_client.stop_daemon(wait=True)
process = engine.submit(multiply_add_process_builder_ready)

# Test the widget can be instantiated with a process
widget = awb.ProcessFollowerWidget(process=process)

daemon_client.start_daemon()

# Follow the process till it is completed.
widget.follow()

daemon_client.stop_daemon(wait=True)


@pytest.mark.usefixtures("aiida_profile_clean")
def test_process_report_widget(
multiply_add_process_builder_ready, daemon_client, await_for_process_completeness
multiply_add_process_builder_ready, await_for_process_completeness
):
"""Test ProcessReportWidget with a simple `WorkChainNode`"""
# Test the widget can be instantiated with empty inputs
awb.ProcessReportWidget()

# Stopping the daemon and submitting the process.
if daemon_client.is_daemon_running:
daemon_client.stop_daemon(wait=True)
process = engine.submit(multiply_add_process_builder_ready)

# Test the widget can be instantiated with a process
Expand All @@ -113,17 +104,14 @@ def test_process_report_widget(
widget.value == "No log messages recorded for this entry"
) # No report produced yet.

# Starting the daemon and waiting for the process to complete.
daemon_client.start_daemon()
await_for_process_completeness(process)

widget.update()
daemon_client.stop_daemon(wait=True)


@pytest.mark.usefixtures("aiida_profile_clean")
def test_process_call_stack_widget(
multiply_add_process_builder_ready, daemon_client, await_for_process_completeness
multiply_add_process_builder_ready, await_for_process_completeness
):
"""Test ProcessCallStackWidget with a simple `WorkChainNode`"""
from aiidalab_widgets_base.process import ProcessCallStackWidget
Expand All @@ -132,26 +120,22 @@ def test_process_call_stack_widget(
ProcessCallStackWidget()

# Stopping the daemon and submitting the process.
if daemon_client.is_daemon_running:
daemon_client.stop_daemon(wait=True)
process = engine.submit(multiply_add_process_builder_ready)

# Test the widget can be instantiated with a process
widget = ProcessCallStackWidget(process=process)
assert widget.value.endswith("Created")

# Starting the daemon and waiting for the process to complete.
daemon_client.start_daemon()
await_for_process_completeness(process)

widget.update()
assert "ArithmeticAddCalculation" in widget.value
daemon_client.stop_daemon(wait=True)


@pytest.mark.usefixtures("aiida_profile_clean")
def test_progress_bar_widget(
multiply_add_process_builder_ready, daemon_client, await_for_process_completeness
multiply_add_process_builder_ready, await_for_process_completeness
):
"""Test ProgressBarWidget with a simple `WorkChainNode`"""
from aiidalab_widgets_base import ProgressBarWidget
Expand All @@ -160,21 +144,17 @@ def test_progress_bar_widget(
ProgressBarWidget()

# Stopping the daemon and submitting the process.
if daemon_client.is_daemon_running:
daemon_client.stop_daemon(wait=True)
process = engine.submit(multiply_add_process_builder_ready)

# Test the widget can be instantiated with a process
widget = ProgressBarWidget(process=process)
assert widget.state.value == "Created"

# Starting the daemon and waiting for the process to complete.
daemon_client.start_daemon()
await_for_process_completeness(process)

widget.update()
assert widget.state.value == "Finished"
daemon_client.stop_daemon(wait=True)


@pytest.mark.usefixtures("aiida_profile_clean")
Expand Down Expand Up @@ -223,14 +203,12 @@ def test_process_list_widget(multiply_add_completed_workchain):

@pytest.mark.usefixtures("aiida_profile_clean")
def test_process_monitor(
multiply_add_process_builder_ready, daemon_client, await_for_process_completeness
multiply_add_process_builder_ready, await_for_process_completeness
):
"""Test ProcessMonitor with a simple `WorkChainNode`"""
awb.ProcessMonitor()

# Stopping the daemon and submitting the process.
if daemon_client.is_daemon_running:
daemon_client.stop_daemon(wait=True)
process = engine.submit(multiply_add_process_builder_ready)

test_variable = False
Expand All @@ -242,13 +220,11 @@ def f():
widget = awb.ProcessMonitor(value=process.uuid, callbacks=[f])

# Starting the daemon and waiting for the process to complete.
daemon_client.start_daemon()
await_for_process_completeness(process)

widget.join() # Make sure the thread is finished.

assert test_variable
daemon_client.stop_daemon(wait=True)


@pytest.mark.usefixtures("aiida_profile_clean")
Expand Down
Loading