def test_success_filter_map(self): """ Applying a :py:class:`f.FilterMap` to the values in a namedtuple after converting (success case). """ self.filter_type = lambda: f.NamedTuple( Color, { # For whatever reason, we decide not to filter ``r``. 'g': f.Required | f.Int | f.Min(0) | f.Max(255), 'b': f.Required | f.Int | f.Min(0) | f.Max(255), }) self.assertFilterPasses( ('64.0', '128', 192.0), Color('64.0', 128, 192), )
def test_fail_filter_map(self): """ Applying a :py:class:`f.FilterMap` to the values in a namedtuple after converting (failure case). """ self.filter_type = lambda: f.NamedTuple( Color, { # For whatever reason, we decide not to filter ``r``. 'g': f.Required | f.Int | f.Min(0) | f.Max(255), 'b': f.Required | f.Int | f.Min(0) | f.Max(255), }) self.assertFilterErrors( ['NaN', None, (42, )], { 'g': [f.Required.CODE_EMPTY], 'b': [f.Decimal.CODE_INVALID], }, )
def filter_type(): return f.NamedTuple(Color)