Example #1
0
 def test_prune_tuple(self):
     l = (Dict(), Dict(), Dict())
     l[0].a.b = 2
     l1 = Dict._prune_iter(l)
     self.assertSequenceEqual(l1, [{'a': {'b': 2}}])
Example #2
0
 def test_init_with_list(self):
     prop = Dict([(0, 1), (1, 2), (2, 3)])
     self.assertDictEqual(prop, {0: 1, 1: 2, 2: 3})
Example #3
0
 def test_init_with_tuples_and_empty_list(self):
     prop = Dict((0, 1), [], (2, 3))
     self.assertDictEqual(prop, {0: 1, 2: 3})
Example #4
0
 def test_set_three_level_properties(self):
     prop = Dict()
     prop.a.b.c = TEST_VAL
     self.assertDictEqual(prop, TEST_DICT)
Example #5
0
 def test_init_with_kws(self):
     prop = Dict(a=2, b={'a': 2}, c=[{'a': 2}])
     self.assertDictEqual(prop, {'a': 2, 'b': {'a': 2}, 'c': [{'a': 2}]})
Example #6
0
 def test_set_one_level_property(self):
     prop = Dict()
     prop.a = TEST_VAL
     self.assertDictEqual(prop, {'a': TEST_VAL})
Example #7
0
 def test_do_not_prune_empty_list_nested(self):
     prop = Dict({'a': 1, 'c': {'d': []}})
     prop.prune(prune_empty_list=False)
     self.assertDictEqual(prop, {'a': 1, 'c': {'d': []}})
Example #8
0
 def test_prune_tuple(self):
     l = (Dict(), Dict(), Dict())
     l[0].a.b = 2
     l1 = Dict._prune_iter(l)
     self.assertSequenceEqual(l1, [{'a': {'b': 2}}])
Example #9
0
 def test_prune_not_new_list(self):
     prop = Dict()
     prop.a.b = []
     prop.b = 2
     prop.prune()
     self.assertDictEqual(prop, {'b': 2})
Example #10
0
 def test_prune_with_tuple(self):
     prop = Dict()
     prop.a = (Dict(), Dict(), Dict())
     prop.a[0].b.c = 2
     prop.prune()
     self.assertDictEqual(prop, {'a': ({'b': {'c': 2}}, )})
Example #11
0
 def test_prune_list(self):
     l = [Dict(), Dict(), Dict()]
     l[0].a.b = 2
     l1 = Dict._prune_iter(l)
     self.assertSequenceEqual(l1, [{'a': {'b': 2}}])
Example #12
0
 def test_prune_with_list(self):
     prop = Dict()
     prop.a = [Dict(), Dict(), Dict()]
     prop.a[0].b.c = 2
     prop.prune()
     self.assertDictEqual(prop, {'a': [{'b': {'c': 2}}]})
Example #13
0
 def test_prune_dont_remove_zero(self):
     prop = Dict()
     prop.a = 0
     prop.b.c
     prop.prune()
     self.assertDictEqual(prop, {'a': 0})
Example #14
0
 def test_set_two_level_items(self):
     some_dict = {'a': {'b': TEST_VAL}}
     prop = Dict()
     prop['a']['b'] = TEST_VAL
     self.assertDictEqual(prop, some_dict)
Example #15
0
 def test_prune_shared_key(self):
     prop = Dict(TEST_DICT)
     prop.a.b.d
     prop.prune()
     self.assertDictEqual(prop, TEST_DICT)
Example #16
0
 def test_iter_reduce(self):
     prop = Dict()
     prop.a = (Dict(), 1, 2)
     prop.a[0].b.c
     prop.prune()
     self.assertDictEqual(prop, {'a': (1, 2)})
Example #17
0
 def test_prune_zero_nested(self):
     prop = Dict({'a': 1, 'c': {'d': 0}})
     prop.prune(prune_zero=True)
     self.assertDictEqual(prop, {'a': 1})
Example #18
0
 def test_prune_nested_list(self):
     prop = Dict()
     prop.a = [Dict(), [[]], [1, 2, 3]]
     prop.prune()
     self.assertDictEqual(prop, {'a': [[1, 2, 3]]})
Example #19
0
 def test_prune_zero_in_tuple(self):
     prop = Dict({'a': 1, 'c': (1, 0)})
     prop.prune(prune_zero=True)
     self.assertDictEqual(prop, {'a': 1, 'c': (1, )})
Example #20
0
 def test_set_three_level_items(self):
     prop = Dict()
     prop['a']['b']['c'] = TEST_VAL
     self.assertDictEqual(prop, TEST_DICT)
Example #21
0
 def test_set_two_level_properties(self):
     prop = Dict()
     prop.a.b = TEST_VAL
     self.assertDictEqual(prop, {'a': {'b': TEST_VAL}})
Example #22
0
 def test_complex_nested_structure(self):
     prop = Dict()
     prop.a = [(Dict(), 2), [[]], [1, (2, 3), 0]]
     prop.prune(prune_zero=True)
     self.assertDictEqual(prop, {'a': [(2, ), [1, (2, 3)]]})
Example #23
0
 def test_init_with_dict(self):
     self.assertDictEqual(TEST_DICT, Dict(TEST_DICT))
Example #24
0
 def test_tuple_key(self):
     prop = Dict()
     prop[(1, 2)] = 2
     self.assertDictEqual(prop, {(1, 2): 2})
     self.assertEqual(prop[(1, 2)], 2)
Example #25
0
 def test_init_with_tuples(self):
     prop = Dict((0, 1), (1, 2), (2, 3))
     self.assertDictEqual(prop, {0: 1, 1: 2, 2: 3})
Example #26
0
 def test_repr_html(self):
     prop = Dict()
     prop.a.b.c = TEST_VAL
     self.assertEqual(prop._repr_html_(), TEST_DICT_STR)
Example #27
0
 def test_init_with_generator(self):
     prop = Dict(((i, i + 1) for i in range(3)))
     self.assertDictEqual(prop, {0: 1, 1: 2, 2: 3})
Example #28
0
 def test_dir(self):
     prop = Dict({'a': 1})
     dir_prop = dir(prop)
     self.assertEqual(dir_prop, dir(Dict))
     self.assertTrue('__methods__' not in dir_prop)
     self.assertTrue('__members__' not in dir_prop)
Example #29
0
 def init():
     Dict(5)
Example #30
0
 def test_dir_with_members(self):
     prop = Dict({'__members__': 1})
     dir(prop)
     self.assertTrue('__members__' in prop.keys())
Example #31
0
 def test_prune_list(self):
     l = [Dict(), Dict(), Dict()]
     l[0].a.b = 2
     l1 = Dict._prune_list(l)
     self.assertSequenceEqual(l1, [{'a': {'b': 2}}])
Example #32
0
 def test_prune_empty_list(self):
     prop = Dict(TEST_DICT)
     prop.b.c = []
     prop.prune()
     self.assertDictEqual(prop, TEST_DICT)