Example #1
0
    def test_validate_okay(self):
        self.handler.returns.coerce = 'eggs'
        arg = Arg(self.param, 'spam', self.handler)
        arg.validate()

        self.assertEqual(self.stub.calls, [
            ('coerce', ('spam',), {}),
            ('validate', ('eggs',), {}),
        ])
Example #2
0
    def test_validate_use_coerced(self):
        handler = FakeHandler()
        other = Arg(Parameter(str, handler), 'spam', handler, israw=False)
        arg = Arg(Parameter(str, self.handler), other, self.handler,
                  israw=False)
        arg.validate()

        self.assertEqual(self.stub.calls, [])
        self.assertEqual(handler.stub.calls, [
            ('validate', ('spam',), {}),
        ])
Example #3
0
    def test_validate_invalid(self):
        self.stub.set_exceptions(
            None,
            ValueError('oops'),
        )
        self.handler.returns.coerce = 'eggs'
        arg = Arg(self.param, 'spam', self.handler)

        with self.assertRaises(ValueError):
            arg.validate()
        self.assertEqual(self.stub.calls, [
            ('coerce', ('spam',), {}),
            ('validate', ('eggs',), {}),
        ])