diff --git a/tests/conftest.py b/tests/conftest.py index 17b4992..ffb7ba2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -69,7 +69,7 @@ def factory(process_class, inputs=None, return_process=False): @pytest.fixture -def generate_calc_job_node(filepath_tests, aiida_computer_local): +def generate_calc_job_node(filepath_tests, aiida_computer_local, tmp_path): """Create and return a :class:`aiida.orm.CalcJobNode` instance.""" def flatten_inputs(inputs, prefix=''): @@ -82,7 +82,9 @@ def flatten_inputs(inputs, prefix=''): flat_inputs.append((prefix + key, value)) return flat_inputs - def factory(entry_point: str, test_name: str | None = None, inputs: dict = None): + def factory( + entry_point: str, test_name: str, inputs: dict = None, retrieve_temporary_list: list[str] | None = None + ): """Create and return a :class:`aiida.orm.CalcJobNode` instance.""" node = CalcJobNode(computer=aiida_computer_local(), process_type=f'aiida.calculations:{entry_point}') @@ -93,13 +95,20 @@ def factory(entry_point: str, test_name: str | None = None, inputs: dict = None) node.store() - if test_name: - filepath_retrieved = filepath_tests / 'parsers' / 'fixtures' / entry_point.split('.')[-1] / test_name + filepath_retrieved = filepath_tests / 'parsers' / 'fixtures' / entry_point.split('.')[-1] / test_name - retrieved = FolderData() - retrieved.base.repository.put_object_from_tree(filepath_retrieved) - retrieved.base.links.add_incoming(node, link_type=LinkType.CREATE, link_label='retrieved') - retrieved.store() + retrieved = FolderData() + retrieved.base.repository.put_object_from_tree(filepath_retrieved) + retrieved.base.links.add_incoming(node, link_type=LinkType.CREATE, link_label='retrieved') + retrieved.store() + + if retrieve_temporary_list: + for pattern in retrieve_temporary_list: + for filename in filepath_retrieved.glob(pattern): + filepath = tmp_path / filename.relative_to(filepath_retrieved) + filepath.write_bytes(filename.read_bytes()) + + return node, tmp_path return node @@ -144,7 +153,7 @@ def factory(inputs=None, exit_code=None): :param exit_code: exit code for the ``PyscfCalculation``. """ process = generate_workchain('pyscf.base', {'pyscf': inputs or generate_inputs_pyscf()}) - node = generate_calc_job_node('pyscf.base', inputs={'parameters': Dict()}) + node = generate_calc_job_node('pyscf.base', 'default', inputs={'parameters': Dict()}) process.ctx.iteration = 1 process.ctx.children = [node] diff --git a/tests/parsers/fixtures/base/cubegen/aiida.err b/tests/parsers/fixtures/base/cubegen/aiida.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/parsers/fixtures/base/cubegen/aiida.out b/tests/parsers/fixtures/base/cubegen/aiida.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/parsers/fixtures/base/cubegen/mo_5.cube b/tests/parsers/fixtures/base/cubegen/mo_5.cube new file mode 100644 index 0000000..03cc3ac --- /dev/null +++ b/tests/parsers/fixtures/base/cubegen/mo_5.cube @@ -0,0 +1 @@ +dummy fcidump file diff --git a/tests/parsers/fixtures/base/cubegen/results.json b/tests/parsers/fixtures/base/cubegen/results.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/parsers/fixtures/base/cubegen/results.json @@ -0,0 +1 @@ +{} diff --git a/tests/parsers/fixtures/base/fcidump/active_space_5_6_8_9.fcidump b/tests/parsers/fixtures/base/fcidump/active_space_5_6_8_9.fcidump new file mode 100644 index 0000000..03cc3ac --- /dev/null +++ b/tests/parsers/fixtures/base/fcidump/active_space_5_6_8_9.fcidump @@ -0,0 +1 @@ +dummy fcidump file diff --git a/tests/parsers/fixtures/base/fcidump/aiida.err b/tests/parsers/fixtures/base/fcidump/aiida.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/parsers/fixtures/base/fcidump/aiida.out b/tests/parsers/fixtures/base/fcidump/aiida.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/parsers/fixtures/base/fcidump/results.json b/tests/parsers/fixtures/base/fcidump/results.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/parsers/fixtures/base/fcidump/results.json @@ -0,0 +1 @@ +{} diff --git a/tests/parsers/test_base.py b/tests/parsers/test_base.py index 09ab0a4..4dbcfb1 100644 --- a/tests/parsers/test_base.py +++ b/tests/parsers/test_base.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """Tests for the :mod:`aiida_pyscf.parsers.base` module.""" # pylint: disable=redefined-outer-name +from aiida.orm import SinglefileData + from aiida_pyscf.calculations.base import PyscfCalculation @@ -36,3 +38,29 @@ def test_failed_missing_result(generate_calc_job_node, generate_parser): assert calcfunction.is_failed assert calcfunction.exit_status == PyscfCalculation.exit_codes.ERROR_OUTPUT_RESULTS_MISSING.status + + +def test_cubegen(generate_calc_job_node, generate_parser, generate_structure): + """Test parsing the outputs of a job that computed CUBE files.""" + inputs = {'structure': generate_structure('N2')} + node, tmp_path = generate_calc_job_node('pyscf.base', 'cubegen', inputs, retrieve_temporary_list=['*.cube']) + parser = generate_parser('pyscf.base') + results, calcfunction = parser.parse_from_node(node, retrieved_temporary_folder=tmp_path, store_provenance=False) + + assert calcfunction.is_finished, calcfunction.exception + assert calcfunction.is_finished_ok, calcfunction.exit_message + assert 'cubegen' in results + assert all(isinstance(node, SinglefileData) for node in results['cubegen'].values()) + + +def test_fcidump(generate_calc_job_node, generate_parser, generate_structure): + """Test parsing the outputs of a job that computed FCIDUMP files.""" + inputs = {'structure': generate_structure('N2')} + node, tmp_path = generate_calc_job_node('pyscf.base', 'fcidump', inputs, retrieve_temporary_list=['*.fcidump']) + parser = generate_parser('pyscf.base') + results, calcfunction = parser.parse_from_node(node, retrieved_temporary_folder=tmp_path, store_provenance=False) + + assert calcfunction.is_finished, calcfunction.exception + assert calcfunction.is_finished_ok, calcfunction.exit_message + assert 'fcidump' in results + assert all(isinstance(node, SinglefileData) for node in results['fcidump'].values())