Beispiel #1
0
    def test(self):
        a = {'1': 'a', '2': 'b'}
        b = DotMap(a, _dynamic=False)

        def capture(**kwargs):
            return kwargs

        self.assertEqual(a, capture(**b.toDict()))
Beispiel #2
0
 def test_dict_conversion(self):
     d = {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}}
     m = DotMap(d)
     self.assertEqual(m.a, 1)
     self.assertEqual(m.b, 2)
     d2 = m.toDict()
     self.assertIsInstance(d2, dict)
     self.assertNotIsInstance(d2, DotMap)
     self.assertEqual(len(d2), 3)
     self.assertEqual(d2['a'], 1)
     self.assertEqual(d2['b'], 2)
     self.assertNotIsInstance(d2['c'], DotMap)
     self.assertEqual(len(d2['c']), 2)
     self.assertEqual(d2['c']['d'], 3)
     self.assertEqual(d2['c']['e'], 4)
Beispiel #3
0
 def test(self):
     m = DotMap()
     m.a = 5
     m_id = id(m)
     m.recursive = m
     self.assertEqual(id(m.recursive.recursive.recursive), m_id)
     self.assertEqual(str(m), '''DotMap(a=5, recursive=DotMap(...))''')
     d = m.toDict()
     d_id = id(d)
     d['a'] = 5
     d['recursive'] = d
     d['recursive']['recursive']['recursive']
     self.assertEqual(id(d['recursive']['recursive']['recursive']), d_id)
     self.assertEqual(str(d), '''{'a': 5, 'recursive': {...}}''')
     m2 = DotMap(d)
     m2_id = id(m2)
     self.assertEqual(id(m2.recursive.recursive.recursive), m2_id)
     self.assertEqual(str(m2), '''DotMap(a=5, recursive=DotMap(...))''')
Beispiel #4
0
 def test(self):
     m = DotMap({'a': 1, 'b': (11, 22, DotMap({'c': 3}))})
     d = m.toDict()
     self.assertEqual(d, {'a': 1, 'b': (11, 22, {'c': 3})})