aiida_crystal17.tests package¶
Submodules¶
aiida_crystal17.tests.mock_crystal17 module¶
This is a mock version of runcry17.
It compares an input file to a hash, and writes an appropriate outputfile to stdoout
to create a hashkey:
import hashlib
input_path = 'path/to/input.d12'
with open(input_path, "rb") as f:
hashkey = hashlib.md5(f.read()).hexdigest()
hashkey
aiida_crystal17.tests.mock_properties17 module¶
This is a mock version of runcry17.
It compares an input file to a hash, and writes an appropriate outputfile to STDOUT
to create a hashkey:
import hashlib
input_path = 'path/to/input.d12'
with open(input_path, "rb") as f:
hashkey = hashlib.md5(f.read()).hexdigest()
hashkey
aiida_crystal17.tests.resources module¶
Retrieval of test resources.
-
aiida_crystal17.tests.resources.
get_test_structure
(name)[source]¶ Return an aiida.StructureData for testing.
-
aiida_crystal17.tests.resources.
get_test_structure_and_symm
(name, symprec=0.01, primitive=True)[source]¶ Return an aiida.StructureData and related aiida_crystal17.SymmetryData for testing.
SymmetryData is computed by the crystal17.sym3d WorkChain.
-
aiida_crystal17.tests.resources.
open_resource_binary
(*path)[source]¶ Return a file-like object opened for binary reading of the resource.
If the resource does not already exist on its own on the file system, a temporary file will be created. If the file was created, it will be deleted upon exiting the context manager (no exception is raised if the directory was deleted prior to the context manager exiting).
-
aiida_crystal17.tests.resources.
open_resource_text
(*path, **kwargs)[source]¶ Return a file-like object opened for text reading of the resource.
If the resource does not already exist on its own on the file system, a temporary file will be created. If the file was created, it will be deleted upon exiting the context manager (no exception is raised if the directory was deleted prior to the context manager exiting).
-
aiida_crystal17.tests.resources.
read_resource_binary
(*path)[source]¶ Return the binary contents of the resource.
-
aiida_crystal17.tests.resources.
read_resource_text
(*path, **kwargs)[source]¶ Return the decoded string of the resource.
The decoding-related arguments have the same semantics as those of bytes.decode().
-
aiida_crystal17.tests.resources.
resource_context
(*path, **kwargs)[source]¶ Provide a context manager that yields a pathlib.Path object to a resource file or directory.
If the resource does not already exist on its own on the file system, a temporary directory/file will be created. If the directory/file was created, it will be deleted upon exiting the context manager (no exception is raised if the directory was deleted prior to the context manager exiting).
aiida_crystal17.tests.utils module¶
-
class
aiida_crystal17.tests.utils.
AiidaTestApp
(work_directory, executable_map, environment=None)[source]¶ Bases:
object
a class providing methods for testing purposes
- Parameters
work_directory (str) – path to a local work directory (used when creating computers)
executable_map (dict) – mapping of computation entry points to the executable name
environment (None or aiida.manage.tests.TestManager) – manager of a temporary AiiDA environment
-
static
check_calculation
(calc_node, expected_outgoing_labels, error_include='results', 'errors', 'results', 'parser_errors')[source]¶ Check a calculation has completed successfully.
-
property
environment
¶ return manager of a temporary AiiDA environment
-
static
generate_calcinfo
(entry_point_name, folder, inputs=None)[source]¶ Generate a CalcInfo instance for testing calculation jobs.
A new CalcJob process instance is instantiated, and prepare_for_submission is called to populate the supplied folder, with raw inputs.
- Parameters
entry_point_name (str) –
folder (aiida.common.folders.Folder) –
-
generate_calcjob_node
(entry_point_name, retrieved=None, computer_name='localhost', options=None, mark_completed=False, remote_path=None, input_nodes=None)[source]¶ Fixture to generate a mock CalcJobNode for testing parsers.
- Parameters
entry_point_name (str) – entry point name of the calculation class
retrieved (aiida.orm.FolderData) – containing the file(s) to be parsed
computer_name (str) – used to get or create a
Computer
, by default ‘localhost’options (None or dict) – any additional metadata options to set on the node
remote_path (str) – path to a folder on the computer
mark_completed (bool) – if True, set the process state to finished, and the exit_status = 0
input_nodes (dict) – mapping of link label to node
- Returns
instance with the retrieved node linked as outgoing
- Return type
-
static
generate_context
(wkchain_cls, inputs, outline_steps)[source]¶ instantiate a WorkChain, call a list of methods (that should be part of spec.outline), then return a sanitized version of the workchain context for testing
-
static
get_calc_cls
(entry_point_name)[source]¶ load a data node class
- Parameters
entry_point_name (str) – entry point name of the data node class
-
static
get_data_node
(entry_point_name, **kwargs)[source]¶ load a data node instance
- Parameters
entry_point_name (str) – entry point name of the data node class
- Returns
- Return type
-
static
get_default_metadata
(max_num_machines=1, max_wallclock_seconds=1800, with_mpi=False, dry_run=False)[source]¶
-
get_or_create_code
(entry_point, computer_name='localhost')[source]¶ Setup code on localhost computer
-
static
parse_from_node
(entry_point_name, node, retrieved_temp=None)[source]¶ Parse the outputs directly from the CalcJobNode.
- Parameters
entry_point_name (str) – entry point name of the parser class
-
property
work_directory
¶ return path to the work directory
-
aiida_crystal17.tests.utils.
get_default_metadata
(max_num_machines=1, max_wallclock_seconds=1800, with_mpi=False, num_mpiprocs_per_machine=1, dry_run=False)[source]¶ Return an instance of the metadata dictionary with the minimally required parameters for a CalcJob and set to default values unless overridden
- Parameters
max_num_machines – set the number of nodes, default=1
max_wallclock_seconds – set the maximum number of wallclock seconds, default=1800
with_mpi – whether to run the calculation with MPI enabled
num_mpiprocs_per_machine – set the number of cpus per node, default=1
- Return type
-
aiida_crystal17.tests.utils.
get_or_create_code
(entry_point, computer, executable, exec_path=None)[source]¶ Setup code on localhost computer.
-
aiida_crystal17.tests.utils.
get_or_create_local_computer
(work_directory, name='localhost')[source]¶ Retrieve or setup a local computer.
- Parameters
- Returns
- Return type
-
aiida_crystal17.tests.utils.
get_path_to_executable
(executable)[source]¶ Get path to local executable.
-
aiida_crystal17.tests.utils.
parse_from_node
(cls, node, store_provenance=True, retrieved_temp=None)[source]¶ Parse the outputs directly from the CalcJobNode.
If store_provenance is set to False, a CalcFunctionNode will still be generated, but it will not be stored. It’s storing method will also be disabled, making it impossible to store, because storing it afterwards would not have the expected effect, as the outputs it produced will not be stored with it.
This method is useful to test parsing in unit tests where a CalcJobNode can be mocked without actually having to run a CalcJob. It can also be useful to actually re-perform the parsing of a completed CalcJob with a different parser.
- Parameters
node – a CalcJobNode instance
store_provenance – bool, if True will store the parsing as a CalcFunctionNode in the provenance
- Returns
a tuple of the parsed results and the CalcFunctionNode representing the process of parsing
Module contents¶
Tests for the plugin that does not pollute your profiles/databases.