def test(self): a = {"1": "a", "2": "b"} b = ConfigMap(a, _dynamic=False) def capture(**kwargs): return kwargs self.assertEqual(a, capture(**b.toDict()))
def test_dict_conversion(self): d = {"a": 1, "b": 2, "c": {"d": 3, "e": 4}} m = ConfigMap(d) self.assertEqual(m.a, 1) self.assertEqual(m.b, 2) d2 = m.toDict() self.assertIsInstance(d2, dict) self.assertNotIsInstance(d2, ConfigMap) self.assertEqual(len(d2), 3) self.assertEqual(d2["a"], 1) self.assertEqual(d2["b"], 2) self.assertNotIsInstance(d2["c"], ConfigMap) self.assertEqual(len(d2["c"]), 2) self.assertEqual(d2["c"]["d"], 3) self.assertEqual(d2["c"]["e"], 4)
def test(self): m = ConfigMap() m.a = 5 m_id = id(m) m.recursive = m self.assertEqual(id(m.recursive.recursive.recursive), m_id) outStr = str(m) self.assertIn("""a=5""", outStr) self.assertIn("""recursive=ConfigMap(...)""", outStr) 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) outStr = str(d) self.assertIn("""'a': 5""", outStr) self.assertIn("""recursive': {...}""", outStr) m2 = ConfigMap(d) m2_id = id(m2) self.assertEqual(id(m2.recursive.recursive.recursive), m2_id) outStr2 = str(m2) self.assertIn("""a=5""", outStr2) self.assertIn("""recursive=ConfigMap(...)""", outStr2)
def test(self): m = ConfigMap({"a": 1, "b": (11, 22, ConfigMap({"c": 3}))}) d = m.toDict() self.assertEqual(d, {"a": 1, "b": (11, 22, {"c": 3})})