Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    def testDecoratorNoArgs(self):
        @rpc.export
        def foo():
            print "foo()"

        rpc.refresh()
        assert "foo" in rpc._exported_callables and rpc._exported_callables["foo"] == foo
Beispiel #4
0
 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
Beispiel #5
0
 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
Beispiel #6
0
 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
Beispiel #7
0
 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
Beispiel #8
0
    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
Beispiel #9
0
    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
Beispiel #10
0
    def testDecoratorNoArgs(self):
        @rpc.export
        def foo():
            print "foo()"

        rpc.refresh()
        assert 'foo' in rpc._exported_callables and rpc._exported_callables[
            'foo'] == foo
Beispiel #11
0
 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
Beispiel #12
0
 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
Beispiel #13
0
 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
Beispiel #14
0
 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
Beispiel #15
0
 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
Beispiel #16
0
    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
Beispiel #17
0
    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
Beispiel #18
0
 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
Beispiel #19
0
 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