def test_logs_and_prefix(self):
        ctx = validation_context.Context()
        self.assertFalse(ctx.result().has_errors)

        ctx.error('hello %s', 'world')
        self.assertTrue(ctx.result().has_errors)

        with ctx.prefix('prefix %d ', 3):
            ctx.warning('warning %s', 2)

        with ctx.prefix('unicode %s', u'\xf0\x9f\x90\xb1 '):
            ctx.error('no cat')

        self.assertEqual(
            ctx.result(),
            validation_context.Result(messages=[
                validation_context.Message(severity=logging.ERROR,
                                           text='hello world'),
                validation_context.Message(severity=logging.WARNING,
                                           text='prefix 3 warning 2'),
                validation_context.Message(
                    severity=logging.ERROR,
                    text=u'unicode \xf0\x9f\x90\xb1 no cat'),
            ], ),
        )
示例#2
0
 def call_validate_delegation_config(r):
     ctx = validation_context.Context()
     conf = config_pb2.DelegationConfig(rules=[r])
     config.validate_delegation_config(conf, ctx)
     return [m.text for m in ctx.messages]