Skip to content

Commit

Permalink
Skip tests that runs pymatgen by default
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Jan 2, 2025
1 parent 02cbe0c commit 6050b5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
14 changes: 13 additions & 1 deletion tests/orm/nodes/data/test_jsonable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import datetime
import math

from aiida.orm.nodes.data.structure import has_pymatgen
import pytest
from pymatgen.core.structure import Molecule

from aiida.orm import load_node
from aiida.orm.nodes.data.jsonable import JsonableData
Expand Down Expand Up @@ -113,8 +113,14 @@ def test_obj():
assert left == right


skip_pymatgen_anyhow = pytest.mark.skipif(not has_pymatgen(), reason='Unable to import pymatgen')


@skip_pymatgen_anyhow
def test_unimportable_module():
"""Test the ``JsonableData.obj`` property if the associated module cannot be loaded."""
from pymatgen.core.structure import Molecule

obj = Molecule(['H'], [[0, 0, 0]])
node = JsonableData(obj)

Expand All @@ -128,8 +134,11 @@ def test_unimportable_module():
_ = loaded.obj


@skip_pymatgen_anyhow
def test_unimportable_class():
"""Test the ``JsonableData.obj`` property if the associated class cannot be loaded."""
from pymatgen.core.structure import Molecule

obj = Molecule(['H'], [[0, 0, 0]])
node = JsonableData(obj)

Expand All @@ -143,8 +152,11 @@ def test_unimportable_class():
_ = loaded.obj


@skip_pymatgen_anyhow
def test_msonable():
"""Test that an ``MSONAble`` object can be wrapped, stored and loaded again."""
from pymatgen.core.structure import Molecule

obj = Molecule(['H'], [[0, 0, 0]])
node = JsonableData(obj)
node.store()
Expand Down
40 changes: 20 additions & 20 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def simplify(string):
skip_spglib = pytest.mark.skipif(not has_spglib(), reason='Unable to import spglib')
skip_pycifrw = pytest.mark.skipif(not has_pycifrw(), reason='Unable to import PyCifRW')
skip_pymatgen = pytest.mark.skipif(not has_pymatgen(), reason='Unable to import pymatgen')
skip_pymatgen_anyhow = pytest.mark.skipif(True, reason='By all means')


@skip_pymatgen
@skip_pymatgen_anyhow
def test_get_pymatgen_version():
assert isinstance(get_pymatgen_version(), str)

Expand Down Expand Up @@ -211,6 +212,7 @@ def test_change_cifdata_file(self):

@skip_ase
@skip_pycifrw
@skip_pymatgen_anyhow
@pytest.mark.requires_rmq
def test_get_structure(self):
"""Test `CifData.get_structure`."""
Expand Down Expand Up @@ -291,7 +293,7 @@ def test_ase_primitive_and_conventional_cells_ase(self):

@skip_ase
@skip_pycifrw
@skip_pymatgen
@skip_pymatgen_anyhow
@pytest.mark.requires_rmq
def test_ase_primitive_and_conventional_cells_pymatgen(self):
"""Checking the number of atoms per primitive/conventional cell
Expand Down Expand Up @@ -2057,7 +2059,7 @@ class TestStructureDataFromPymatgen:
Molecule objects.
"""

@skip_pymatgen
@skip_pymatgen_anyhow
def test_1(self):
"""Tests roundtrip pymatgen -> StructureData -> pymatgen
Test's input is derived from COD entry 9011963, processed with
Expand Down Expand Up @@ -2158,7 +2160,7 @@ def recursively_compare_values(left, right):

recursively_compare_values(dict1, dict2)

@skip_pymatgen
@skip_pymatgen_anyhow
def test_2(self):
"""Tests xyz -> pymatgen -> StructureData
Input source: http://pymatgen.org/_static/Molecule.html
Expand Down Expand Up @@ -2188,7 +2190,7 @@ def test_2(self):
assert [round(x, 2) for x in list(struct.sites[3].position)] == [5.26, 6.78, 5.36]
assert [round(x, 2) for x in list(struct.sites[4].position)] == [5.77, 5.89, 5.73]

