Skip to content

Commit

Permalink
Devops: Address internal deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Feb 13, 2024
1 parent 97e9f30 commit 3fc0dfa
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 87 deletions.
2 changes: 1 addition & 1 deletion docs/source/topics/processes/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ They can be accessed through the corresponding properties on the process node as
:code: python

The source code of the file in which the function is defined is also stored, but since it can be quite big, it is stored as a raw file in the repository of the process node.
It can be retrieved through the :py:meth:`~aiida.orm.utils.mixins.FunctionCalculationMixin.get_function_source_code` method.
It can be retrieved through the :py:meth:`~aiida.orm.utils.mixins.FunctionCalculationMixin.get_source_code_file` method.

The attributes give some querability to the process functions stored in the provenance graph and by storing the source code of the function that was executed, there will be some reference in the future to track how the function created its output nodes.
Note, however, that just storing the source file of the function does not guarantee that one can reproduce the exact result.
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,11 @@ filterwarnings = [
'ignore::DeprecationWarning:pymatgen:',
'ignore::DeprecationWarning:jsonbackend:',
'ignore::DeprecationWarning:pkg_resources:',
'ignore:Object of type .* not in session, .* operation along .* will not proceed:sqlalchemy.exc.SAWarning',
'ignore::pytest.PytestCollectionWarning',
'ignore:Creating AiiDA configuration folder.*:UserWarning',
'ignore:Object of type .* not in session, .* operation along .* will not proceed:sqlalchemy.exc.SAWarning',
'ignore:The `aiida.orm.nodes.data.upf` module is deprecated.*:aiida.common.warnings.AiidaDeprecationWarning',
'ignore:The `Code` class is deprecated.*:aiida.common.warnings.AiidaDeprecationWarning',
'default::ResourceWarning'
]
markers = [
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/engine/processes/calcjobs/calcjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def run(self) -> Union[plumpy.process_states.Stop, int, plumpy.process_states.Wa
# this case, the parser will not be called. The outputs will already have been added to the process node
# though, so all that needs to be done here is just also assign them to the process instance. This such that
# when the process returns its results, it returns the actual outputs and not an empty dictionary.
self._outputs = self.node.get_outgoing(link_type=LinkType.CREATE).nested()
self._outputs = self.node.base.links.get_outgoing(link_type=LinkType.CREATE).nested()
return self.node.exit_status

# Launch the upload operation
Expand Down
15 changes: 8 additions & 7 deletions src/aiida/storage/sqlite_zip/migrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ def copy_tar_to_zip(
temp_extracted = Path(tmpdirname) / 'extracted'
with get_progress_reporter()(total=1) as progress:
callback = create_callback(progress)
TarPath(inpath, mode='r:*').extract_tree(
temp_extracted,
allow_dev=False,
allow_symlink=False,
callback=callback,
cb_descript=f'{title} (extracting tar)',
)
with TarPath(inpath, mode='r:*') as path:
path.extract_tree(
temp_extracted,
allow_dev=False,
allow_symlink=False,
callback=callback,
cb_descript=f'{title} (extracting tar)',
)
temp_archive = Path(tmpdirname) / 'archive.zip'
with ZipPath(temp_archive, mode='w', compresslevel=compression, info_order=info_order) as new_path:
length = sum(1 for _ in temp_extracted.glob('**/*'))
Expand Down
8 changes: 8 additions & 0 deletions src/aiida/transports/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def close(self):
break
time.sleep(0.2)

for f in [self.process.stdout, self.process.stderr, self.process.stdin]:
if f is None:
continue
try:
f.close()
except ValueError:
pass


def copy_from_remote_to_remote(transportsource, transportdestination, remotesource, remotedestination, **kwargs):
"""Copy files or folders from a remote computer to another remote computer.
Expand Down
13 changes: 8 additions & 5 deletions tests/cmdline/commands/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gzip
import io
import os
import warnings

import pytest
from aiida import orm
Expand Down Expand Up @@ -401,11 +402,13 @@ def test_node_id_label_format(self, run_cli_command):
@pytest.mark.parametrize('output_file', ('without_extension', 'without_extension.pdf'))
def test_output_file(self, run_cli_command, output_file):
"""Test that the output file can be specified through an argument."""
try:
run_cli_command(cmd_node.graph_generate, [str(self.node.pk), output_file])
assert os.path.isfile(output_file)
finally:
delete_temporary_file(output_file)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
try:
run_cli_command(cmd_node.graph_generate, [str(self.node.pk), output_file])
assert os.path.isfile(output_file)
finally:
delete_temporary_file(output_file)


COMMENT = 'Well I never...'
Expand Down
50 changes: 26 additions & 24 deletions tests/cmdline/params/options/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
###########################################################################
"""Unit tests for the :class:`aiida.cmdline.params.options.config.ConfigOption`."""
import functools
import tempfile
import textwrap

import click
Expand All @@ -32,37 +31,40 @@ def cmd(integer, boolean):
click.echo(f'Boolean: {boolean}')


def test_valid(run_cli_command):
def test_valid(run_cli_command, tmp_path):
"""Test the option for a valid configuration file."""
with tempfile.NamedTemporaryFile('w+') as handle:
handle.write(
textwrap.dedent(
"""
filepath = tmp_path / 'config.yml'
filepath.write_text(
textwrap.dedent(
"""
integer: 1
boolean: false
"""
)
"""
)
handle.flush()
)

result = run_cli_command(cmd, ['--config', handle.name])
assert 'Integer: 1' in result.output_lines[0]
assert 'Boolean: False' in result.output_lines[1]
result = run_cli_command(cmd, ['--config', str(filepath)])
assert 'Integer: 1' in result.output_lines[0]
assert 'Boolean: False' in result.output_lines[1]


def test_invalid_unknown_keys(run_cli_command):
"""Test the option for an invalid configuration file containing unknown keys."""
with tempfile.NamedTemporaryFile('w+') as handle:
handle.write(
textwrap.dedent(
"""
@pytest.mark.filterwarnings('ignore')
def test_invalid_unknown_keys(run_cli_command, tmp_path):
"""Test the option for an invalid configuration file containing unknown keys.
The test emits a ``ResourceWarning`` because the config file is not closed since the command errors, but this is
just a side-effect of how the test is run and doesn't apply to the real CLI command invocation.
"""
filepath = tmp_path / 'config.yml'
filepath.write_text(
textwrap.dedent(
"""
integer: 1
unknown: 2.0
"""
)
"""
)
handle.flush()
)

result = run_cli_command(cmd, ['--config', handle.name], raises=True)
assert "Error: Invalid value for '--config': Invalid configuration file" in result.stderr
assert "the following keys are not supported: {'unknown'}" in result.stderr
result = run_cli_command(cmd, ['--config', str(filepath)], raises=True)
assert "Error: Invalid value for '--config': Invalid configuration file" in result.stderr
assert "the following keys are not supported: {'unknown'}" in result.stderr
1 change: 0 additions & 1 deletion tests/cmdline/params/options/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def test_default_value_prompt(run_cli_command):
returns.append(result)
expected = 'Opt [default]: TEST\nTEST\n'
assert expected in result.output
return returns


def test_default_value_empty_opt(run_cli_command):
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/processes/calcjobs/test_calc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_get_hash(self, get_calcjob_builder):
"""Test that :meth:`aiida.orm.CalcJobNode.get_hash` returns the same hash as what is stored in the extras."""
builder = get_calcjob_builder()
_, node = launch.run_get_node(builder)
assert node.base.extras.get(node.base.caching._HASH_EXTRA_KEY) == node.get_hash()
assert node.base.extras.get(node.base.caching._HASH_EXTRA_KEY) == node.base.caching.get_hash()

def test_process_status(self):
"""Test that the process status is properly reset if calculation ends successfully."""
Expand Down
6 changes: 5 additions & 1 deletion tests/engine/processes/workchains/test_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for `aiida.engine.processes.workchains.restart` module."""
import warnings

import pytest
from aiida import engine, orm
from aiida.engine.processes.workchains.awaitable import Awaitable
Expand Down Expand Up @@ -66,7 +68,9 @@ def test_get_process_handlers():
)
def test_get_process_handlers_by_priority(generate_work_chain, inputs, priorities):
"""Test the `BaseRestartWorkChain.get_process_handlers_by_priority` method."""
process = generate_work_chain(SomeWorkChain, inputs)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
process = generate_work_chain(SomeWorkChain, inputs)
process.setup()
assert sorted([priority for priority, handler in process.get_process_handlers_by_priority()]) == priorities

Expand Down
2 changes: 1 addition & 1 deletion tests/engine/test_calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_calcfunction_caching_change_code(self):
result_cached, cached = add_calcfunction.run_get_node(self.default_int)
assert result_original != result_cached
assert not cached.base.caching.is_created_from_cache
assert cached.is_valid_cache
assert cached.base.caching.is_valid_cache

# Test that the locally-created calcfunction can be cached in principle
result2_cached, cached2 = add_calcfunction.run_get_node(self.default_int)
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def define(cls, spec):
spec.input('any_type', required=False)


@pytest.mark.usefixtures('clear_database_before_test')
@pytest.mark.usefixtures('aiida_profile_clean')
def test_not_required_accepts_none():
"""Test that a port that is not required, accepts ``None``."""
from aiida.engine.utils import instantiate_process
Expand Down
12 changes: 6 additions & 6 deletions tests/engine/test_process_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_process_function(data):
_, node = test_process_function.run_get_node(data=orm.Int(5))

# Read the source file of the calculation function that should be stored in the repository
function_source_code = node.get_function_source_code().split('\n')
function_source_code = node.get_source_code_file().split('\n')

# Verify that the function name is correct and the first source code linenumber is stored
assert node.function_name == function_name
Expand All @@ -214,8 +214,8 @@ def test_process_function(data):
assert node.function_name in function_name_from_source


def test_get_function_source_code():
"""Test that ``get_function_source_code`` returns ``None`` if no source code was stored.
def test_get_source_code_file():
"""Test that ``get_source_code_file`` returns ``None`` if no source code was stored.
This is the case for example for functions defined in an interactive shell, where the retrieval of the source code
upon storing the node fails and nothing is stored. The function should not except in this case.
Expand All @@ -227,7 +227,7 @@ def test_get_function_source_code():
# Delete the source file by going down to the ``RepositoryBackend`` to circumvent the immutability check.
node.base.repository._repository.delete_object(FunctionCalculationMixin.FUNCTION_SOURCE_FILE_PATH)

assert node.get_function_source_code() is None
assert node.get_source_code_file() is None


def test_function_varargs():
Expand All @@ -236,7 +236,7 @@ def test_function_varargs():
assert isinstance(result, orm.Str)
assert result.value == 'a b c d'

inputs = node.get_incoming().nested()
inputs = node.base.links.get_incoming().nested()
assert inputs['str_a'].value == 'a'
assert inputs['str_b'].value == 'b'
assert inputs['args_0'].value == 'c'
Expand Down Expand Up @@ -648,7 +648,7 @@ def function(**kwargs):
}
results, node = function.run_get_node(**inputs)
assert results == inputs
assert node.get_incoming().nested() == inputs
assert node.base.links.get_incoming().nested() == inputs

inputs = {
'nested': {
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_run_return_value_cached(aiida_local_code_factory):
'y': Int(-2),
}
results_source, node_source = launch.run_get_node(ArithmeticAddCalculation, **inputs)
assert node_source.is_valid_cache
assert node_source.base.caching.is_valid_cache

with enable_caching():
results_cached, node_cached = launch.run_get_node(ArithmeticAddCalculation, **inputs)
Expand Down
34 changes: 16 additions & 18 deletions tests/manage/test_caching_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for the functionality that reads and modifies the caching configuration file."""


import contextlib
import json
from pathlib import Path
import pathlib

import pytest
import yaml
Expand Down Expand Up @@ -60,7 +58,7 @@ def test_merge_deprecated_yaml(tmp_path):
# Create a temporary folder, set it as the current config directory path
settings.AIIDA_CONFIG_FOLDER = str(tmp_path)
config_dictionary = json.loads(
Path(__file__)
pathlib.Path(__file__)
.parent.joinpath('configuration/migrations/test_samples/reference/6.json')
.read_text(encoding='utf-8')
)
Expand Down Expand Up @@ -146,53 +144,53 @@ def test_default(configure_caching):
(
{
'default_enabled': True,
'enabled_for': ['aiida.calculations:arithmetic.add'],
'enabled_for': ['aiida.calculations:core.arithmetic.add'],
'disabled_for': ['aiida.calculations:core.templatereplacer'],
},
['some_identifier', 'aiida.calculations:arithmetic.add', 'aiida.calculations:TEMPLATEREPLACER'],
['some_identifier', 'aiida.calculations:core.arithmetic.add', 'aiida.calculations:TEMPLATEREPLACER'],
['aiida.calculations:core.templatereplacer'],
),
(
{
'default_enabled': False,
'enabled_for': ['aiida.calculations:arithmetic.add'],
'enabled_for': ['aiida.calculations:core.arithmetic.add'],
'disabled_for': ['aiida.calculations:core.templatereplacer'],
},
['aiida.calculations:arithmetic.add'],
['aiida.calculations:core.arithmetic.add'],
['aiida.calculations:core.templatereplacer', 'some_identifier'],
),
(
{
'default_enabled': False,
'enabled_for': ['aiida.calculations:*'],
},
['aiida.calculations:core.templatereplacer', 'aiida.calculations:arithmetic.add'],
['aiida.calculations:core.templatereplacer', 'aiida.calculations:core.arithmetic.add'],
['some_identifier'],
),
(
{
'default_enabled': False,
'enabled_for': ['aiida.calcul*'],
},
['aiida.calculations:core.templatereplacer', 'aiida.calculations:arithmetic.add'],
['aiida.calculations:core.templatereplacer', 'aiida.calculations:core.arithmetic.add'],
['some_identifier'],
),
(
{
'default_enabled': False,
'enabled_for': ['aiida.calculations:*'],
'disabled_for': ['aiida.calculations:arithmetic.add'],
'disabled_for': ['aiida.calculations:core.arithmetic.add'],
},
['aiida.calculations:core.templatereplacer', 'aiida.calculations:ARIthmetic.add'],
['some_identifier', 'aiida.calculations:arithmetic.add'],
['aiida.calculations:core.templatereplacer', 'aiida.calculations:core.ARIthmetic.add'],
['some_identifier', 'aiida.calculations:core.arithmetic.add'],
),
(
{
'default_enabled': False,
'enabled_for': ['aiida.calculations:ar*thmetic.add'],
'enabled_for': ['aiida.calculations:core.ar*thmetic.add'],
'disabled_for': ['aiida.calculations:*'],
},
['aiida.calculations:arithmetic.add', 'aiida.calculations:arblarghthmetic.add'],
['aiida.calculations:core.arithmetic.add', 'aiida.calculations:core.arblarghthmetic.add'],
['some_identifier', 'aiida.calculations:core.templatereplacer'],
),
],
Expand Down Expand Up @@ -221,11 +219,11 @@ def test_configuration(configure_caching, config_dict, enabled_for, disabled_for
(
{
'default_enabled': False,
'enabled_for': ['aiida.calculations:arithmetic.add'],
'disabled_for': ['aiida.calculations:arithmetic.add'],
'enabled_for': ['aiida.calculations:core.arithmetic.add'],
'disabled_for': ['aiida.calculations:core.arithmetic.add'],
},
['some_identifier', 'aiida.calculations:core.templatereplacer'],
['aiida.calculations:arithmetic.add'],
['aiida.calculations:core.arithmetic.add'],
),
],
)
Expand Down
4 changes: 3 additions & 1 deletion tests/orm/data/code/test_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pytest
from aiida.common.exceptions import ModificationNotAllowed, ValidationError
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.orm import Computer
from aiida.orm.nodes.data.code.installed import InstalledCode

Expand Down Expand Up @@ -128,4 +129,5 @@ def test_full_label(aiida_localhost):
def test_get_execname(aiida_localhost):
"""Test the deprecated :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.get_execname` method."""
code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable='/usr/bin/bash')
assert code.get_execname() == '/usr/bin/bash'
with pytest.warns(AiidaDeprecationWarning):
assert code.get_execname() == '/usr/bin/bash'
Loading

0 comments on commit 3fc0dfa

Please sign in to comment.