def test_work_show(self): """Test verdi process show""" workchain_one = WorkChainNode().store() workchain_two = WorkChainNode().store() workchains = [workchain_one, workchain_two] # Running without identifiers should not except and not print anything options = [] result = self.cli_runner.invoke(cmd_process.process_show, options) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 0) # Giving a single identifier should print a non empty string message options = [str(workchain_one.pk)] result = self.cli_runner.invoke(cmd_process.process_show, options) self.assertClickResultNoException(result) self.assertTrue(len(get_result_lines(result)) > 0) # Giving multiple identifiers should print a non empty string message options = [str(workchain.pk) for workchain in workchains] result = self.cli_runner.invoke(cmd_process.process_show, options) self.assertIsNone(result.exception, result.output) self.assertTrue(len(get_result_lines(result)) > 0)
def setUpClass(cls, *args, **kwargs): """ Create some code to test the CalculationParamType parameter type for the command line infrastructure We create an initial code with a random name and then on purpose create two code with a name that matches exactly the ID and UUID, respectively, of the first one. This allows us to test the rules implemented to solve ambiguities that arise when determing the identifier type """ super().setUpClass(*args, **kwargs) cls.param = CalculationParamType() cls.entity_01 = CalculationNode().store() cls.entity_02 = CalculationNode().store() cls.entity_03 = CalculationNode().store() cls.entity_04 = WorkFunctionNode() cls.entity_05 = CalcFunctionNode() cls.entity_06 = CalcJobNode() cls.entity_07 = WorkChainNode() cls.entity_01.label = 'calculation_01' cls.entity_02.label = str(cls.entity_01.pk) cls.entity_03.label = str(cls.entity_01.uuid)
def setUpClass(cls, *args, **kwargs): super().setUpClass(*args, **kwargs) from aiida.engine import ProcessState from aiida.orm.groups import Group cls.calcs = [] cls.process_label = 'SomeDummyWorkFunctionNode' # Create 6 WorkFunctionNodes and WorkChainNodes (one for each ProcessState) for state in ProcessState: calc = WorkFunctionNode() calc.set_process_state(state) # Set the WorkFunctionNode as successful if state == ProcessState.FINISHED: calc.set_exit_status(0) # Give a `process_label` to the `WorkFunctionNodes` so the `--process-label` option can be tested calc.set_attribute('process_label', cls.process_label) calc.store() cls.calcs.append(calc) calc = WorkChainNode() calc.set_process_state(state) # Set the WorkChainNode as failed if state == ProcessState.FINISHED: calc.set_exit_status(1) # Set the waiting work chain as paused as well if state == ProcessState.WAITING: calc.pause() calc.store() cls.calcs.append(calc) cls.group = Group('some_group').store() cls.group.add_nodes(cls.calcs[0])
def test_report(self): """Test the report command.""" grandparent = WorkChainNode().store() parent = WorkChainNode() child = WorkChainNode() parent.add_incoming(grandparent, link_type=LinkType.CALL_WORK, link_label='link') parent.store() child.add_incoming(parent, link_type=LinkType.CALL_WORK, link_label='link') child.store() grandparent.logger.log(LOG_LEVEL_REPORT, 'grandparent_message') parent.logger.log(LOG_LEVEL_REPORT, 'parent_message') child.logger.log(LOG_LEVEL_REPORT, 'child_message') result = self.cli_runner.invoke(cmd_process.process_report, [str(grandparent.pk)]) self.assertClickResultNoException(result) self.assertEqual(len(get_result_lines(result)), 3) result = self.cli_runner.invoke(cmd_process.process_report, [str(parent.pk)]) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 2) result = self.cli_runner.invoke(cmd_process.process_report, [str(child.pk)]) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 1) # Max depth should limit nesting level for flag in ['-m', '--max-depth']: for flag_value in [1, 2]: result = self.cli_runner.invoke( cmd_process.process_report, [str(grandparent.pk), flag, str(flag_value)] ) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), flag_value) # Filtering for other level name such as WARNING should not have any hits and only print the no log message for flag in ['-l', '--levelname']: result = self.cli_runner.invoke(cmd_process.process_report, [str(grandparent.pk), flag, 'WARNING']) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 1) self.assertEqual(get_result_lines(result)[0], 'No log messages recorded for this entry')
def test_process_show(self): """Test verdi process show""" workchain_one = WorkChainNode() workchain_two = WorkChainNode() workchains = [workchain_one, workchain_two] workchain_two.set_attribute('process_label', 'workchain_one_caller') workchain_two.store() workchain_one.add_incoming(workchain_two, link_type=LinkType.CALL_WORK, link_label='called') workchain_one.store() calcjob_one = CalcJobNode() calcjob_two = CalcJobNode() calcjob_one.set_attribute('process_label', 'process_label_one') calcjob_two.set_attribute('process_label', 'process_label_two') calcjob_one.add_incoming(workchain_one, link_type=LinkType.CALL_CALC, link_label='one') calcjob_two.add_incoming(workchain_one, link_type=LinkType.CALL_CALC, link_label='two') calcjob_one.store() calcjob_two.store() # Running without identifiers should not except and not print anything options = [] result = self.cli_runner.invoke(cmd_process.process_show, options) self.assertIsNone(result.exception, result.output) self.assertEqual(len(get_result_lines(result)), 0) # Giving a single identifier should print a non empty string message options = [str(workchain_one.pk)] result = self.cli_runner.invoke(cmd_process.process_show, options) lines = get_result_lines(result) self.assertClickResultNoException(result) self.assertTrue(len(lines) > 0) self.assertIn('workchain_one_caller', result.output) self.assertIn('process_label_one', lines[-2]) self.assertIn('process_label_two', lines[-1]) # Giving multiple identifiers should print a non empty string message options = [str(node.pk) for node in workchains] result = self.cli_runner.invoke(cmd_process.process_show, options) self.assertIsNone(result.exception, result.output) self.assertTrue(len(get_result_lines(result)) > 0)