def test_validate(self):
        # good
        data = [
            {
                'foo': 'a',
                'bar': {
                    'baz': 'b'
                },
                'bof': 'c'
            },
            {
                'foo': 'x',
                'bar': {
                    'baz': 'y'
                },
                'bof': 'z'
            },
        ]
        missing, extras = validate(data)
        self.assertEqual([], missing) # no problem
        self.assertEqual([], extras) # no problem
        # missing key
        data = [
            {
                'foo': 'a',
                'bar': {
                    'baz': 'b'
                },
                'bof': 'c'
            },
            {
                'foo': 'x',
                'bar': {
                    'baz': 'y'
                },
            },
        ]
        missing, extras = validate(data)
        self.assertEqual([], extras) # no problem
        self.assertEqual(1, len(missing))
        self.assertTrue("Field 'bof'" in missing[0])
        # additional key
        data = [
            {
                'foo': 'a',
                'bar': {
                    'baz': 'b'
                },
                'bof': 'c'
            },
            {
                'foo': 'x',
                'bar': {
                    'baz': 'y',
                },
                'bof': 'z',
                'qux': 'quux'
            },
        ]
        missing, extras = validate(data)
        self.assertEqual([], missing) # no problem
        self.assertEqual(1, len(extras))
        self.assertTrue("Field 'qux' in record" in extras[0])
        # check validation includes sub-dictionaries
        data = [
            {
                'foo': 'a',
                'bar': {
                    'baz': 'b'
                },
                'bof': 'c'
            },
            {
                'foo': 'x',
                'bar': {
                    'quux': 'bif'
                },
                'bof': 'z'
            },
        ]
        missing, extras = validate(data)
        self.assertEqual(1, len(extras))
        self.assertTrue("Field 'quux' in record" in  extras[0])
        self.assertEqual(1, len(missing))
        self.assertTrue("Field 'baz' in record" in missing[0])
dataset/ETHPy150Open fluidinfo/flimp/tests/test_utils.py/TestUtils.test_validate/original