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

Migrating to aiida v2.5 and optimade-python-tools 1.0 #527

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions aiida_optimade/mappers/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class ResourceMapper(OptimadeResourceMapper):
"relationships",
"links",
"meta",
"description",
"related",
"structures",
"data",
"self",
"references",
}

@classmethod
Expand Down
4 changes: 3 additions & 1 deletion aiida_optimade/mappers/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class StructureMapper(ResourceMapper):
"data.core.cif.CifData.": CifDataTranslator,
"data.core.structure.StructureData.": StructureDataTranslator,
}
REQUIRED_ATTRIBUTES = set(StructureResourceAttributes.schema().get("required"))
REQUIRED_ATTRIBUTES = set(
StructureResourceAttributes.model_json_schema().get("required")
)
# This should be REQUIRED_FIELDS, but should be set as such in `optimade`
ENTRY_RESOURCE_CLASS = StructureResource

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
optimade[server]~=0.25.3
aiida-core~=2.4.0
pymatgen>=2019.7.2,!=2019.9.7,<2024.6.5
optimade[server]~=1.0.1
aiida-core~=2.5.0
#pymatgen>=2019.7.2,!=2019.9.7,<2024.6.5

# Dependencies used directly in this package, but included through other dependencies:
# aiida-core:
Expand Down
14 changes: 7 additions & 7 deletions tests/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@


@pytest.fixture
def aiida_test_profile() -> str:
def aiida_test_profile_name() -> str:
"""Return AiiDA test profile used for AiiDA-OPTIMADE"""
from aiida_optimade.cli.cmd_aiida_optimade import AIIDA_OPTIMADE_TEST_PROFILE

return AIIDA_OPTIMADE_TEST_PROFILE


@pytest.fixture
def run_cli_command(aiida_test_profile: str):
def run_cli_command(aiida_test_profile_name: str):
"""Run a `click` command with the given options.

The call will raise if the command triggered an exception or the exit code returned
Expand All @@ -43,10 +43,10 @@ def _run_cli_command(
import traceback

runner = click.testing.CliRunner()
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile)
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile_name)
if profile == "test_profile":
# This is for local tests only
profile = aiida_test_profile
profile = aiida_test_profile_name
result = runner.invoke(command, options or [], env={"AIIDA_PROFILE": profile})

if raises:
Expand All @@ -68,7 +68,7 @@ def _run_cli_command(


@pytest.fixture
def run_and_terminate_server(aiida_test_profile: str):
def run_and_terminate_server(aiida_test_profile_name: str):
"""Run a `click` command with the given options.

The call will raise if the command triggered an exception or the exit code returned
Expand All @@ -89,10 +89,10 @@ def _run_and_terminate_server(
:param raises: Whether the command is expected to raise an exception
:return: Test result
"""
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile)
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile_name)
if profile == "test_profile":
# This is for local tests only
profile = aiida_test_profile
profile = aiida_test_profile_name

args = ["aiida-optimade", "-p", profile]
args.append(command)
Expand Down
18 changes: 9 additions & 9 deletions tests/cli/test_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is not None,
reason="Test is not for MongoDB",
)
def test_calc_all_new(run_cli_command, aiida_profile, top_dir, caplog):
def test_calc_all_new(run_cli_command, aiida_profile_populated, top_dir, caplog):
"""Test `aiida-optimade -p profile_name calc` works for non-existent fields.

By "non-existent" the meaning is calculating fields that don't already exist for
Expand All @@ -24,7 +24,7 @@ def test_calc_all_new(run_cli_command, aiida_profile, top_dir, caplog):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear database and get initialized_structure_nodes.aiida
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
archive = top_dir.joinpath("tests/cli/static/initialized_structure_nodes.aiida")
import_archive(archive)

Expand Down Expand Up @@ -97,7 +97,7 @@ def test_calc_all_new(run_cli_command, aiida_profile, top_dir, caplog):
), caplog.text

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
original_data = top_dir.joinpath("tests/static/test_structures.aiida")
import_archive(original_data)

