def test_dynamic_in_filter(): with FilterEnvironment( "pyfile://" + os.path.dirname(__file__) + "/../interface/SimpleDynamicFilter.py", "SimpleDynInFilter", PropertyCollectionImpl("root", None)) as dynInPyFilter: f = dynInPyFilter.getPlugin() dip = InputPort(True, "dynInPort", dynInPyFilter) dynInPyFilter.addPort(dip) expect_exception(dynInPyFilter.addPort, dip) dop = OutputPort(True, "dynOutPort", dynInPyFilter) expect_exception(dynInPyFilter.addPort, dop) if useCImpl: assert [p.data() for p in dynInPyFilter.getDynamicInputPorts() ] == [dip.data()] else: assert dynInPyFilter.getDynamicInputPorts() == [dip] assert dynInPyFilter.getDynamicOutputPorts() == [] sip = dynInPyFilter.getStaticInputPorts() assert len(sip) == 0 sop = dynInPyFilter.getStaticOutputPorts() assert len(sop) == 1 assert sop[0].name() == "outPort" assert sop[0] is dynInPyFilter.getOutputPort("outPort") assert dynInPyFilter.state() == FilterState.CONSTRUCTED dynInPyFilter.init() dip2 = InputPort(True, "dynInPort2", dynInPyFilter) expect_exception(dynInPyFilter.addPort, dip2) dynInPyFilter.open() expect_exception(dynInPyFilter.addPort, dip2)
def __init__(self, environment): super().__init__(False, True, environment) self.inPort = InputPort(False, "inPort", environment) self.addStaticPort(self.inPort) self.outPort = OutputPort(False, "outPort", environment) self.addStaticPort(self.outPort) self.dynOutPorts = None
def __init__(self, environment): Filter.__init__(self, False, False, environment) self.inPort = InputPort(False, "inPort", environment) self.addStaticPort(self.inPort) self.outPort = OutputPort(False, "outPort", environment) self.addStaticPort(self.outPort) self.sleep_time = self.propertyCollection().defineProperty( "sleep_time", 0.0, "sleep time to simulate computational load [s]", options=dict(min=0.0, max=1.0)) self.log_rcv = self.propertyCollection().defineProperty( "log_rcv", True, "whether or not to log receive events") self.log_prefix = self.propertyCollection().defineProperty( "log_prefix", "", "a prefix for log messages") self.propertyCollection().defineProperty( "an_int_property", 4223, "to have coverage for the integer props", options=dict(min=1234, max=5000)) self.propertyCollection().defineProperty( "an_enum_property", "e1", "to have coverage for the integer props", options=dict(enum=["e1", "e2"]))
def __init__(self, env): super().__init__(False, False, env) self.inputPort = InputPort(False, "in", env) self.addStaticPort(self.inputPort) self.propertyCollection().defineProperty("caption", "view", "Caption of view window.") self.label = None
def __init__(self, env, envCInput, envCOutput, parent): Filter.__init__(self, False, False, env) self._parent = parent for src in envCInput.getDynamicOutputPorts(): dest = InputPort(False, src.name(), env) self.addStaticPort(dest) for src in envCOutput.getDynamicInputPorts(): dest = OutputPort(False, src.name(), env) self.addStaticPort(dest)
def __init__(self, env): super().__init__(False, False, env) self.propertyCollection().defineProperty( "whereToThrow", "nowhere", "one of nowhere,constructor,init,open,start,port,stop,close,deinit" ) if self.propertyCollection().getProperty( "whereToThrow") == "constructor": raise RuntimeError("exception in constructor") self.port = InputPort(False, "port", env) self.addStaticPort(self.port)
def addStaticInputPort(self, name, queueSizeSamples=1, queueSizeSeconds=None): """ Shortcut for generating a static input port and adding it to the filter. See also :py:func:`nexxT.interface.Ports.InputPort` :param name: The name of the input port :param queueSizeSamples: The size of the input queue in samples :param queueSizeSeconds: The size of the input queue in seconds :return: the new port instance """ port = InputPort(False, name, self._environment, queueSizeSamples=queueSizeSamples, queueSizeSeconds=queueSizeSeconds) self.addStaticPort(port) return port
def test_static_filter(): function_calls = [] with FilterEnvironment( "pyfile://" + os.path.dirname(__file__) + "/../interface/SimpleStaticFilter.py", "SimpleStaticFilter", PropertyCollectionImpl("root", None)) as staticPyFilter: f = staticPyFilter.getPlugin() # call the methods to check everything is sane assert f.environment() is staticPyFilter assert len(f.onSuggestDynamicPorts()[0]) == 0 assert len(f.onSuggestDynamicPorts()[1]) == 0 origCallbacks = dict(onInit=f.onInit, onOpen=f.onOpen, onStart=f.onStart, onStop=f.onStop, onClose=f.onClose, onDeinit=f.onDeinit, onPortDataChanged=f.onPortDataChanged) for callback in origCallbacks: setattr(f, callback, lambda *args, callback=callback: function_calls.append( (callback, origCallbacks[callback](*args)))) def exceptionCallback(*args): raise RuntimeError() assert staticPyFilter.getDynamicInputPorts() == [] assert staticPyFilter.getDynamicOutputPorts() == [] sip = staticPyFilter.getStaticInputPorts() assert len(sip) == 1 assert sip[0].name() == "inPort" assert sip[0] is staticPyFilter.getInputPort("inPort") sop = staticPyFilter.getStaticOutputPorts() assert len(sop) == 1 assert sop[0].name() == "outPort" assert sop[0] is staticPyFilter.getOutputPort("outPort") expect_exception(staticPyFilter.addPort, InputPort(True, "dynOutPort", staticPyFilter)) expect_exception(staticPyFilter.addPort, OutputPort(True, "dynOutPort", staticPyFilter)) assert staticPyFilter.state() == FilterState.CONSTRUCTED assert len(function_calls) == 0 expect_exception(staticPyFilter.start) expect_exception(staticPyFilter.open) expect_exception(staticPyFilter.stop) expect_exception(staticPyFilter.close) expect_exception(staticPyFilter.deinit) staticPyFilter.init() assert function_calls == [("onInit", None)] assert staticPyFilter.state() == FilterState.INITIALIZED function_calls.clear() expect_exception(staticPyFilter.init) expect_exception(staticPyFilter.stop) expect_exception(staticPyFilter.start) expect_exception(staticPyFilter.close) staticPyFilter.open() assert function_calls == [("onOpen", None)] assert staticPyFilter.state() == FilterState.OPENED function_calls.clear() expect_exception(staticPyFilter.init) expect_exception(staticPyFilter.open) expect_exception(staticPyFilter.stop) expect_exception(staticPyFilter.deinit) staticPyFilter.start() assert function_calls == [("onStart", None)] assert staticPyFilter.state() == FilterState.ACTIVE function_calls.clear() assert len(function_calls) == 0 expect_exception(staticPyFilter.init) expect_exception(staticPyFilter.open) expect_exception(staticPyFilter.start) expect_exception(staticPyFilter.close) expect_exception(staticPyFilter.deinit) staticPyFilter.stop() assert function_calls == [("onStop", None)] assert staticPyFilter.state() == FilterState.OPENED function_calls.clear() assert len(function_calls) == 0 expect_exception(staticPyFilter.init) expect_exception(staticPyFilter.open) expect_exception(staticPyFilter.stop) expect_exception(staticPyFilter.deinit) staticPyFilter.close() assert function_calls == [("onClose", None)] assert staticPyFilter.state() == FilterState.INITIALIZED function_calls.clear() assert len(function_calls) == 0 staticPyFilter.deinit() assert function_calls == [("onDeinit", None)] assert staticPyFilter.state() == FilterState.CONSTRUCTED function_calls.clear() # check exception call backs f.onInit = exceptionCallback staticPyFilter.init() assert staticPyFilter.state() == FilterState.INITIALIZED staticPyFilter.deinit() function_calls.clear() # check auto cleanup functionality with FilterEnvironment( "pyfile://" + os.path.dirname(__file__) + "/../interface/SimpleStaticFilter.py", "SimpleStaticFilter", PropertyCollectionImpl("root", None)) as staticPyFilter: f = staticPyFilter.getPlugin() origCallbacks = dict(onInit=f.onInit, onOpen=f.onOpen, onStart=f.onStart, onStop=f.onStop, onClose=f.onClose, onDeinit=f.onDeinit, onPortDataChanged=f.onPortDataChanged) for callback in origCallbacks: setattr(f, callback, lambda *args, callback=callback: function_calls.append( (callback, origCallbacks[callback](*args)))) assert len(function_calls) == 0 with FilterEnvironment( "pyfile://" + os.path.dirname(__file__) + "/../interface/SimpleStaticFilter.py", "SimpleStaticFilter", PropertyCollectionImpl("root", None)) as staticPyFilter: f = staticPyFilter.getPlugin() origCallbacks = dict(onInit=f.onInit, onOpen=f.onOpen, onStart=f.onStart, onStop=f.onStop, onClose=f.onClose, onDeinit=f.onDeinit, onPortDataChanged=f.onPortDataChanged) for callback in origCallbacks: setattr(f, callback, lambda *args, callback=callback: function_calls.append( (callback, origCallbacks[callback](*args)))) staticPyFilter.init() assert function_calls == [("onInit", None), ("onDeinit", None)] function_calls.clear() with FilterEnvironment( "pyfile://" + os.path.dirname(__file__) + "/../interface/SimpleStaticFilter.py", "SimpleStaticFilter", PropertyCollectionImpl("root", None)) as staticPyFilter: f = staticPyFilter.getPlugin() origCallbacks = dict(onInit=f.onInit, onStart=f.onStart, onOpen=f.onOpen, onStop=f.onStop, onClose=f.onClose, onDeinit=f.onDeinit, onPortDataChanged=f.onPortDataChanged) for callback in origCallbacks: setattr(f, callback, lambda *args, callback=callback: function_calls.append( (callback, origCallbacks[callback](*args)))) staticPyFilter.init() staticPyFilter.open() staticPyFilter.start() assert function_calls == [("onInit", None), ("onOpen", None), ("onStart", None), ("onStop", None), ("onClose", None), ("onDeinit", None)] function_calls.clear() expect_exception(FilterEnvironment, "weird.plugin.extension", "factory", PropertyCollectionImpl("root", None))