def test_union(self): Number = c.union(c.Int, c.Float) self.assertEqual(1.0, Number(1.0)) self.assertEqual(2, Number(2)) with self.assertRaises(exceptions.PyCombValidationError) as e: Number('hello') e = e.exception self.assertEqual('Error on Union(Int, Float): expected Int or Float but was str', e.args[0])
def test_union_production(self): Number = c.union(c.Int, c.Float) self.assertEqual('hello', Number('hello', ctx=context.create(production_mode=True)))
def test_union_custom_error(self): observer = Mock() ctx = context.create(validation_error_observer=observer) Number = c.union(c.Int, c.Float) Number('hello', ctx=ctx) observer.on_error.assert_called_once_with(_ANY_CONTEXT, 'Int or Float', str)
}, strict=True) SplitSessionJoinValidator = validators.struct( { "client_alias": validators.String, }, strict=True) SplitSessionMasterEditValidator = validators.struct( { "client_alias": validators.String, "auth": validators.String, "session": SplitSessionValidator }, strict=True) SplitSessionEditValidator = validators.union(SplitSessionJoinValidator, SplitSessionMasterEditValidator) CombineSessionCreateValidator = validators.struct( { "client_alias": validators.String, "session_alias": validators.String, "session_type": validators.String, "session_id": validators.maybe(UUIDValidator), "session_policies": validators.struct({ "quorum": validators.Int, "shares": validators.Int