def test_no_exception(self): with self.assertRaises(AssertionError) as cm: with allow_extra(): pass # No exceptions raised exc = cm.exception self.assertEqual('No differences found: allow_extra', str(exc))
def test_allow_some(self): differences = [Extra('xxx'), Missing('yyy')] with self.assertRaises(DataError) as cm: with allow_extra(): raise DataError('example error', differences) rejected = list(cm.exception.differences) self.assertEqual(rejected, [Missing('yyy')])
def test_kwds(self): in_diffs = [ Extra('xxx', aaa='foo'), Extra('yyy', aaa='bar'), Missing('zzz', aaa='foo'), ] with self.assertRaises(DataError) as cm: with allow_extra('example allowance', aaa='foo'): raise DataError('example error', in_diffs) rejected = list(cm.exception.differences) self.assertEqual(rejected, [Extra('yyy', aaa='bar'), Missing('zzz', aaa='foo')])
def test_allow_all(self): with allow_extra(): raise DataError('example error', [Extra('xxx'), Extra('yyy')])