def test_token_handler_setup_manual(self): stream = setup_logger(self, logger) definitions = {} unparser = BaseUnparser(definitions, token_handler_str_default) token_handler, layout_handlers, deferrable_handlers, prewalk_hooks = ( unparser.setup()) self.assertIs(token_handler, token_handler_str_default) self.assertIn( "DEBUG 'BaseUnparser' instance using manually specified " "token_handler 'token_handler_str_default'", stream.getvalue())
def test_token_handler_default(self): stream = setup_logger(self, logger) definitions = {} unparser = BaseUnparser(definitions) token_handler, layout_handlers, deferrable_handlers, prewalk_hooks = ( unparser.setup()) self.assertIs(token_handler, token_handler_str_default) self.assertIn( "DEBUG 'BaseUnparser' instance has no token_handler specified; " "default handler 'token_handler_str_default' activate", stream.getvalue())
def test_token_handler_setup_with_rules(self): def rule1(): def handler1(): "handler1" return {'token_handler': handler1} def rule2(): def handler2(): "handler2" return {'token_handler': handler2} def custom_handler(): "custom handler" stream = setup_logger(self, logger) definitions = {} unparser = BaseUnparser(definitions, rules=(rule1, rule2)) token_handler, layout_handlers, deferrable_handlers, prewalk_hooks = ( unparser.setup()) self.assertEqual(token_handler.__name__, 'handler2') self.assertIn( "DEBUG rule 'rule1' specified a token_handler 'handler1'", stream.getvalue()) self.assertIn( "WARNING rule 'rule2' specified a new token_handler 'handler2', " "overriding previously assigned token_handler 'handler1'", stream.getvalue()) unparser = BaseUnparser(definitions, token_handler=custom_handler, rules=(rule1, rule2)) token_handler, layout_handlers, deferrable_handlers, prewalk_hooks = ( unparser.setup()) self.assertIs(token_handler, custom_handler) self.assertIn( "INFO manually specified token_handler 'custom_handler' to the " "'BaseUnparser' instance will override rule derived token_handler " "'handler2'", stream.getvalue())