def test_merge_list(self): root = Root() root.merge(''' a: b: - 1 - 2 c: [] ''') assert root.a.b == [1, 2] root.c.merge(root.a.b.copy()) root.a.b.append(3) assert root.a.b == [1, 2, 3] assert root.c == [1, 2]
def test_merge_list(self): root = Root() root.merge(''' a: b: - 1 - 2 c: [] ''') self.assertEqual([1, 2], root.a.b) root.c.merge(root.a.b.copy()) root.a.b.append(3) self.assertEqual([1, 2, 3], root.a.b) self.assertEqual([1, 2], root.c)
def test_merge_deep_object(self): root = Root() root.merge(''' a: b: c: 3 ''') self.assertEqual(3, root.a.b.c) root.merge(''' d: e: 1 ''') self.assertIsInstance(root.d, Mergable) root.d.merge(root.a) self.assertEqual(3, root.d.b.c) root.a.b = 2 self.assertEqual(2, root.a.b) self.assertEqual(3, root.d.b.c)
def test_merge_deep_object(self): root = Root() root.merge(''' a: b: c: 3 ''') assert root.a.b.c == 3 root.merge(''' d: e: 1 ''') assert isinstance(root.d, Mergable) root.d.merge(root.a) assert root.d.b.c == 3 root.a.b = 2 assert root.a.b == 2 assert root.d.b.c == 3
def test_constructor(self): context = dict( c=3 ) builtin = ''' a: a1: 1 b: - 1 - 2 - %(c)s ''' root = Root(builtin, context) assert root.a.a1 == 1 assert root.b[0] == 1 assert root.b[1] == 2 assert root.b[2] == 3 root.merge(''' a: a2: 2 ''') assert root.a.a2 == 2 root.a.a3 = 3 assert root.a.a1 == 1 assert root.a.a2 == 2 assert root.a.a3 == 3 root.merge(''' b: - 4 ''') assert root.b[0] == 4 assert len(root.b) == 1
def test_constructor(self): context = dict(c=3) builtin = ''' a: a1: 1 b: - 1 - 2 - %(c)s ''' root = Root(builtin, context) self.assertEqual(root.a.a1, 1) self.assertEqual(root.b[0], 1) self.assertEqual(root.b[1], 2) self.assertEqual(root.b[2], 3) root.merge(''' a: a2: 2 ''') self.assertEqual(root.a.a2, 2) root.a.a3 = 3 self.assertEqual(root.a.a1, 1) self.assertEqual(root.a.a2, 2) self.assertEqual(root.a.a3, 3) root.merge(''' b: - 4 ''') self.assertEqual(root.b[0], 4) self.assertEqual(1, len(root.b))
def test_merge_empty_object(self): root = Root() root.merge('') self.assertEqual(0, len(root.keys()))
def test_merge_errors(self): root = Root() with self.assertRaises(TypeError): root.merge(None)
def test_merge_empty_object(self): root = Root() root.merge('') assert len(root.keys()) == 0
def test_merge_errors(self): root = Root() with pytest.raises(TypeError): root.merge(None)