def test_no_exception(self): function = lambda x: False # <- Rejects everything. with self.assertRaises(AssertionError) as cm: with allow_each(function): pass # No exceptions raised exc = cm.exception self.assertEqual('No differences found: <lambda>', str(exc))
def test_allow_some(self): function = lambda x: x.value == 'bar' in_diffs = [ Missing('foo'), Missing('bar'), ] with self.assertRaises(DataError) as cm: with allow_each(function, 'example message'): raise DataError('example error', in_diffs) rejected = list(cm.exception.differences) self.assertEqual(rejected, [Missing('foo')])
def test_kwds(self): function = lambda x: True # <- Accepts everything. in_diffs = [ Missing('foo', aaa='x', bbb='y'), Missing('bar', aaa='x', bbb='z'), ] with self.assertRaises(DataError) as cm: # Keyword bbb='y' should reject second in_diffs element. with allow_each(function, 'example message', bbb='y'): raise DataError('example error', in_diffs) rejected = list(cm.exception.differences) self.assertEqual(rejected, [Missing('bar', aaa='x', bbb='z')])
def test_allow_all(self): function = lambda x: isinstance(x, Missing) # <- Allow only missing. with allow_each(function, 'example message'): raise DataError('example error', [Missing('xxx'), Missing('yyy')])