Пример #1
0
    def test_recursion_factory(self):
        """ Test Recursion detection"""

        pm = self.pm
        #pm.init()
        pkg = Package("compositenode", {})

        sgfactory1 = CompositeNodeFactory("graph1")
        sgfactory2 = CompositeNodeFactory("graph2")

        map(pkg.add_factory, (sgfactory1, sgfactory2))

        assert len(pkg.get_names()) == 2

        pm.add_package(pkg)
    
        n1 = sgfactory1.instantiate()
        n2 = sgfactory1.instantiate()
        # build the compositenode factory
        n1.add_node(n2)
        n2.add_node(n1)

        n1.to_factory(sgfactory1)
        n2.to_factory(sgfactory2)

        #sgfactory1.add_nodefactory ( ("compositenode", "graph2"))
        #sgfactory2.add_nodefactory ( ("compositenode", "graph1"))

        try:
            sg = sgfactory1.instantiate()
            assert False
        except RecursionError:
            assert True
Пример #2
0
    def test_compositenodeio(self):
        """ Test IO"""
        pm = self.pm
        # pm.init()

        pkg = Package("compositenode", {})

        # create a compositenode with 2 in and 1 out
        # the compositenode does an addition
        sg = CompositeNode(
            inputs=(dict(name="in1", interface=None, value=None),
                    dict(name="in2", interface=None, value=None)),
            outputs=(dict(name="out", interface=None), ),
        )
        addid = sg.add_node(self.plus_node)

        sg.connect(sg.id_in, 0, addid, 0)
        sg.connect(sg.id_in, 1, addid, 1)
        sg.connect(addid, 0, sg.id_out, 0)

        sgfactory = CompositeNodeFactory("additionsg")
        sg.to_factory(sgfactory)

        sg1 = sgfactory.instantiate()
        sg1.set_input(0, 2.)
        sg1.set_input(1, 3.)
        sg1()

        assert sg1.get_output(0) == 5.

        pkg.add_factory(sgfactory)
        pm.add_package(pkg)

        sg = CompositeNode()
        addid = sg.add_node(pm.get_node("compositenode", "additionsg"))
        val1id = sg.add_node(self.float_node)
        val2id = sg.add_node(self.float_node)
        val3id = sg.add_node(self.float_node)

        sg.connect(val1id, 0, addid, 0)
        sg.connect(val2id, 0, addid, 1)
        sg.connect(addid, 0, val3id, 0)

        sgfactory2 = CompositeNodeFactory("testio")
        sg.to_factory(sgfactory2)
        # allocate the compositenode

        sg = sgfactory2.instantiate()
        sg.node(val1id).set_input(0, 2.)
        sg.node(val2id).set_input(0, 3.)

        # evaluation
        sg()
        assert sg.node(val3id).get_output(0) == 5.
Пример #3
0
    def test_compositenodeio(self):
        """ Test IO"""
        pm = self.pm
        # pm.init()

        pkg = Package("compositenode", {})

        # create a compositenode with 2 in and 1 out
        # the compositenode does an addition
        sg = CompositeNode(inputs=(dict(name="in1", interface=None, value=None),
                                   dict(name="in2", interface=None,
                                        value=None)),
                           outputs=(dict(name="out", interface=None),), )
        addid = sg.add_node(self.plus_node)

        sg.connect(sg.id_in, 0, addid, 0)
        sg.connect(sg.id_in, 1, addid, 1)
        sg.connect(addid, 0, sg.id_out, 0)

        sgfactory = CompositeNodeFactory("additionsg")
        sg.to_factory(sgfactory)

        sg1 = sgfactory.instantiate()
        sg1.set_input(0, 2.)
        sg1.set_input(1, 3.)
        sg1()

        assert sg1.get_output(0) == 5.

        pkg.add_factory(sgfactory)
        pm.add_package(pkg)

        sg = CompositeNode()
        addid = sg.add_node(pm.get_node("compositenode", "additionsg"))
        val1id = sg.add_node(self.float_node)
        val2id = sg.add_node(self.float_node)
        val3id = sg.add_node(self.float_node)

        sg.connect(val1id, 0, addid, 0)
        sg.connect(val2id, 0, addid, 1)
        sg.connect(addid, 0, val3id, 0)

        sgfactory2 = CompositeNodeFactory("testio")
        sg.to_factory(sgfactory2)
        # allocate the compositenode

        sg = sgfactory2.instantiate()
        sg.node(val1id).set_input(0, 2.)
        sg.node(val2id).set_input(0, 3.)

        # evaluation
        sg()
        assert sg.node(val3id).get_output(0) == 5.
Пример #4
0
def register_packages(pkgmanager):
    package = Package("jcd_test", {})

    nf = Factory( name="dbg", 
                description="debug", 
                category="display", 
                inputs=(dict(name='in', interface=None, value=None), ),
                outputs=(dict(name='out', interface=None), ),
                nodemodule="jcd_node",
                nodeclass="DebugNode",
                )
    package.add_factory( nf )
    
    nf = Factory( name="cid", 
                description="cells scale", 
                category="creator", 
                inputs=(),
                outputs=(dict(name='scale', interface=IInt), ),
                nodemodule="jcd_node",
                nodeclass="CidNode",
                )
    package.add_factory( nf )
    
    nf = Factory( name="wid", 
                  description="walls scale", 
                  category="creator", 
                  inputs=(),
                  outputs=(dict(name='scale', interface=IInt),),
                  nodemodule="jcd_node",
                  nodeclass="WidNode",
                )
    package.add_factory( nf )
    
    nf = Factory( name="eid", 
                description="edges scale", 
                category="creator", 
                inputs=(),
                outputs=(dict(name='scale', interface=IInt),),
                nodemodule="jcd_node",
                nodeclass="EidNode",
                )
    package.add_factory( nf )
    pkgmanager.add_package(package)