def root_parser_created_handler(root_parser): lancamento_parser = root_parser.add_parser('lanc', aliases=['la'], help='Lançamento commands') subparsers = lancamento_parser.add_subparsers() controller.event('lancamento_parser_created', lancamento_parser=subparsers)
def test_parametrized_event_trigger(self): di_container.load_resources(['commons']) controller.load_listeners([__package__]) global _test_event_parameter _test_event_parameter = -1 controller.event('parametrized_event', parameter=41) self.assertEqual(_test_event_parameter, 41)
def test_event_triggered(self): di_container.load_resources_from_class(TestConfigurations) di_container.load_resources(['commons']) controller.load_listeners([__package__]) global _test_event_handled _test_event_handled = False controller.event('no_parameter_event') self.assertTrue(_test_event_handled)
def parse_command_line(self): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() controller.event('root_parser_created', root_parser=subparsers) args = parser.parse_args() if not hasattr(args, "event"): parser.print_help() parser.exit(0, "No arguments supplied\n") else: return args
def main(self): packages = [ 'commons', 'di_container', __package__ + '.commons', __package__ + '.conta', __package__ + '.database', __package__ + '.import', 'fdc.lancamento', 'fdc.produto', 'fdc.fornecedor', ] di_container.load_resources(packages) controller.load_listeners(packages) di_container.inject_resources(self) self._logger.info('Loaded resources and listeners from packages: {}', packages) self._logger.debug('Using configurations: {}', self._configs.dump()) args = self.parse_command_line() self._logger.info('Command line parsed: {}', args) event_results = controller.event(args.event, inject_dependencies=True, args=args) for result in event_results: self._logger.info( 'Calling front end for "{}" with data "{}, {}" due to status "{}"', args.event, result.kwdata, result.data, result.status) # inject_dependencies parameter put first event_args = True, *result.data controller.event(args.event + '_' + result.status, *event_args, **result.kwdata)
def test_event_which_return_data(self): di_container.load_resources(['commons']) controller.load_listeners([__package__]) results = controller.event('event_that_will_return_data') self.assertIsInstance(results, list) self.assertEqual(len(results), 1) result = results[0] self.assertEqual(result.status, 'status') self.assertEqual(result.data, ('first data', 'second data')) self.assertEqual(result.kwdata['property1'], 'key-value data 1 value') self.assertEqual( result.kwdata['property2'], 'software é como lingüiça: melhor não saber como é feito')
def root_parser_created_handler(self, root_parser): db_parser = root_parser.add_parser("db", help="Database commands") subparsers = db_parser.add_subparsers() controller.event('database_parser_created', db_parser=subparsers)
def root_parser_created_handler(self, root_parser): import_parser = root_parser.add_parser( "import", help="Import data from external source") subparsers = import_parser.add_subparsers() controller.event('import_parser_created', import_parser=subparsers)