예제 #1
0
def test_mixin():

    class S(object):
        some_attr = "some_attr"

        def instance_method(self):     return "instance_method"
        def _instance_method(self):   return "_instance_method"
        def __instance_method__(self): return "__instance_method__"
        
        @classmethod
        def klass_method(klass): return "klass_method"

        @staticmethod
        def static_method(): return "static_method"

    class T(object):
        pass

    t = T()
    Extension.mixin(T, S)

    has = ["instance_method", "_instance_method"]
    for name in has:
        # attributes exist
        yield lambda _: assert_(hasattr(t, _), "has " + _), name
        # expected value
        yield lambda _: assert_(getattr(t, _), "get " + _), name

    hasnot = ["some_attr", "__instance_method__",
              "klass_method", "static_method"]
    for name in hasnot:
        yield lambda _: assert_(not hasattr(t, _), "has not " + _), name
예제 #2
0
    def __init__(self, sensor_controller):
        """
        Initializer.

        @type  sensor_controller: L{SensorController}
        @param sensor_controller: backing sensor controller
        """
        Extension.__init__(self, extension_name="sensor")
        self.sensor_controller = sensor_controller
예제 #3
0
    def __init__(self, sensor_controller):
        """
        Initializer.

        @type  sensor_controller: L{SensorController}
        @param sensor_controller: backing sensor controller
        """
        Extension.__init__(self, extension_name="sensor")
        self.sensor_controller = sensor_controller
예제 #4
0
def test_mixin():
    class S(object):
        some_attr = "some_attr"

        def instance_method(self):
            return "instance_method"

        def _instance_method(self):
            return "_instance_method"

        def __instance_method__(self):
            return "__instance_method__"

        @classmethod
        def klass_method(klass):
            return "klass_method"

        @staticmethod
        def static_method():
            return "static_method"

    class T(object):
        pass

    t = T()
    Extension.mixin(T, S)

    has = ["instance_method", "_instance_method"]
    for name in has:
        # attributes exist
        yield lambda _: assert_(hasattr(t, _), "has " + _), name
        # expected value
        yield lambda _: assert_(getattr(t, _), "get " + _), name

    hasnot = [
        "some_attr", "__instance_method__", "klass_method", "static_method"
    ]
    for name in hasnot:
        yield lambda _: assert_(not hasattr(t, _), "has not " + _), name
예제 #5
0
 def decorate_tossim_class(self, tossim_class):
     Extension.mixin(tossim_class, TestExtensionC.Mixin)
     tossim_class.property_c = "property_c"
예제 #6
0
 def __init__(self):
     Extension.__init__(self, extension_name="extension_c")
예제 #7
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, TestExtensionA.Mixin)
예제 #8
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, SensorNodeMixin)
예제 #9
0
 def decorate_tossim_class(self, tossim_class):
     Extension.mixin(tossim_class, TestExtensionC.Mixin)
     tossim_class.property_c = "property_c"
예제 #10
0
 def __init__(self):
     Extension.__init__(self, extension_name="extension_c")
예제 #11
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, TestExtensionA.Mixin)
예제 #12
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, SensorNodeMixin)