def test_import_of_django_sqla_export_file(self): """Check that sqla import manages to import the django export file correctly""" from tests.utils.archives import import_archive for archive in ['django.aiida', 'sqlalchemy.aiida']: # Clean the database self.reset_database() # Import the needed data import_archive(archive, filepath='export/compare') # The expected metadata comp1_metadata = {'workdir': '/tmp/aiida'} # Check that we got the correct metadata # Make sure to exclude the default computer builder = orm.QueryBuilder() builder.append(orm.Computer, project=['metadata'], tag='comp', filters={'name': { '!==': self.computer.label }}) self.assertEqual(builder.count(), 1, 'Expected only one computer') res = builder.dict()[0] self.assertEqual(res['comp']['metadata'], comp1_metadata)
def test_calcjob_inoutputcat_old(self): """Test most recent process class / plug-in can be successfully used to find filenames""" # Import old archive of ArithmeticAddCalculation import_archive('calcjob/arithmetic.add_old.aiida') ArithmeticAddCalculation = CalculationFactory('arithmetic.add') calculations = orm.QueryBuilder().append( ArithmeticAddCalculation).all() for job in calculations: if job[0].uuid == self.arithmetic_job.uuid: continue add_job = job[0] return # Make sure add_job does not specify options 'input_filename' and 'output_filename' self.assertIsNone( add_job.get_option('input_filename'), msg="'input_filename' should not be an option for {}".format( add_job)) self.assertIsNone( add_job.get_option('output_filename'), msg="'output_filename' should not be an option for {}".format( add_job)) # Run `verdi calcjob inputcat add_job` options = [add_job.uuid] result = self.cli_runner.invoke(command.calcjob_inputcat, options) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 1) self.assertEqual(get_result_lines(result)[0], '2 3') # Run `verdi calcjob outputcat add_job` options = [add_job.uuid] result = self.cli_runner.invoke(command.calcjob_outputcat, options) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 1) self.assertEqual(get_result_lines(result)[0], '5')
def setUpClass(cls, *args, **kwargs): super().setUpClass(*args, **kwargs) from aiida.common.links import LinkType from aiida.engine import ProcessState cls.computer = orm.Computer(name='comp', hostname='localhost', transport_type='local', scheduler_type='direct', workdir='/tmp/aiida').store() cls.code = orm.Code(remote_computer_exec=(cls.computer, '/bin/true')).store() cls.group = orm.Group(label='test_group').store() cls.node = orm.Data().store() cls.calcs = [] user = orm.User.objects.get_default() authinfo = orm.AuthInfo(computer=cls.computer, user=user) authinfo.store() process_class = CalculationFactory('templatereplacer') process_type = get_entry_point_string_from_class( process_class.__module__, process_class.__name__) # Create 5 CalcJobNodes (one for each CalculationState) for calculation_state in CalcJobState: calc = orm.CalcJobNode(computer=cls.computer, process_type=process_type) calc.set_option('resources', { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }) calc.store() calc.set_process_state(ProcessState.RUNNING) cls.calcs.append(calc) if calculation_state == CalcJobState.PARSING: cls.KEY_ONE = 'key_one' cls.KEY_TWO = 'key_two' cls.VAL_ONE = 'val_one' cls.VAL_TWO = 'val_two' output_parameters = orm.Dict(dict={ cls.KEY_ONE: cls.VAL_ONE, cls.KEY_TWO: cls.VAL_TWO, }).store() output_parameters.add_incoming(calc, LinkType.CREATE, 'output_parameters') # Create shortcut for easy dereferencing cls.result_job = calc # Add a single calc to a group cls.group.add_nodes([calc]) # Create a single failed CalcJobNode cls.EXIT_STATUS = 100 calc = orm.CalcJobNode(computer=cls.computer) calc.set_option('resources', { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }) calc.store() calc.set_exit_status(cls.EXIT_STATUS) calc.set_process_state(ProcessState.FINISHED) cls.calcs.append(calc) # Load the fixture containing a single ArithmeticAddCalculation node import_archive('calcjob/arithmetic.add.aiida') # Get the imported ArithmeticAddCalculation node ArithmeticAddCalculation = CalculationFactory('arithmetic.add') calculations = orm.QueryBuilder().append( ArithmeticAddCalculation).all()[0] cls.arithmetic_job = calculations[0]