Esempio n. 1
0
    def test_walk_nondiff_items(self):
        flat_list = ['xxx', 'yyy']
        with self.assertRaises(TypeError):
            list(allow_only._walk_diff(flat_list))

        flat_dict = {'key1': 'xxx', 'key2': 'yyy'}
        with self.assertRaises(TypeError):
            list(allow_only._walk_diff(flat_dict))

        nested_list = [Missing('xxx'), ['yyy']]
        with self.assertRaises(TypeError):
            list(allow_only._walk_diff(nested_list))

        irregular_collection = {
            'key1': Missing('xxx'),
            'key2': [
                Missing('yyy'),
                [
                    Missing('zzz'),
                    'qux',
                ],
            ],
        }
        with self.assertRaises(TypeError):
            list(allow_only._walk_diff(irregular_collection))
Esempio n. 2
0
    def test_walk_dict(self):
        values_set = set([
            Missing('xxx'),
            Missing('yyy'),
        ])
        flat_dict = {
            'key1': Missing('xxx'),
            'key2': Missing('yyy'),
        }
        nested_dict = {
            'key1': {
                'key2': Missing('xxx'),
            },
            'key3': {
                'key4': Missing('yyy'),
            },
        }
        irregular_dict = {
            'key1': Missing('xxx'),
            'key2': {
                'key3': {
                    'key4': Missing('yyy'),
                },
            },
        }

        result = allow_only._walk_diff(flat_dict)
        self.assertEqual(values_set, set(result))

        result = allow_only._walk_diff(nested_dict)
        self.assertEqual(values_set, set(result))

        result = allow_only._walk_diff(irregular_dict)
        self.assertEqual(values_set, set(result))
Esempio n. 3
0
    def test_walk_list(self):
        flat_list = [Missing('val1'), Missing('val2')]
        nested_list = [[Missing('val1')], [Missing('val2')]]
        irregular_list = [[[Missing('val1')]], [Missing('val2')]]

        result = allow_only._walk_diff(flat_list)
        self.assertEqual(flat_list, list(result))

        result = allow_only._walk_diff(nested_list)
        self.assertEqual(flat_list, list(result))

        result = allow_only._walk_diff(irregular_list)
        self.assertEqual(flat_list, list(result))
Esempio n. 4
0
 def test_walk_mixed_types(self):
     values_set = set([
         Missing('alpha'),
         Missing('bravo'),
         Missing('charlie'),
         Missing('delta'),
     ])
     irregular_collection = {
         'key1': Missing('alpha'),
         'key2': [
             Missing('bravo'),
             [
                 Missing('charlie'),
                 Missing('delta'),
             ],
         ],
     }
     result = allow_only._walk_diff(irregular_collection)
     self.assertEqual(values_set, set(result))
Esempio n. 5
0
 def test_walk_single_element(self):
     result = allow_only._walk_diff(
         Missing('xxx'))  # <- Not wrapped in container.
     self.assertEqual([Missing('xxx')], list(result))