Пример #1
0
    def test_no_exception(self):
        with self.assertRaises(AssertionError) as cm:
            with allow_any(foo='bar'):
                pass  # No exceptions raised

        exc = cm.exception
        self.assertEqual('No differences found: allow_any', str(exc))
Пример #2
0
    def test_no_kwds(self):
        in_diffs = [
            Extra('xxx', aaa='foo'),
            Extra('yyy', aaa='bar'),
        ]
        with self.assertRaises(TypeError) as cm:
            with allow_any('example message'):  # <- Missing keyword argument!
                raise DataError('example error', in_diffs)

        result = cm.exception
        expected = 'requires 1 or more keyword arguments (0 given)'
        self.assertEqual(expected, str(result))
Пример #3
0
    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_any('example message', aaa='foo'):
                raise DataError('example error', in_diffs)

        rejected = list(cm.exception.differences)
        self.assertEqual(rejected, [Extra('yyy', aaa='bar')])
Пример #4
0
def _allowAny(self, number=None, msg=None, **kwds_filter):
    if number:
        return datatest.allow_limit(number, msg, **kwds_filter)
    return datatest.allow_any(msg, **kwds_filter)