def test_multiple_registrations(self):
        assert OpaqueFuncRegistry.Size() == 0

        @register_opaque_func('py_func1', [TypeCode.Str, TypeCode.XGraph])
        def py_func(str_name, xgraph):
            assert xgraph.get_name() == "name1"
            xgraph.set_name(str_name)

        @register_opaque_func('py_func2', [TypeCode.Str, TypeCode.XGraph])
        def py_func2(str_name, xgraph):
            xgraph.add(XLayer(name=str_name, type=[str_name]))

        assert OpaqueFuncRegistry.Size() == 2
        assert set(OpaqueFuncRegistry.GetRegisteredFuncs()) == \
            set(['py_func1', 'py_func2'])

        xg = XGraph("name1")
        of1 = OpaqueFuncRegistry.Get("py_func1")
        of1("name2", xg)
        assert xg.get_name() == "name2"
        assert len(xg) == 0

        of2 = OpaqueFuncRegistry.Get("py_func2")
        of2("x1", xg)
        assert xg.get_name() == "name2"
        assert len(xg) == 1
        assert xg.get('x1').name == 'x1'
        assert xg.get('x1').type == ['x1']
Ejemplo n.º 2
0
    def test_xgraph_arg_name(self):
        def py_func(xg):
            assert xg.get_name() == "test"
            xg.set_name("test2")

        xgraph = XGraph("test")
        of = OpaqueFunc(py_func, [TypeCode.XGraph])
        of(xgraph)
        assert xgraph.get_name() == "test2"
Ejemplo n.º 3
0
    def test_xgraph_layer_add(self):
        def py_func(xg):
            assert xg.get_name() == "test"
            X = XLayer(name='x1', type=['X1'])
            xg.add(X)

        xgraph = XGraph("test")
        assert len(xgraph) == 0
        of = OpaqueFunc(py_func, [TypeCode.XGraph])
        of(xgraph)

        assert xgraph.get_name() == "test"
        assert len(xgraph) == 1
        assert xgraph.get('x1').type == ['X1']
    def test_registration_flow(self):
        assert OpaqueFuncRegistry.Size() == 0

        @register_opaque_func('py_func', [TypeCode.Str, TypeCode.XGraph])
        def py_func(str_name, xgraph):
            assert xgraph.get_name() == "name1"
            xgraph.set_name(str_name)

        assert OpaqueFuncRegistry.Size() == 1
        assert OpaqueFuncRegistry.GetRegisteredFuncs() == ['py_func']

        xg = XGraph("name1")
        of = OpaqueFuncRegistry.Get("py_func")
        of("name2", xg)
        assert xg.get_name() == "name2"