@skip_pymatgen
@skip_pymatgen_anyhow
def test_partial_occ_and_spin(self):
"""Tests pymatgen -> StructureData, with partial occupancies and spins.
This should raise a ValueError.
Expand Down Expand Up @@ -2226,9 +2228,8 @@ def test_partial_occ_and_spin(self):
with pytest.raises(ValueError):
StructureData(pymatgen=a)

@skip_pymatgen
@staticmethod
def test_multiple_kinds_partial_occupancies():
@skip_pymatgen_anyhow
def test_multiple_kinds_partial_occupancies(self):
"""Tests that a structure with multiple sites with the same element but different
partial occupancies, get their own unique kind name.
"""
Expand All @@ -2244,9 +2245,8 @@ def test_multiple_kinds_partial_occupancies():

StructureData(pymatgen=a)

@skip_pymatgen
@staticmethod
def test_multiple_kinds_alloy():
@skip_pymatgen_anyhow
def test_multiple_kinds_alloy(self):
"""Tests that a structure with multiple sites with the same alloy symbols but different
weights, get their own unique kind name
"""
Expand All @@ -2270,7 +2270,7 @@ class TestPymatgenFromStructureData:
StructureData.
"""

@skip_pymatgen
@skip_pymatgen_anyhow
@pytest.mark.parametrize(
'pbc', ((True, True, True), (True, True, False), (True, False, False), (False, False, False))
)
Expand All @@ -2289,7 +2289,7 @@ def test_get_pymatgen_structure_pbc(self, pbc):
assert pymatgen.lattice.pbc == pbc
assert pymatgen.lattice.matrix.tolist() == cell

@skip_pymatgen
@skip_pymatgen_anyhow
def test_no_pbc(self):
"""Tests the `get_pymatgen*` methods for a 0D system, i.e. no periodic boundary conditions.
Expand All @@ -2310,7 +2310,7 @@ def test_no_pbc(self):
structure.get_pymatgen_structure()

@skip_ase
@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_ase_aiida_pymatgen_structure(self):
"""Tests ASE -> StructureData -> pymatgen."""
import ase
Expand All @@ -2336,7 +2336,7 @@ def test_roundtrip_ase_aiida_pymatgen_structure(self):
assert coord_array == [[0.0, 0.0, 0.0], [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.3, 0.3, 0.3]]

@skip_ase
@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_ase_aiida_pymatgen_molecule(self):
"""Tests the conversion of StructureData to pymatgen's Molecule
(ASE -> StructureData -> pymatgen)
Expand Down Expand Up @@ -2364,7 +2364,7 @@ def test_roundtrip_ase_aiida_pymatgen_molecule(self):
[3.0, 3.0, 3.0],
]

@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_aiida_pymatgen_aiida(self):
"""Tests roundtrip StructureData -> pymatgen -> StructureData
(no spins)
Expand Down Expand Up @@ -2394,7 +2394,7 @@ def test_roundtrip_aiida_pymatgen_aiida(self):
(0, 0, 2.8),
]

@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_kindnames(self):
"""Tests roundtrip StructureData -> pymatgen -> StructureData
(no spins, but with all kind of kind names)
Expand Down Expand Up @@ -2435,7 +2435,7 @@ def test_roundtrip_kindnames(self):
(0, 0, 2.8),
]

@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_spins(self):
"""Tests roundtrip StructureData -> pymatgen -> StructureData
(with spins)
Expand Down Expand Up @@ -2471,7 +2471,7 @@ def test_roundtrip_spins(self):
(0, 0, 2.8),
]

@skip_pymatgen
@skip_pymatgen_anyhow
def test_roundtrip_partial_occ(self):
"""Tests roundtrip StructureData -> pymatgen -> StructureData
(with partial occupancies).
Expand Down Expand Up @@ -2538,7 +2538,7 @@ def test_roundtrip_partial_occ(self):
],
)

@skip_pymatgen
@skip_pymatgen_anyhow
def test_partial_occ_and_spin(self):
"""Tests StructureData -> pymatgen, with partial occupancies and spins.
This should raise a ValueError.
Expand Down

0 comments on commit 6050b5a

Please sign in to comment.