Skip to content

Commit

Permalink
Rearrange the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 16, 2023
1 parent 4a79b02 commit e5056ad
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 143 deletions.
19 changes: 0 additions & 19 deletions stack/docker-compose.base-with-services.yml

This file was deleted.

48 changes: 0 additions & 48 deletions stack/docker-compose.base.yml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def pytest_addoption(parser):
parser.addoption(
"--variant",
action="store",
default="base",
default="lab",
help="Variant (image name) of the docker-compose file to use.",
)

Expand Down
21 changes: 0 additions & 21 deletions tests/test-base-with-services.py

This file was deleted.

53 changes: 0 additions & 53 deletions tests/test-base.py

This file was deleted.

54 changes: 53 additions & 1 deletion tests/test-common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
"""Tests for all images, which are docker/docker-compose related tests."""
"""Tests for all images, which are docker/docker-compose related and AiiDA/package management related tests."""
import requests
import pytest
import json
from packaging.version import parse


@pytest.mark.parametrize("incompatible_version", ["1.6.3"])
def test_prevent_pip_install_of_incompatible_aiida_version(
aiidalab_exec, nb_user, aiida_version, incompatible_version
):
package_manager = "pip"
assert parse(aiida_version) != parse(incompatible_version)
# Expected to succeed:
aiidalab_exec(
f"{package_manager} install aiida-core=={aiida_version}", user=nb_user
)
with pytest.raises(Exception):
aiidalab_exec(
f"{package_manager} install aiida-core=={incompatible_version}",
user=nb_user,
)


def test_correct_python_version_installed(aiidalab_exec, python_version):
info = json.loads(aiidalab_exec("mamba list --json --full-name python").decode())[0]
assert info["name"] == "python"
assert parse(info["version"]) == parse(python_version)


def test_create_conda_environment(aiidalab_exec, nb_user):
output = aiidalab_exec("conda create -y -n tmp", user=nb_user).decode().strip()
assert "conda activate tmp" in output
# New conda environments should be created in ~/.conda/envs/
output = aiidalab_exec("conda env list", user=nb_user).decode().strip()
assert f"/home/{nb_user}/.conda/envs/tmp" in output


def test_pip_check(aiidalab_exec):
aiidalab_exec("pip check")


def test_correct_aiida_version_installed(aiidalab_exec, aiida_version):
info = json.loads(
aiidalab_exec("mamba list --json --full-name aiida-core").decode()
)[0]
assert info["name"] == "aiida-core"
assert parse(info["version"]) == parse(aiida_version)


def test_path_local_pip(aiidalab_exec, nb_user):
"""test that the pip local bin path ~/.local/bin is added to PATH"""
output = aiidalab_exec("bash -c 'echo \"${PATH}\"'", user=nb_user).decode()
assert f"/home/{nb_user}/.local/bin" in output


def test_notebook_service_available(notebook_service):
Expand Down
22 changes: 22 additions & 0 deletions tests/test-full-stack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
"""Services related test and package integration tests by installing apps from app store."""
import pytest

import json
from packaging.version import parse


def test_correct_pgsql_version_installed(aiidalab_exec, pgsql_version):
info = json.loads(
aiidalab_exec(
"mamba list -n aiida-core-services --json --full-name postgresql"
).decode()
)[0]
assert info["name"] == "postgresql"
assert parse(info["version"]).major == parse(pgsql_version).major


def test_rabbitmq_can_start(aiidalab_exec):
"""Test the rabbitmq-server can start, the output should be empty if
the command is successful."""
output = aiidalab_exec("mamba run -n aiida-core-services rabbitmq-server -detached")

assert output == b""


@pytest.fixture(scope="function")
def generate_aiidalab_install_output(aiidalab_exec, nb_user):
Expand Down

0 comments on commit e5056ad

Please sign in to comment.