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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #5
0
 def decorate_tossim_class(self, tossim_class):
     Extension.mixin(tossim_class, TestExtensionC.Mixin)
     tossim_class.property_c = "property_c"
Beispiel #6
0
 def __init__(self):
     Extension.__init__(self, extension_name="extension_c")
Beispiel #7
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, TestExtensionA.Mixin)
Beispiel #8
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, SensorNodeMixin)
 def decorate_tossim_class(self, tossim_class):
     Extension.mixin(tossim_class, TestExtensionC.Mixin)
     tossim_class.property_c = "property_c"
 def __init__(self):
     Extension.__init__(self, extension_name="extension_c")
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, TestExtensionA.Mixin)
Beispiel #12
0
 def decorate_node_class(self, node_class):
     Extension.mixin(node_class, SensorNodeMixin)