def testDecoratorWithArgs(self): @rpc.export("bar") def bar_impl(): print "bar_impl()" rpc.refresh() assert "bar" in rpc.list_() and rpc._exported_callables["bar"] == bar_impl
def testFunctionCall(self): def baz(): print "baz()" rpc.export("mybaz", baz) rpc.refresh() assert "mybaz" in rpc._exported_callables and rpc._exported_callables["mybaz"] == baz
def testDecoratorNoArgs(self): @rpc.export def foo(): print "foo()" rpc.refresh() assert "foo" in rpc._exported_callables and rpc._exported_callables["foo"] == foo
def __init__(self): # * Create application context, passing in custom arguments, and get a logger argParser = argparse.ArgumentParser(add_help=False) argParser.add_argument('--features', type=str, default=None, help="features to look for, comma separated") self.context = Context.createInstance(description=self.__class__.__name__, parent_argparsers=[argParser]) self.logger = logging.getLogger(self.__class__.__name__) # * Parse arguments self.features = self.context.options.features.split(',') if (hasattr(self.context.options, 'features') and self.context.options.features is not None) else [] self.featureWeights = dict() for feature in self.features: if ':' in feature: # check for explicit weights, e.g. RG:0.8,BY:0.75 try: featureSpec = feature.split(':') self.featureWeights[featureSpec[0].strip()] = float(featureSpec[1].strip()) except Exception as e: self.logger.warn("Invalid feature specification '%s': %s", feature, e) else: # use default weight self.featureWeights[feature.strip()] = default_feature_weight if 'rest' not in self.featureWeights: self.featureWeights['rest'] = default_feature_weight_rest # explicitly specify rest, otherwise previous weights will remain self.logger.info("Searching with feature weights: %s", self.featureWeights) # * Create systems and associated managers self.context.update() # get fresh time self.visSys = VisualSystem(imageSize=self.image_size, timeNow=self.context.timeNow, showMonitor=False) self.visMan = VisionManager(self.visSys, screen_background=self.screen_background) # TODO: Design a better way to share systems/managers (every system has a parent/containing agent?) # * Export RPC calls, if enabled if self.context.isRPCEnabled: self.logger.info("Exporting RPC calls") rpc.export(self.visSys) rpc.export(self.visMan) rpc.refresh() # Context is expected to have started RPC server
def testClassMethodDisable(self): rpc.disable(self.QueueService.count) # enable/disable a class method after class has been defined # rpc.export(self.QueueService) # need to re-export class if a class method has been enabled/disabled (only if already started) rpc.refresh() assert "QueueService.count" not in rpc._exported_callables assert "QueueService.push" not in rpc._exported_callables assert "QueueService.pop" not in rpc._exported_callables
def testInstanceDefaultName(self): q = self.QueueService() rpc.export(q) # export an instance, use class name by default rpc.refresh() assert "QueueService.count" not in rpc._exported_callables assert "QueueService.push" in rpc._exported_callables and rpc._exported_callables["QueueService.push"] == q.push assert "QueueService.pop" not in rpc._exported_callables
def testInstanceDefaultName(self): q = self.QueueService() rpc.export(q) # export an instance, use class name by default rpc.refresh() assert 'QueueService.count' not in rpc._exported_callables assert 'QueueService.push' in rpc._exported_callables and rpc._exported_callables[ 'QueueService.push'] == q.push assert 'QueueService.pop' not in rpc._exported_callables
def testFunctionCall(self): def baz(): print "baz()" rpc.export('mybaz', baz) rpc.refresh() assert 'mybaz' in rpc._exported_callables and rpc._exported_callables[ 'mybaz'] == baz
def testDecoratorWithArgs(self): @rpc.export('bar') def bar_impl(): print "bar_impl()" rpc.refresh() assert 'bar' in rpc.list_( ) and rpc._exported_callables['bar'] == bar_impl
def testDecoratorNoArgs(self): @rpc.export def foo(): print "foo()" rpc.refresh() assert 'foo' in rpc._exported_callables and rpc._exported_callables[ 'foo'] == foo
def testClassDefaultName(self): rpc.refresh() assert ( "QueueService.count" in rpc._exported_callables and rpc._exported_callables["QueueService.count"] == self.QueueService.count ) assert "QueueService.push" not in rpc._exported_callables assert "QueueService.pop" not in rpc._exported_callables
def testClassMethodDisable(self): rpc.disable( self.QueueService.count ) # enable/disable a class method after class has been defined #rpc.export(self.QueueService) # need to re-export class if a class method has been enabled/disabled (only if already started) rpc.refresh() assert 'QueueService.count' not in rpc._exported_callables assert 'QueueService.push' not in rpc._exported_callables assert 'QueueService.pop' not in rpc._exported_callables
def testInstanceExplicitName(self): q = self.QueueService() rpc.export('q', q) # export an instance, explicitly specify name rpc.refresh() assert 'QueueService.count' in rpc._exported_callables and rpc._exported_callables[ 'QueueService.count'] == self.QueueService.count assert 'q.push' in rpc._exported_callables and rpc._exported_callables[ 'q.push'] == q.push assert 'q.pop' not in rpc._exported_callables
def testInstanceMethodEnable(self): q = self.QueueService() rpc.export("q", q) # export an instance, explicitly specify name rpc.enable(q.pop) # enable/disable an instance method after instance has been exported # rpc.export('q', q) # need to re-export instance if an instance method has been enabled/disabled (only if already started) rpc.refresh() assert "QueueService.count" in rpc._exported_callables assert "q.push" in rpc._exported_callables and rpc._exported_callables["q.push"] == q.push assert "q.pop" in rpc._exported_callables and rpc._exported_callables["q.pop"] == q.pop
def testInstanceExplicitName(self): q = self.QueueService() rpc.export("q", q) # export an instance, explicitly specify name rpc.refresh() assert ( "QueueService.count" in rpc._exported_callables and rpc._exported_callables["QueueService.count"] == self.QueueService.count ) assert "q.push" in rpc._exported_callables and rpc._exported_callables["q.push"] == q.push assert "q.pop" not in rpc._exported_callables
def testUnexport(self): @rpc.export def foo(): print "foo()" rpc.refresh() assert "foo" in rpc._exported_callables and rpc._exported_callables["foo"] == foo rpc.unexport("foo") rpc.refresh() assert "foo" not in rpc._exported_callables
def testUnexport(self): @rpc.export def foo(): print "foo()" rpc.refresh() assert 'foo' in rpc._exported_callables and rpc._exported_callables[ 'foo'] == foo rpc.unexport('foo') rpc.refresh() assert 'foo' not in rpc._exported_callables
def testInstanceMethodEnable(self): q = self.QueueService() rpc.export('q', q) # export an instance, explicitly specify name rpc.enable( q.pop ) # enable/disable an instance method after instance has been exported #rpc.export('q', q) # need to re-export instance if an instance method has been enabled/disabled (only if already started) rpc.refresh() assert 'QueueService.count' in rpc._exported_callables assert 'q.push' in rpc._exported_callables and rpc._exported_callables[ 'q.push'] == q.push assert 'q.pop' in rpc._exported_callables and rpc._exported_callables[ 'q.pop'] == q.pop
def testClassDefaultName(self): rpc.refresh() assert 'QueueService.count' in rpc._exported_callables and rpc._exported_callables[ 'QueueService.count'] == self.QueueService.count assert 'QueueService.push' not in rpc._exported_callables assert 'QueueService.pop' not in rpc._exported_callables