Ejemplo n.º 1
0
def testExtensionInheritanceTwoExtensions():
    """Test non_extension injection for multiple extensions."""
    class Test1ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test1"
        def _execute(self):
            return 1
    class Test2ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test2"
    class Test3ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test3"
        def _execute(self):
            return "3a"
    class TestNode1(mdp.Node):
        pass
    class TestNode2(TestNode1):
        pass
    class ExtendedTest1Node2(Test1ExtensionNode, TestNode2):
        pass
    class ExtendedTest2Node1(Test2ExtensionNode, TestNode1):
        def _execute(self):
            return 2
    class ExtendedTest3Node1(Test3ExtensionNode, TestNode1):
        def _execute(self):
            return "3b"
    test_node = TestNode2()
    mdp.activate_extension('__test2')
    assert test_node._execute() == 2
    mdp.deactivate_extension('__test2')
    # in this order TestNode2 should get execute from __test1,
    # the later addition by __test1 to TestNode1 doesn't matter
    mdp.activate_extensions(['__test1', '__test2'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])
    # now activate in inverse order
    # TestNode2 already gets _execute from __test2, but that is still
    # overriden by __test1, thats how its registered in _extensions
    mdp.activate_extensions(['__test2', '__test1'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])
    ## now the same with extension 3
    mdp.activate_extension('__test3')
    assert test_node._execute() == "3b"
    mdp.deactivate_extension('__test3')
    # __test3 does not override, since the _execute slot for Node2
    # was first filled by __test1
    mdp.activate_extensions(['__test3', '__test1'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test3', '__test1'])
    # inverse order
    mdp.activate_extensions(['__test1', '__test3'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])
Ejemplo n.º 2
0
# Note:  throbbers created at http://www.loadinfo.net
#    throbber 16_cycle_one_24

import cStringIO as StringIO
import json
import os
import fnmatch

import mdp
from mdp.hinet import (ChannelSwitchboard, Rectangular2dSwitchboard,
                       DoubleRect2dSwitchboard, DoubleRhomb2dSwitchboard,
                       get_2d_image_switchboard)

import switchboard_svg
mdp.activate_extensions(["switchboard_factory", "svg"])

# keys are nice switchboard standard names, values are the types
SWITCHBOARD_TYPES_DICT = {
    "standard rect": Rectangular2dSwitchboard,
    "double rect": DoubleRect2dSwitchboard,
    "double rhomb": DoubleRhomb2dSwitchboard,
    "single node": ChannelSwitchboard
}
# ordered list of switchboard names for the UI
SWITCHBOARD_NAMES = [
    "standard rect", "double rect", "double rhomb", "single node"
]

# SVG style
SVG_BASE_SIZE = 3  # size of the little channel rectangles
Ejemplo n.º 3
0
 def setup_environment(self):
     """Activate the used extensions."""
     # deactivate all active extensions for safety
     mdp.deactivate_extensions(mdp.get_active_extensions())
     mdp.activate_extensions(self._used_extensions)
Ejemplo n.º 4
0
 def setup_environment(self):
     """Activate the used extensions."""
     # deactivate all active extensions for safety
     mdp.deactivate_extensions(mdp.get_active_extensions())
     mdp.activate_extensions(self._used_extensions)
Ejemplo n.º 5
0
# Note:  throbbers created at http://www.loadinfo.net
#    throbber 16_cycle_one_24

import cStringIO as StringIO
import json
import os
import fnmatch

import mdp
from mdp.hinet import (
    ChannelSwitchboard, Rectangular2dSwitchboard, DoubleRect2dSwitchboard,
    DoubleRhomb2dSwitchboard, get_2d_image_switchboard
)

import switchboard_svg
mdp.activate_extensions(["switchboard_factory", "svg"])

# keys are nice switchboard standard names, values are the types
SWITCHBOARD_TYPES_DICT = {
    "standard rect": Rectangular2dSwitchboard,
    "double rect": DoubleRect2dSwitchboard,
    "double rhomb": DoubleRhomb2dSwitchboard,
    "single node": ChannelSwitchboard
}
# ordered list of switchboard names for the UI
SWITCHBOARD_NAMES = ["standard rect", "double rect",
                     "double rhomb", "single node"] 

# SVG style
SVG_BASE_SIZE = 3  # size of the little channel rectangles
SVG_GAP_SIZE = 1  # size of the gap between them
Ejemplo n.º 6
0
def testExtensionInheritanceTwoExtensions():
    """Test non_extension injection for multiple extensions."""
    class Test1ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test1"

        def _execute(self):
            return 1

    class Test2ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test2"

    class Test3ExtensionNode(mdp.ExtensionNode):
        extension_name = "__test3"

        def _execute(self):
            return "3a"

    class TestNode1(mdp.Node):
        pass

    class TestNode2(TestNode1):
        pass

    class ExtendedTest1Node2(Test1ExtensionNode, TestNode2):
        pass

    class ExtendedTest2Node1(Test2ExtensionNode, TestNode1):
        def _execute(self):
            return 2

    class ExtendedTest3Node1(Test3ExtensionNode, TestNode1):
        def _execute(self):
            return "3b"

    test_node = TestNode2()
    mdp.activate_extension('__test2')
    assert test_node._execute() == 2
    mdp.deactivate_extension('__test2')
    # in this order TestNode2 should get execute from __test1,
    # the later addition by __test1 to TestNode1 doesn't matter
    mdp.activate_extensions(['__test1', '__test2'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])
    # now activate in inverse order
    # TestNode2 already gets _execute from __test2, but that is still
    # overriden by __test1, thats how its registered in _extensions
    mdp.activate_extensions(['__test2', '__test1'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])
    ## now the same with extension 3
    mdp.activate_extension('__test3')
    assert test_node._execute() == "3b"
    mdp.deactivate_extension('__test3')
    # __test3 does not override, since the _execute slot for Node2
    # was first filled by __test1
    mdp.activate_extensions(['__test3', '__test1'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test3', '__test1'])
    # inverse order
    mdp.activate_extensions(['__test1', '__test3'])
    assert test_node._execute() == 1
    mdp.deactivate_extensions(['__test2', '__test1'])