From 2ca485ce95e671b83e1ec0ef958982d554df0c2c Mon Sep 17 00:00:00 2001 From: Julian Geiger Date: Mon, 27 May 2024 15:04:11 +0200 Subject: [PATCH 1/2] Capture `ImportTestRun` as dry-run success. --- src/aiida/cmdline/commands/cmd_archive.py | 9 +++++++++ tests/cmdline/commands/test_archive_import.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/aiida/cmdline/commands/cmd_archive.py b/src/aiida/cmdline/commands/cmd_archive.py index 4ed99bc883..2db9fbcd62 100644 --- a/src/aiida/cmdline/commands/cmd_archive.py +++ b/src/aiida/cmdline/commands/cmd_archive.py @@ -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 @@ -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) diff --git a/tests/cmdline/commands/test_archive_import.py b/tests/cmdline/commands/test_archive_import.py index 92b6690433..ed81b10c8c 100644 --- a/tests/cmdline/commands/test_archive_import.py +++ b/tests/cmdline/commands/test_archive_import.py @@ -49,6 +49,20 @@ 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']) + print(result.output) + 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. From 0e48f48a60bf4a01dc854aca2a9c58f3c6dff066 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 27 May 2024 17:52:14 +0200 Subject: [PATCH 2/2] Update tests/cmdline/commands/test_archive_import.py --- tests/cmdline/commands/test_archive_import.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cmdline/commands/test_archive_import.py b/tests/cmdline/commands/test_archive_import.py index ed81b10c8c..b644859c50 100644 --- a/tests/cmdline/commands/test_archive_import.py +++ b/tests/cmdline/commands/test_archive_import.py @@ -59,7 +59,6 @@ def test_import_archive(run_cli_command, newest_archive): def test_import_dry_run(run_cli_command, archive): """Test import dry-run""" result = run_cli_command(cmd_archive.import_archive, [archive, '--dry-run']) - print(result.output) assert f'import dry-run of archive {archive} completed' in result.output