예제 #1
0
    def test_singleton(self):
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        a = ConfigProxy(c1, 'root1')
        b = ConfigProxy(c2, 'root2')

        assert a is b
        assert b.get_root_node('root2')['y'] == 2
예제 #2
0
    def test_write(self):
        root = cnode.CNode({'z': 3})
        c = Configuration(root)
        ConfigProxy.reset()
        cp = ConfigProxy()
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        cp.add_proxy(c1, 'root1')
        cp.add_proxy(c2, 'root2')
        cp.add_proxy(c, 'root3')
        cp.write('root1', 'x/x1', {'x11': 3, 'x12': 4})

        assert cp['root1']['x']['x1']['x11'] == 3
        assert cp['root1']['x']['x1']['x12'] == 4
예제 #3
0
    def test_set_configs_by_dic_way(self):
        root = cnode.CNode({'z': 3})
        c = Configuration(root)
        ConfigProxy.reset()
        cp = ConfigProxy()
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        cp.add_proxy(c1, 'root1')
        cp.add_proxy(c2, 'root2')
        cp.add_proxy(c, 'root3')
        cp.write('root1', 'x/x1', {'x11': 3, 'x12': 4})
        node = cnode.CNode({'w': 6})

        c_new = Configuration(node)
        cp['root3'] = c_new
        assert cp['root3']['w'] == 6
        assert cp['root3']['z'] is None
예제 #4
0
 def test_cview_set(self):
     root = cnode.CNode({'x': {'a': 1, 'b': 2}})
     c1 = Configuration(root)
     ConfigProxy.reset()
     c = ConfigProxy()
     c.add_proxy(c1, 'root1')
     cfg = c.get_view('root1', 'x')
     assert cfg['a'] == 1
     cfg['b'] = 3
     assert cfg['b'] == 3
예제 #5
0
    def test_add_proxy(self):
        root = cnode.CNode({'z': 3})
        c = Configuration(root)
        ConfigProxy.reset()
        cp = ConfigProxy()
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        cp.add_proxy(c1, 'root1')
        cp.add_proxy(c2, 'root2')

        cp.add_proxy(c, 'root3')
        assert cp['root3']['z'] == 3
        assert cp['root1']['x'] == 1
        assert cp['root2']['y'] == 2
예제 #6
0
    def test_set_root_node(self):
        root = cnode.CNode({'z': 3})
        c = Configuration(root)
        ConfigProxy.reset()
        cp = ConfigProxy()
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        cp.add_proxy(c1, 'root1')
        cp.add_proxy(c2, 'root2')
        cp.add_proxy(c, 'root3')
        cp.write('root1', 'x/x1', {'x11': 3, 'x12': 4})
        node = cnode.CNode({'q': 5})

        cp.set_root_node('root3', node)
        assert cp.get_root_node('root3')['q'] == 5
        assert 'z' not in cp.get_root_node('root3')
예제 #7
0
    def test_write_overwrite(self):
        root = cnode.CNode({'z': 3})
        c = Configuration(root)
        ConfigProxy.reset()
        cp = ConfigProxy()
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})
        c1 = Configuration(root1)
        c2 = Configuration(root2)
        cp.add_proxy(c1, 'root1')
        cp.add_proxy(c2, 'root2')
        cp.add_proxy(c, 'root3')
        cp.write('root1', 'x/x1', {'x11': 3, 'x12': 4})
        node = cnode.CNode({'yy': 11})
        node2 = cnode.CNode({'yyy': 22})
        node3 = cnode.CNode({'yyyy': 33})
        cp.write('root2', 'y', node, is_overwrite=False)
        cp.write('root2', 'y', node3, is_overwrite=False)
        assert cp['root2']['y']['yy'] == 11
        assert cp['root2']['y']['yyyy'] == 33
        cp.write('root2', 'y', node2, is_overwrite=True)

        assert cp['root2']['y']['yyy'] == 22
        assert cp['root2']['y']['yy'] is None