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

Devops: Make use of the improved fixtures in aiida-core #171

Merged
merged 2 commits into from
Oct 29, 2024
Merged
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
8 changes: 0 additions & 8 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ jobs:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

services:
postgres:
image: postgres:12
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672

steps:
- uses: actions/checkout@v2

Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ jobs:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

services:
postgres:
image: postgres:12
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672

steps:
- uses: actions/checkout@v2

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
'Programming Language :: Python :: 3.12'
]
dependencies = [
'aiida-core~=2.1',
'aiida-core~=2.6',
'click~=8.0',
'pint~=0.23.0',
'requests~=2.20'
Expand Down Expand Up @@ -46,7 +46,6 @@ requires-python = '>=3.9'

[project.optional-dependencies]
dev = [
'pgtest~=1.3',
'pre-commit~=2.2',
'pytest>=6.0'
]
Expand Down
4 changes: 2 additions & 2 deletions src/aiida_pseudo/data/pseudo/pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
class PseudoPotentialDataCaching(NodeCaching):
"""Class to define caching behavior of ``PseudoPotentialData`` nodes."""

def get_objects_to_hash(self) -> list:
def get_objects_to_hash(self) -> dict[str, str]:
"""Return a list of objects which should be included in the node hash."""
return [self._node.element, self._node.md5]
return {'element': self._node.element, 'md5': self._node.md5}


class PseudoPotentialData(plugins.DataFactory('core.singlefile')):
Expand Down
20 changes: 11 additions & 9 deletions tests/cli/test_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from numpy.testing import assert_almost_equal


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_family_cutoffs_set(run_cli_command, get_pseudo_family, generate_cutoffs_dict, tmp_path):
"""Test the `aiida-pseudo family cutoffs set` command."""
family = get_pseudo_family(cls=CutoffsPseudoPotentialFamily)
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_family_cutoffs_set(run_cli_command, get_pseudo_family, generate_cutoffs
assert family.get_cutoffs(stringency) == cutoffs_dict['high']


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_family_cutoffs_set_unit(run_cli_command, get_pseudo_family, generate_cutoffs, tmp_path):
"""Test the `aiida-pseudo family cutoffs set` command with the ``--unit`` flag."""
family = get_pseudo_family(cls=CutoffsPseudoPotentialFamily)
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_family_cutoffs_set_unit(run_cli_command, get_pseudo_family, generate_cu
'family_cls,label',
[(SsspFamily, 'SSSP/1.1/PBE/efficiency'), (PseudoDojoFamily, 'PseudoDojo/0.4/PBE/SR/standard/psp8')],
)
@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_family_cutoffs_set_established(
run_cli_command, get_pseudo_family, generate_cutoffs, tmp_path, family_cls, label
):
Expand All @@ -117,7 +117,7 @@ def test_family_cutoffs_set_established(
assert f"Invalid value for 'FAMILY': The value `{family}` is not allowed for this parameter." in result.output


def test_family_show(clear_db, run_cli_command, get_pseudo_family):
def test_family_show(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `aiida-pseudo show` command."""
family = get_pseudo_family()
result = run_cli_command(cmd_family_show, [family.label])
Expand All @@ -127,7 +127,9 @@ def test_family_show(clear_db, run_cli_command, get_pseudo_family):
assert node.filename in result.output


def test_family_show_recommended_cutoffs(clear_db, run_cli_command, get_pseudo_family, generate_cutoffs_dict):
def test_family_show_recommended_cutoffs(
aiida_profile_clean, run_cli_command, get_pseudo_family, generate_cutoffs_dict
):
"""Test the `aiida-pseudo show` command for a family with recommended cutoffs."""
family = get_pseudo_family(cls=CutoffsPseudoPotentialFamily)
stringencies = ('normal', 'high')
Expand Down Expand Up @@ -157,7 +159,7 @@ def test_family_show_recommended_cutoffs(clear_db, run_cli_command, get_pseudo_f
assert_almost_equal(cutoffs[1], float(fields[4]))


def test_family_show_argument_type(clear_db, run_cli_command, get_pseudo_family):
def test_family_show_argument_type(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test that `aiida-pseudo show` only accepts instances of `PseudoPotentialFamily` or subclasses as argument."""
pseudo_family = get_pseudo_family(label='pseudo-family', cls=PseudoPotentialFamily)
normal_group = Group('normal-group').store()
Expand All @@ -166,7 +168,7 @@ def test_family_show_argument_type(clear_db, run_cli_command, get_pseudo_family)
run_cli_command(cmd_family_show, [normal_group.label], raises=SystemExit)


def test_family_show_raw(clear_db, run_cli_command, get_pseudo_family):
def test_family_show_raw(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `-r/--raw` option."""
family = get_pseudo_family()

Expand All @@ -175,7 +177,7 @@ def test_family_show_raw(clear_db, run_cli_command, get_pseudo_family):
assert len(result.output_lines) == len(family.nodes)


def test_family_show_unit_default(clear_db, run_cli_command, get_pseudo_family):
def test_family_show_unit_default(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `family show` command with default unit."""
elements = ['Ar', 'Kr']
cutoff_dict = {'normal': {'Ar': {'cutoff_wfc': 50, 'cutoff_rho': 200}, 'Kr': {'cutoff_wfc': 25, 'cutoff_rho': 100}}}
Expand All @@ -199,7 +201,7 @@ def test_family_show_unit_default(clear_db, run_cli_command, get_pseudo_family):


@pytest.mark.parametrize('unit', ['Ry', 'eV', 'hartree', 'aJ'])
def test_family_show_unit(clear_db, run_cli_command, get_pseudo_family, unit):
def test_family_show_unit(aiida_profile_clean, run_cli_command, get_pseudo_family, unit):
"""Test the `-u/--unit` option."""
elements = [
'Ar',
Expand Down
26 changes: 13 additions & 13 deletions tests/cli/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _run_monkeypatched_install_pseudo_dojo(options=None, raises=None):
return _run_monkeypatched_install_pseudo_dojo


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_family(run_cli_command, get_pseudo_archive):
"""Test ``aiida-pseudo install family``."""
label = 'family'
Expand All @@ -165,7 +165,7 @@ def test_install_family(run_cli_command, get_pseudo_archive):
assert len(family.pseudos) != 0


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_family_folder(run_cli_command, filepath_pseudos):
"""Test ``aiida-pseudo install family` from folder`."""
label = 'family_test'
Expand All @@ -183,7 +183,7 @@ def test_install_family_folder(run_cli_command, filepath_pseudos):
assert len(family.pseudos) != 0


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_family_url(run_cli_command, get_pseudo_archive, monkeypatch):
"""Test ``aiida-pseudo install family`` when installing from a URL.

Expand Down Expand Up @@ -222,7 +222,7 @@ def convert(*_, **__):
assert len(family.pseudos) != 0


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_sssp(run_cli_command):
"""Test the ``aiida-pseudo install sssp`` command."""
from aiida_pseudo import __version__
Expand All @@ -241,7 +241,7 @@ def test_install_sssp(run_cli_command):
assert 'is already installed' in result.output


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_pseudo_dojo(run_cli_command):
"""Test the ``aiida-pseudo install pseudo-dojo`` command."""
from aiida_pseudo import __version__
Expand All @@ -260,7 +260,7 @@ def test_install_pseudo_dojo(run_cli_command):
assert 'is already installed' in result.output


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_install_sssp_monkeypatched(run_monkeypatched_install_sssp):
"""Test the ``aiida-pseudo install sssp`` command with a monkeypatched download function.

Expand All @@ -283,7 +283,7 @@ def test_install_sssp_monkeypatched(run_monkeypatched_install_sssp):
assert family.label == label


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
@pytest.mark.filterwarnings('ignore:filename .* does not have a supported extension.:UserWarning')
def test_install_pseudo_dojo_monkeypatched(run_monkeypatched_install_pseudo_dojo):
"""Test the ``aiida-pseudo install pseudo-dojo`` command with a monkeypatched download function.
Expand All @@ -308,7 +308,7 @@ def test_install_pseudo_dojo_monkeypatched(run_monkeypatched_install_pseudo_dojo
assert family.label == label


@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_sssp_download_only(run_monkeypatched_install_sssp):
"""Test the ``aiida-pseudo install sssp`` command with the ``--download-only`` option.

Expand All @@ -328,7 +328,7 @@ def test_install_sssp_download_only(run_monkeypatched_install_sssp):
assert 'Success: Pseudopotential archive written to:' in result.output


@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_sssp_download_only_exists(run_monkeypatched_install_sssp, get_pseudo_family):
"""Test the ``aiida-pseudo install sssp`` command with the ``--download-only`` option.

Expand All @@ -350,7 +350,7 @@ def test_install_sssp_download_only_exists(run_monkeypatched_install_sssp, get_p


@pytest.mark.parametrize('configuration', SsspFamily.valid_configurations)
@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_sssp_from_download(run_monkeypatched_install_sssp, configuration):
"""Test the ``aiida-pseudo install sssp`` command with the ``--from-download`` option."""
options = [
Expand All @@ -373,7 +373,7 @@ def test_install_sssp_from_download(run_monkeypatched_install_sssp, configuratio
assert 'Success: installed `SSSP/' in result.output


@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_pseudo_dojo_download_only(run_monkeypatched_install_pseudo_dojo):
"""Test the ``aiida-pseudo install pseudo-dojo`` command with the ``--download-only`` option.

Expand All @@ -393,7 +393,7 @@ def test_install_pseudo_dojo_download_only(run_monkeypatched_install_pseudo_dojo
assert 'Success: Pseudopotential archive written to:' in result.output


@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_pseudo_dojo_download_only_exists(run_monkeypatched_install_pseudo_dojo, get_pseudo_family):
"""Test the ``aiida-pseudo install pseudo_dojo`` command with the ``--download-only`` option.

Expand Down Expand Up @@ -429,7 +429,7 @@ def test_install_pseudo_dojo_download_only_exists(run_monkeypatched_install_pseu
assert 'Success: Pseudopotential archive written to:' in result.output


@pytest.mark.usefixtures('clear_db', 'chdir_tmp_path')
@pytest.mark.usefixtures('aiida_profile_clean', 'chdir_tmp_path')
def test_install_pseudo_dojo_from_download(run_monkeypatched_install_pseudo_dojo):
"""Test the ``aiida-pseudo install pseudo-dojo`` command with the ``--from-download`` option."""
version = '1.0'
Expand Down
10 changes: 5 additions & 5 deletions tests/cli/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from aiida_pseudo.groups.family import PseudoPotentialFamily, SsspFamily


def test_list(clear_db, run_cli_command, get_pseudo_family):
def test_list(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `aiida-pseudo list` command."""
result = run_cli_command(cmd_list)
assert 'no pseudo potential families have been installed yet: use `aiida-pseudo install`.' in result.output
Expand All @@ -17,7 +17,7 @@ def test_list(clear_db, run_cli_command, get_pseudo_family):
assert family.label in result.output


def test_list_raw(clear_db, run_cli_command, get_pseudo_family):
def test_list_raw(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `-r/--raw` option."""
get_pseudo_family()

Expand All @@ -26,7 +26,7 @@ def test_list_raw(clear_db, run_cli_command, get_pseudo_family):
assert len(result.output_lines) == 1


def test_list_project(clear_db, run_cli_command, get_pseudo_family):
def test_list_project(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the `-p/--project` option."""
family = get_pseudo_family()

Expand All @@ -39,7 +39,7 @@ def test_list_project(clear_db, run_cli_command, get_pseudo_family):
assert family.label in result.output


def test_list_filter(clear_db, run_cli_command, get_pseudo_family):
def test_list_filter(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the filtering option `-F`."""
family_base = get_pseudo_family(label='Pseudo potential family', cls=PseudoPotentialFamily)
family_sssp = get_pseudo_family(label='SSSP/1.0/PBE/efficiency', cls=SsspFamily, pseudo_type=UpfData)
Expand All @@ -57,7 +57,7 @@ def test_list_filter(clear_db, run_cli_command, get_pseudo_family):
assert family_sssp.label in result.output


def test_list_filter_no_result(clear_db, run_cli_command, get_pseudo_family):
def test_list_filter_no_result(aiida_profile_clean, run_cli_command, get_pseudo_family):
"""Test the filtering option `-F` for a type for which no families exist."""
get_pseudo_family(label='Pseudo potential family', cls=PseudoPotentialFamily)

Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiida_pseudo.groups.family import PseudoPotentialFamily


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
@pytest.mark.parametrize(('fmt',), [(fmt[0],) for fmt in shutil.get_archive_formats()])
def test_create_family_from_archive(get_pseudo_archive, fmt):
"""Test the `create_family_from_archive` utility function."""
Expand All @@ -21,14 +21,14 @@ def test_create_family_from_archive(get_pseudo_archive, fmt):
assert family.count() != 0


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_create_family_from_archive_incorrect_filetype(tmp_path):
"""Test the `create_family_from_archive` utility function for incorrect archive filetype."""
with pytest.raises(OSError, match=r'failed to unpack the archive.*'):
create_family_from_archive(PseudoPotentialFamily, 'label', tmp_path)


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_create_family_from_archive_incorrect_format(tmp_path):
"""Test the `create_family_from_archive` utility function for invalid archive content."""
with tempfile.NamedTemporaryFile(suffix='.tar.gz') as filepath_archive:
Expand Down
8 changes: 1 addition & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
from aiida_pseudo.data.pseudo import PseudoPotentialData
from aiida_pseudo.groups.family import CutoffsPseudoPotentialFamily, PseudoPotentialFamily

pytest_plugins = ['aiida.manage.tests.pytest_fixtures']


@pytest.fixture
def clear_db(aiida_profile_clean):
"""Alias for the `aiida_profile_clean` fixture from `aiida-core`."""
yield
pytest_plugins = 'aiida.tools.pytest_fixtures'


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/data/pseudo/test_jthxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_constructor(filepath_pseudos):
assert pseudo.element == filepath.name.split('.')[0]


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_set_file(filepath_pseudos, get_pseudo_potential_data):
"""Test the `JthXmlData.set_file` method.

Expand Down
10 changes: 5 additions & 5 deletions tests/data/pseudo/test_pseudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_prepare_source(source):
assert PseudoPotentialData.prepare_source(source) is source


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_store():
"""Test the `PseudoPotentialData.store` method."""
stream = io.BytesIO(b'pseudo')
Expand All @@ -123,7 +123,7 @@ def test_store():
assert pseudo.is_stored


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_element():
"""Test the `PseudoPotentialData.element` property."""
element = 'Ar'
Expand All @@ -143,7 +143,7 @@ def test_element():
pseudo.element = element


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_md5():
"""Test the `PseudoPotentialData.md5` property."""
stream = io.BytesIO(b'pseudo')
Expand All @@ -163,7 +163,7 @@ def test_md5():
pseudo.md5 = md5


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_store_indirect():
"""Test the `PseudoPotentialData.store` method when called indirectly because its is an input."""
pseudo = PseudoPotentialData(io.BytesIO(b'pseudo'))
Expand All @@ -174,7 +174,7 @@ def test_store_indirect():
node.store_all()


@pytest.mark.usefixtures('clear_db')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_get_or_create(get_pseudo_potential_data):
"""Test the ``PseudoPotentialData.get_or_create`` classmethod."""
upf = get_pseudo_potential_data(entry_point='upf')
Expand Down
Loading
Loading