Expand All @@ -106,7 +106,7 @@ def test_calc_all_new(run_cli_command, aiida_profile, top_dir, caplog):
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is not None,
reason="Test is not for MongoDB",
)
def test_calc(run_cli_command, aiida_profile, top_dir):
def test_calc(run_cli_command, aiida_profile_populated, top_dir):
"""Test `aiida-optimade -p profile_name calc` works."""
from aiida import orm
from aiida.tools.archive.imports import import_archive
Expand All @@ -115,7 +115,7 @@ def test_calc(run_cli_command, aiida_profile, top_dir):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear database and get initialized_structure_nodes.aiida
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
archive = top_dir.joinpath("tests/cli/static/initialized_structure_nodes.aiida")
import_archive(archive)

Expand Down Expand Up @@ -159,7 +159,7 @@ def test_calc(run_cli_command, aiida_profile, top_dir):
assert n_structure_data == n_updated_structure_data

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
original_data = top_dir.joinpath("tests/static/test_structures.aiida")
import_archive(original_data)

Expand All @@ -168,7 +168,7 @@ def test_calc(run_cli_command, aiida_profile, top_dir):
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is not None,
reason="Test is not for MongoDB",
)
def test_calc_partially_init(run_cli_command, aiida_profile, top_dir, caplog):
def test_calc_partially_init(run_cli_command, aiida_profile_populated, top_dir, caplog):
"""Test `aiida-optimade -p profile_name calc` works for a partially initalized DB"""
from aiida import orm
from aiida.tools.archive.imports import import_archive
Expand All @@ -177,7 +177,7 @@ def test_calc_partially_init(run_cli_command, aiida_profile, top_dir, caplog):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear database and get initialized_structure_nodes.aiida
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
archive = top_dir.joinpath("tests/cli/static/initialized_structure_nodes.aiida")
import_archive(archive)

Expand Down Expand Up @@ -256,6 +256,6 @@ def test_calc_partially_init(run_cli_command, aiida_profile, top_dir, caplog):
), caplog.text

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
original_data = top_dir.joinpath("tests/static/test_structures.aiida")
import_archive(original_data)
26 changes: 14 additions & 12 deletions tests/cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is not None,
reason="Test is not for MongoDB",
)
def test_init_structuredata(run_cli_command, aiida_profile, top_dir, caplog):
def test_init_structuredata(run_cli_command, aiida_profile_populated, top_dir, caplog):
"""Test `aiida-optimade -p profile_name init` works for StructureData Nodes.

Also, check the `-f/--force` option.
Expand All @@ -23,7 +23,7 @@ def test_init_structuredata(run_cli_command, aiida_profile, top_dir, caplog):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear database
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()

archive = top_dir.joinpath("tests/cli/static/structure_data_nodes.aiida")
import_archive(archive)
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_init_structuredata(run_cli_command, aiida_profile, top_dir, caplog):
), caplog.text

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
original_data = top_dir.joinpath("tests/static/test_structures.aiida")
import_archive(original_data)

Expand All @@ -92,7 +92,7 @@ def test_init_structuredata(run_cli_command, aiida_profile, top_dir, caplog):
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is not None,
reason="Test is not for MongoDB",
)
def test_init_cifdata(run_cli_command, aiida_profile, top_dir, caplog):
def test_init_cifdata(run_cli_command, aiida_profile_populated, top_dir, caplog):
"""Test `aiida-optimade -p profile_name init` works for CifData Nodes."""
from aiida import orm
from aiida.tools.archive.imports import import_archive
Expand All @@ -101,7 +101,7 @@ def test_init_cifdata(run_cli_command, aiida_profile, top_dir, caplog):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear database
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()

archive = top_dir.joinpath("tests/cli/static/cif_data_nodes.aiida")
import_archive(archive)
Expand Down Expand Up @@ -137,15 +137,17 @@ def test_init_cifdata(run_cli_command, aiida_profile, top_dir, caplog):
), caplog.text

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
original_data = top_dir.joinpath("tests/static/test_structures.aiida")
import_archive(original_data)


@pytest.mark.skipif(
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is None, reason="Test is only for MongoDB"
)
def test_init_structuredata_mongo(run_cli_command, aiida_profile, top_dir, caplog):
def test_init_structuredata_mongo(
run_cli_command, aiida_profile_populated, top_dir, caplog
):
"""Test `aiida-optimade -p profile_name init --mongo` works for StructureData Nodes.

