Skip to content

Commit 8c23bfb

Browse files
committed
Add minimal CLI tests for dumping feature
1 parent ec1df86 commit 8c23bfb

File tree

3 files changed

+89
-27
lines changed

3 files changed

+89
-27
lines changed

tests/cmdline/commands/test_group.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,34 @@ def test_copy_existing_group(self, run_cli_command):
595595
assert dest_group.count() == 2
596596
nodes_dest_group = {str(node.uuid) for node in dest_group.nodes}
597597
assert nodes_source_group == nodes_dest_group
598+
599+
def test_dump(self, run_cli_command, tmp_path, generate_calculation_node_add):
600+
"""Test verdi group dump"""
601+
from aiida import orm
602+
603+
# Create a group with some nodes
604+
group = orm.Group(label='test_dump_group').store()
605+
node = generate_calculation_node_add()
606+
group.add_nodes([node])
607+
608+
test_path = tmp_path / 'group-dump'
609+
610+
# Test dry run
611+
options = [group.label, '--path', str(test_path / 'dry'), '--dry-run']
612+
result = run_cli_command(cmd_group.group_dump, options)
613+
assert result.exception is None, result.output
614+
assert 'Dry run completed' in result.output
615+
assert not test_path.exists()
616+
617+
# Basic dump test
618+
options = [group.label, '--path', str(test_path)]
619+
result = run_cli_command(cmd_group.group_dump, options)
620+
assert result.exception is None, result.output
621+
assert 'Success:' in result.output
622+
assert test_path.exists()
623+
624+
# Test overwrite
625+
options = [group.label, '--path', str(test_path), '--overwrite']
626+
result = run_cli_command(cmd_group.group_dump, options)
627+
assert result.exception is None, result.output
628+
assert 'Success:' in result.output

tests/cmdline/commands/test_process.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -561,37 +561,32 @@ def test_report(self, run_cli_command):
561561
assert len(result.output_lines) == 1, result.output_lines
562562
assert result.output_lines[0] == 'No log messages recorded for this entry'
563563

564-
# def test_process_dump(self, run_cli_command, tmp_path, generate_workchain_multiply_add):
565-
# """Test verdi process dump"""
566564

567-
# # Only test CLI interface here, the actual functionalities of the Python API are tested in `test_processes.py`
568-
# test_path = tmp_path / 'cli-dump'
569-
# node = generate_workchain_multiply_add()
565+
def test_dump(self, run_cli_command, tmp_path, generate_calculation_node_add):
566+
"""Test verdi process dump"""
567+
# Only test CLI interface here, the actual functionalities of the Python API are tested elsewhere
568+
test_path = tmp_path / 'cli-dump'
569+
node = generate_calculation_node_add()
570570

571-
# # Giving a single identifier should print a non empty string message
572-
# options = [str(node.pk), '-p', str(test_path)]
573-
# result = run_cli_command(cmd_process.process_dump, options)
574-
# assert result.exception is None, result.output
575-
# assert 'Success:' in result.output
576-
577-
# # Trying to run the dumping again in the same path but with overwrite=False should raise exception
578-
# options = [str(node.pk), '-p', str(test_path), '--no-incremental']
579-
# result = run_cli_command(cmd_process.process_dump, options, raises=True)
580-
# assert result.exit_code is ExitCode.CRITICAL
581-
582-
# # Works fine when using overwrite=True
583-
# options = [str(node.pk), '-p', str(test_path), '-o', '--no-incremental']
584-
# result = run_cli_command(cmd_process.process_dump, options)
585-
# assert result.exception is None, result.output
586-
# assert 'Success:' in result.output
587-
588-
# # Set overwrite=True but provide bad directory, i.e. missing metadata file
589-
# (test_path / 'aiida_node_metadata.yaml').unlink()
571+
# Test dry run
572+
options = [str(node.pk), '--path', str(test_path / 'dry'), '--dry-run']
573+
result = run_cli_command(cmd_process.process_dump, options)
574+
assert result.exception is None, result.output
575+
assert 'Dry run completed' in result.output
576+
assert not test_path.exists()
590577

591-
# options = [str(node.pk), '-p', str(test_path), '-o']
592-
# result = run_cli_command(cmd_process.process_dump, options, raises=True)
593-
# assert result.exit_code is ExitCode.CRITICAL
578+
# Basic dump test
579+
options = [str(node.pk), '--path', str(test_path)]
580+
result = run_cli_command(cmd_process.process_dump, options)
581+
assert result.exception is None, result.output
582+
assert 'Success:' in result.output
583+
assert test_path.exists()
594584

585+
# Test overwrite
586+
options = [str(node.pk), '--path', str(test_path), '--overwrite']
587+
result = run_cli_command(cmd_process.process_dump, options)
588+
assert result.exception is None, result.output
589+
assert 'Success:' in result.output
595590

596591
@pytest.mark.usefixtures('aiida_profile_clean')
597592
@pytest.mark.parametrize('numprocesses, percentage', ((0, 100), (1, 90)))

tests/cmdline/commands/test_profile.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,39 @@ def test_configure_rabbitmq(run_cli_command, isolated_config):
334334
cli_result = run_cli_command(cmd_profile.profile_configure_rabbitmq, options, use_subprocess=False)
335335
assert 'Connected to RabbitMQ with the provided connection parameters' in cli_result.stdout
336336
assert profile.process_control_config['broker_port'] == 5672
337+
338+
def test_profile_dump(run_cli_command, tmp_path, generate_calculation_node_add):
339+
"""Test verdi profile dump"""
340+
from aiida import orm
341+
342+
# Create some data to dump
343+
group = orm.Group(label='test_profile_dump_group').store()
344+
node = generate_calculation_node_add()
345+
group.add_nodes([node])
346+
347+
test_path = tmp_path / 'profile-dump'
348+
349+
# Test dry run
350+
options = ['--path', str(test_path / 'dry'), '--all', '--dry-run']
351+
result = run_cli_command(cmd_profile.profile_dump, options)
352+
assert result.exception is None, result.output
353+
assert 'Dry run completed' in result.output
354+
355+
# Basic dump test with all entries
356+
options = ['--path', str(test_path), '--all']
357+
result = run_cli_command(cmd_profile.profile_dump, options)
358+
assert result.exception is None, result.output
359+
assert 'Success:' in result.output
360+
assert test_path.exists()
361+
362+
# Test group-specific dump
363+
options = ['--path', str(test_path / 'group'), '--groups', group.label]
364+
result = run_cli_command(cmd_profile.profile_dump, options)
365+
assert result.exception is None, result.output
366+
assert 'Success:' in result.output
367+
368+
# Test overwrite
369+
options = ['--path', str(test_path), '--all', '--overwrite']
370+
result = run_cli_command(cmd_profile.profile_dump, options)
371+
assert result.exception is None, result.output
372+
assert 'Success:' in result.output

0 commit comments

Comments
 (0)