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)