Also, check the `-f/--force` option.
Expand All @@ -159,7 +161,7 @@ def test_init_structuredata_mongo(run_cli_command, aiida_profile, top_dir, caplo
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear databases
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
STRUCTURES_MONGO.collection.drop()

archive = top_dir.joinpath("tests/cli/static/structure_data_nodes.aiida")
Expand Down Expand Up @@ -223,7 +225,7 @@ def test_init_structuredata_mongo(run_cli_command, aiida_profile, top_dir, caplo
), caplog.text

# Repopulate databases with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
import_archive(top_dir.joinpath("tests/static/test_structures.aiida"))
STRUCTURES_MONGO.collection.drop()
with open(top_dir.joinpath("tests/static/test_structures_mongo.json")) as handle:
Expand All @@ -234,7 +236,7 @@ def test_init_structuredata_mongo(run_cli_command, aiida_profile, top_dir, caplo
@pytest.mark.skipif(
os.getenv("PYTEST_OPTIMADE_CONFIG_FILE") is None, reason="Test is only for MongoDB"
)
def test_init_cifdata_mongo(run_cli_command, aiida_profile, top_dir, caplog):
def test_init_cifdata_mongo(run_cli_command, aiida_profile_populated, top_dir, caplog):
"""Test `aiida-optimade -p profile_name init` works for CifData Nodes."""
import bson.json_util
from aiida import orm
Expand All @@ -245,7 +247,7 @@ def test_init_cifdata_mongo(run_cli_command, aiida_profile, top_dir, caplog):
from aiida_optimade.translators.entities import AiidaEntityTranslator

# Clear databases
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
STRUCTURES_MONGO.collection.drop()

archive = top_dir.joinpath("tests/cli/static/cif_data_nodes.aiida")
Expand Down Expand Up @@ -284,7 +286,7 @@ def test_init_cifdata_mongo(run_cli_command, aiida_profile, top_dir, caplog):
), caplog.text

# Repopulate database with the "proper" test data
aiida_profile.reset_db()
aiida_profile_populated.clear_profile()
import_archive(top_dir.joinpath("tests/static/test_structures.aiida"))
STRUCTURES_MONGO.collection.drop()
with open(top_dir.joinpath("tests/static/test_structures_mongo.json")) as handle:
Expand Down
10 changes: 5 additions & 5 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@


@pytest.fixture
def run_server(aiida_test_profile: str):
def run_server(aiida_test_profile_name: str):
"""Run the server using `aiida-optimade run`

:param options: the list of command line options to pass to `aiida-optimade run`
invocation
:param raises: whether `aiida-optimade run` is expected to raise an exception
"""
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile)
profile = os.getenv("AIIDA_PROFILE", aiida_test_profile_name)
if profile == "test_profile":
# This is for local tests only
profile = aiida_test_profile
profile = aiida_test_profile_name

args = ["aiida-optimade", "-p", profile, "run"]
env = dict(os.environ)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_logging_precedence(run_and_terminate_server):
), f"output: {output!r}, errors: {errors!r}"


def test_env_var_is_set(run_and_terminate_server, aiida_test_profile: str):
def test_env_var_is_set(run_and_terminate_server, aiida_test_profile_name: str):
"""Test the AIIDA_PROFILE env var is set

The issue with this test, is that the set "AIIDA_PROFILE" environment variable
Expand All @@ -131,7 +131,7 @@ def test_env_var_is_set(run_and_terminate_server, aiida_test_profile: str):
assert fixture_profile is not None
if fixture_profile == "test_profile":
# This is for local tests only
fixture_profile = aiida_test_profile
fixture_profile = aiida_test_profile_name
output, errors = run_and_terminate_server(command="run")
assert fixture_profile in output, f"output: {output!r}, errors: {errors!r}"

Expand Down
Loading
Loading