Exemplo n.º 1
0
 def test_successful_add_new_to_level1(self):
     update_dict(self.d, ['b', 4])
     self.assertEqual(self.d, {
         'a': {
             '1': 1
         },
         'b': 4
     })
Exemplo n.º 2
0
 def test_successful_multilevel(self):
     update_dict(self.d, ['b', 'c', 'd', 10])
     self.assertEqual(self.d, {
         'a': {
             '1': 1
         },
         'b': {
             'c': {
                 'd': 10
             }
         }
     })
Exemplo n.º 3
0
    def test_unsuccessful_change_item_types(self):
        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, [{}, 4])

        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, [(5,), 4])

        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, [set([5]), 4])

        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, [[5], 4])
Exemplo n.º 4
0
    def test_successful_add_new_dictionary(self):
        update_dict(self.d, ['b', {'c': 4}])
        self.assertEqual(self.d, {
            'a': {
                '1': 1
            },
            'b': {
                'c': 4
            }
        })

        update_dict(self.d, ['b', 'c', 5])
        self.assertEqual(self.d, {
            'a': {
                '1': 1
            },
            'b': {
                'c': 5
            }
        })
Exemplo n.º 5
0
    def test_successful_value_update(self):
        update_dict(self.d, ['a', '1', 'value'])
        self.assertEqual(self.d, {
            'a': {
                '1': 'value'
            }
        })

        update_dict(self.d, ['a', '1', [1, 2, 3]])
        self.assertEqual(self.d, {
            'a': {
                '1': [1, 2, 3]
            }
        })

        update_dict(self.d, ['a', '1', (1, 2, 3,)])
        self.assertEqual(self.d, {
            'a': {
                '1': (1, 2, 3,)
            }
        })
Exemplo n.º 6
0
 def test_unsuccessful_value_exists(self):
     with self.assertRaises(CacheUpdateError):
         update_dict(self.d, ['a', '1', 'key', 'value'])
Exemplo n.º 7
0
 def test_unsuccessful_blacklisted_value_type(self):
     with self.assertRaises(CacheUpdateError):
         update_dict(self.d, ['a', '1', set([1, 2, 3])])
Exemplo n.º 8
0
    def test_unsuccessful_number_args(self):
        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, ['b'])

        with self.assertRaises(CacheUpdateError):
            update_dict(self.d, [])