コード例 #1
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_find_ancestors(self):
     c0 = cnode.CNode()
     c1 = cnode.CNode({'x': c0})
     c2 = cnode.CNode({'y': c1})
     nodes = view._find_ancestors(c2, c0)
     self.assertEqual(len(nodes), 2)
     self.assertIs(nodes[0], c2)
     self.assertIs(nodes[1], c1)
コード例 #2
0
    def test_read_configs_node(self):
        root1 = cnode.CNode({'x': 1})
        root2 = cnode.CNode({'y': 2})

        a = Configuration(root1)
        b = Configuration(root2)
        assert a is not b
        assert a.read('x') == 1
        assert a['x'] == 1
コード例 #3
0
 def test_update_n(self):
     c = cnode.CNode({'x': 1})
     c = cnode.CNode({'y': 2, 's': c})
     self.assertEqual(c['y'], 2)
     c.update(cnode.QueryKey('y'), 3)
     self.assertEqual(c['y'], 3)
     self.assertEqual(c.read(['s', 'x']), 1)
     c = c.update('s', {'x': 2})
     self.assertEqual(c.read(['s', 'x']), 2)
コード例 #4
0
    def test_write_configs(self):
        root1 = cnode.CNode({'x': 1})
        a = Configuration(root1)
        a.write('x/y', 2)
        a.write('x/z', {'z1': 11, 'z2': 22})

        a.write('x/y/d', cnode.CNode({'d1': 33}))
        assert a['x']['z']['z2'] == 22
        assert a['x']['y'] is not 2
        assert a['x']['y']['d']['d1'] == 33
コード例 #5
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
コード例 #6
0
    def test_write_configs_with_overwrite(self):
        root1 = cnode.CNode({'x': 1})
        node1 = cnode.CNode({'z': 3})
        node2 = cnode.CNode({'d': 4})
        a = Configuration(root1)
        a.write('x/y', node2)
        a.write('x/y', node1, is_overwrite=False)
        assert a['x']['y']['d'] == 4
        a.write('x/y', node1, is_overwrite=True)

        assert a['x']['y']['d'] is None
コード例 #7
0
 def test_get_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})
     assert cp.get_root_node('root3')['z'] == 3
コード例 #8
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_setitem(self):
     c = cnode.CNode()
     c.update('x', {'a': 1})
     v = view.create_view(c, 'x')
     v['b'] = 2
     assert v['a'] == 1
     assert v['b'] == 2
コード例 #9
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
コード例 #10
0
 def test_normal_dict(self):
     c = cnode.CNode({'x': 1, 'y': 2})
     assert len(c) == 2
     assert c['x'] == 1
     assert c['y'] == 2
     assert tuple(c.keys()) == ('x', 'y')
     assert tuple(c.values()) == (1, 2)
     assert [v for k, v in c.items()] == [1, 2]
     assert [k for k, v in c.items()] == ['x', 'y']
コード例 #11
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
コード例 #12
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
コード例 #13
0
 def test_basic_dict(self):
     dct = {
         'f1': {
             'x': 0,
             'y': 1,
         },
         'z': 2,
     }
     c = cnode.CNode(dct)
     self.assertEqual(c.read(cnode.QueryKey(['z'])), 2)
     self.assertEqual(c.read(cnode.QueryKey(['f1', 'x'])), 0)
コード例 #14
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
コード例 #15
0
 def test_read_value_recursive(self):
     c_sub = cnode.CNode({'x': 1})
     c = cnode.CNode({'y': 2, 's': c_sub})
     self.assertEqual(c.read(cnode.QueryKey(['s', 'x'])), 1)
コード例 #16
0
 def test_update_self(self):
     c = cnode.CNode({'x': 1})
     c.update([], {'x': 2})
     self.assertEqual(c['x'], 2)
     c.update(None, {'x': 3})
     self.assertEqual(c['x'], 3)
コード例 #17
0
 def test_basic_init(self):
     c = cnode.CNode()
     c.update('x', {'a': 1, 'b': 2})
     self.assertEqual(c.read(['x', 'a']), 1)
コード例 #18
0
 def test_construct(self):
     c_sub = cnode.CNode({'x': 1, 'y': 2})
     c = cnode.CNode({'sub': c_sub, 'z': 3})
コード例 #19
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_update_default_without_conflict(self):
     c = cnode.CNode()
     c.update('x', {'a': 1})
     v = view.create_view(c, 'x')
     v.update_default('b', 3)
     assert v['b'] == 3
コード例 #20
0
 def test_fast_create(self):
     c = cnode.CNode()
     c.create('x', cnode.CNode({'y': 1}))
     self.assertEqual(c.read(cnode.QueryKey(['x', 'y'])), 1)
コード例 #21
0
 def test_update_v(self):
     c = cnode.CNode({'x': 1})
     c = cnode.CNode({'y': 2, 's': c})
     self.assertEqual(c['y'], 2)
     c.update(cnode.QueryKey('y'), 3)
     self.assertEqual(c['y'], 3)
コード例 #22
0
 def test_father(self):
     c = cnode.CNode({'x': 1, 'y': {'z': 2}})
     c2 = c['y']
     assert c2.father == c
コード例 #23
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_keys(self):
     c = cnode.CNode()
     c.update('x', {'a': 1, 'b': 2})
     v = view.create_view(c, 'x')
     v.keys()
     assert False
コード例 #24
0
 def test_read_value_simple(self):
     c = cnode.CNode({'x': 1})
     self.assertEqual(c.read(cnode.QueryKey(['x'])), 1)
コード例 #25
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_update_value_and_default_value(self):
     c = cnode.CNode()
     c.update('x', {'a': 1})
     v = view.create_view(c, 'x')
     v.update_value_and_default('b', 1, 3)
     assert v['b'] == 1
コード例 #26
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_base_node(self):
     sub = cnode.CNode()
     c = cnode.CNode({'x': sub})
     self.assertIs(view.base_node(c, 'x'), sub)
コード例 #27
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_update_default(self):
     c = cnode.CNode()
     c.update('x', {'a': 1})
     v = view.create_view(c, 'x')
     v.update_default('a', 3)
     assert v['a'] == 1
コード例 #28
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_basic_view(self):
     c = cnode.CNode()
     c.update('x', {'a': 1, 'b': 2})
     v = view.create_view(c, 'x')
     self.assertEqual(v.get('a'), 1)
コード例 #29
0
ファイル: test_view.py プロジェクト: tech-pi/dxcore
 def test_update_with_none_without_conflict(self):
     c = cnode.CNode()
     c.update('x', {'a': 1})
     v = view.create_view(c, 'x')
     v.update('b', None)
     assert v['b'] is None
コード例 #30
0
 def test_fast_read(self):
     c = cnode.CNode({'x': 1})
     c = cnode.CNode({'s': c, 'y': 2})
     self.assertEqual(c.read(['s', 'x']), 1)
     self.assertEqual(c.read('y'), 2)