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

Capture ImportTestRun as dry-run success #6403

Merged
merged 2 commits into from
May 27, 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
9 changes: 9 additions & 0 deletions src/aiida/cmdline/commands/cmd_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ def _import_archive_and_migrate(

from aiida.common.folders import SandboxFolder
from aiida.tools.archive.abstract import get_format
from aiida.tools.archive.exceptions import ImportTestRun
from aiida.tools.archive.imports import import_archive as _import_archive

archive_format = get_format()
filepath = ctx.obj['config'].get_option('storage.sandbox') or None
dry_run_success = f'import dry-run of archive {archive} completed. Profile storage unmodified.'

with SandboxFolder(filepath=filepath) as temp_folder:
archive_path = archive
Expand Down Expand Up @@ -515,12 +517,19 @@ def _import_archive_and_migrate(
echo.echo_report('proceeding with import of migrated archive')
try:
_import_archive(archive_path, archive_format=archive_format, **import_kwargs)
except ImportTestRun:
echo.echo_success(dry_run_success)
return
except Exception as sub_exception:
_echo_exception(
f'an exception occurred while trying to import the migrated archive {archive}', sub_exception
)
else:
_echo_exception(f'an exception occurred while trying to import the archive {archive}', exception)
except ImportTestRun:
echo.echo_success(dry_run_success)
return

except Exception as exception:
_echo_exception(f'an exception occurred while trying to import the archive {archive}', exception)

Expand Down
13 changes: 13 additions & 0 deletions tests/cmdline/commands/test_archive_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def test_import_archive(run_cli_command, newest_archive):
run_cli_command(cmd_archive.import_archive, options)


@pytest.mark.parametrize(
'archive',
(
get_archive_file('arithmetic.add.aiida', filepath='calcjob'),
get_archive_file('export_0.9_simple.aiida', filepath=ARCHIVE_PATH),
),
)
def test_import_dry_run(run_cli_command, archive):
"""Test import dry-run"""
result = run_cli_command(cmd_archive.import_archive, [archive, '--dry-run'])
assert f'import dry-run of archive {archive} completed' in result.output


def test_import_to_group(run_cli_command, newest_archive):
"""Test import to existing Group and that Nodes are added correctly for multiple imports of the same,
as well as separate, archives.
Expand Down
Loading