Beispiel #1
0
    def test(self):
        import copy

        original = ConfigMap()
        original.a = 1
        original.b = 3
        shallowCopy = original
        deepCopy = copy.deepcopy(original)
        self.assertEqual(original, shallowCopy)
        self.assertEqual(id(original), id(shallowCopy))
        self.assertEqual(original, deepCopy)
        self.assertNotEqual(id(original), id(deepCopy))
        original.a = 2
        self.assertEqual(original, shallowCopy)
        self.assertNotEqual(original, deepCopy)
Beispiel #2
0
 def test(self):
     m = ConfigMap()
     self.assertTrue(m.empty())
     m.a = 1
     self.assertFalse(m.empty())
     self.assertTrue(m.b.empty())
     self.assertIsInstance(m.b, ConfigMap)
Beispiel #3
0
    def test_order_preserved(self):
        import copy

        original = ConfigMap()
        original.a = 1
        original.b = 2
        original.c = 3
        deepCopy = copy.deepcopy(original)
        orderedPairs = []
        for k, v in original.iteritems():
            orderedPairs.append((k, v))
        for i, (k, v) in enumerate(deepCopy.iteritems()):
            self.assertEqual(k, orderedPairs[i][0])
            self.assertEqual(v, orderedPairs[i][1])
Beispiel #4
0
 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)