def test_broadcast_incoming_value_changes(self):
        # params
        pars = Params()
        pars.string('name')
        pars.int('age')
        # server
        s = Server(pars)
        # remote r1
        r1 = Remote()
        s.connect(r1)

        # remote r2
        r2_value_log = []

        def onval(path, val):
            print('--- on val {}'.format(path))
            r2_value_log.append((path, val))

        r2 = Remote()
        r2.outgoing.sendValueEvent += onval
        s.connect(r2)

        self.assertEqual(r2_value_log, [])
        # remote r1 send value change to server
        r1.incoming.valueEvent('/age', 41)
        # verify the change was broadcasted to r2
        self.assertEqual(r2_value_log, [('/age', 41)])
    def test_disconnect_with_invalid_remote(self):
        # params
        pars = Params()
        pars.string('name').set('Abe')
        # server
        s = Server(pars)

        r = Remote()
        s.disconnect(r)
        s.disconnect(None)
Beispiel #3
0
 def test_propagates_param_changes(self):
   p = Params()
   self.assertEqual(p.changeEvent._fireCount, 0)
   name = p.string('name')
   self.assertEqual(p.changeEvent._fireCount, 1)
   name.set('John')
   self.assertEqual(p.changeEvent._fireCount, 2)
Beispiel #4
0
  def test_string(self):
    params = Params()
    param = params.string('name')
    self.assertEqual(param.type, 's')
    self.assertTrue(isinstance(param, Param))

    param.set(4)
    self.assertEqual(param.val(), '4')
    def test_option_queueIncomingValuesUntilUpdate(self):
        # params
        pars = Params()
        pars.string('name').set('Abe')
        # server
        s = Server(pars, queueIncomingValuesUntilUpdate=True)
        # remote
        r1 = Remote()
        s.connect(r1)

        # remote sends value change event
        r1.incoming.valueEvent('/name', 'Bob')
        # incoming value NOT effectuated yet (operation queued)
        self.assertEqual(pars.get('name').val(), 'Abe')
        # process queued operations
        s.update()
        # incoming value effectuated
        self.assertEqual(pars.get('name').val(), 'Bob')
    def test_disconnect(self):
        # params
        pars = Params()
        pars.string('name').set('Abe')
        # server
        s = Server(pars)

        # remote
        r1 = Remote()
        s.connect(r1)
        p1 = create_sync_params(r1)

        # before
        self.assertEqual(p1.get('name').val(), 'Abe')

        # action-1; param value change
        pars.get('name').set('Bob')

        # after-1; verify value change arrived at r1
        self.assertEqual(p1.get('name').val(), 'Bob')

        # action-1.1; r1 send value change
        r1.incoming.valueEvent('/name', 'Cat')

        # after-1; verify value change was processed by server
        self.assertEqual(pars.get('name').val(), 'Cat')
        # ... and was sent back to r1
        self.assertEqual(p1.get('name').val(), 'Cat')

        # action-2; param value changes AFTER r1 disconnects
        s.disconnect(r1)
        pars.get('name').set('Don')

        # after-2; verify value change did NOT arrive at r1
        self.assertEqual(p1.get('name').val(), 'Cat')

        # action-2.1; r1 send value change
        r1.incoming.valueEvent('/name', 'Eve')

        # after-1; verify value change was NOT processed by server
        self.assertEqual(pars.get('name').val(), 'Don')
        # ... and was NOT sent back to r1
        self.assertEqual(p1.get('name').val(), 'Cat')
  def test_schema_list_with_values(self):
    pars = Params()
    pars.string('name').set('Moby Dick')
    pars.int('count').set(100)
    pars.float('price').set(9.99)
    pars.bool('soldout').set(False)

    details = Params()
    details.int('page_count').set(345)
    details.string('author').set('Herman Melville')
    pars.group('details', details)

    self.assertEqual(schema_list(pars), [
      {'path': '/name', 'type':'s', 'value':'Moby Dick'},
      {'path': '/count', 'type':'i', 'value':100},
      {'path': '/price', 'type':'f', 'value':9.99},
      {'path': '/soldout', 'type':'b', 'value':False},
      {'path': '/details/page_count', 'type':'i','value':345},
      {'path': '/details/author', 'type':'s','value':'Herman Melville'}
    ])
  def test_schema_list(self):
    pars = Params()
    pars.string('name')
    pars.int('count')
    pars.float('price')
    pars.bool('soldout')

    details = Params()
    details.int('page_count')
    details.string('author')
    pars.group('details', details)

    self.assertEqual(schema_list(pars), [
      {'path': '/name', 'type':'s'},
      {'path': '/count', 'type':'i'},
      {'path': '/price', 'type':'f'},
      {'path': '/soldout', 'type':'b'},
      {'path': '/details/page_count', 'type':'i'},
      {'path': '/details/author', 'type':'s'}
    ])
    def test_create_sync_params(self):
        # params
        pars = Params()
        pars.string('name')
        # server
        s = Server(pars)
        # remote
        r1 = Remote()
        s.connect(r1)
        p1 = create_sync_params(r1)

        # before
        self.assertEqual(len(p1), 1)
        self.assertIsNone(p1.get('ranking'))
        # mutation; a new parameter is added to pars
        pars.int('ranking')

        # after; verify the mutation is applied to r1's synced params
        self.assertEqual(len(p1), 2)
        self.assertIsNotNone(p1.get('ranking'))
Beispiel #10
0
                          default='info')

        opts, args = parser.parse_args()
        lvl = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL
        }['debug' if opts.verbose else str(opts.verbosity).lower()]
        logging.basicConfig(level=lvl)

        return opts, args

    opts, args = parse_args()

    params = Params()
    params.string('name')
    params.float('score')
    params.int('level')
    params.bool('highest-score')

    http_server = HttpServer(Server(params))
    try:
        while True:
            time.sleep(0.5)
    except KeyboardInterrupt:
        print("Received Ctrl+C... initiating exit")

    http_server.stop()
Beispiel #11
0
    def test_osc_server_choreography(self):
        #
        # setup
        #

        # param
        params = Params()
        params.string("name")
        # server
        server = Server(params)

        # intercept all outgoing osc messages into send_log
        send_log = []

        def capture(host, port, addr, args):
            send_log.append((host, port, addr, args))

        # create osc server
        osc_server = OscServer(server, capture_sends=capture, listen=False)

        #
        # Client connects
        #

        # create fake incoming connect message
        osc_server.receive('/params/connect', ['127.0.0.1:8081'])
        # verify a connect confirmation was sent
        self.assertEqual(send_log,
                         [('127.0.0.1', 8081, '/params/connect/confirm',
                           (json.dumps(schema_list(params))))])

        #
        # Client sends new value
        #
        self.assertIsNone(params.get('name').val())
        send_log.clear()
        osc_server.receive('/params/value', ['/name', 'Fab'])
        # verify value got applied into our local params
        self.assertEqual(params.get('name').val(), 'Fab')
        # verify the value was broadcasted back to client
        self.assertEqual(send_log, [('127.0.0.1', 8081, '/params/value',
                                     ('/name', 'Fab'))])

        #
        # Client sends invalid new value
        #
        send_log.clear()
        osc_server.receive('/params/value', ['/foo', 'bar'])
        # verify nothing sent out to client(s)
        self.assertEqual(len(send_log), 0)

        #
        # Schema change broadcasted to client
        #
        send_log.clear()
        params.int('age')
        self.assertEqual(send_log, [('127.0.0.1', 8081, '/params/schema',
                                     (json.dumps(schema_list(params))))])

        #
        # Client requests schema
        #
        send_log.clear()
        osc_server.receive('/params/schema', ['192.168.1.2:8080'])
        # verify response
        self.assertEqual(send_log, [('192.168.1.2', 8080, '/params/schema',
                                     (json.dumps(schema_list(params))))])

        #
        # Client disconnected by server
        #
        send_log.clear()
        # osc_server.receive('/params/disconnect', ('127.0.0.1:8081'))
        for r in server.connected_remotes:
            r.outgoing.send_disconnect()
            # server.disconnect(r)
        self.assertEqual(send_log,
                         [('127.0.0.1', 8081, '/params/disconnect', ())])
 def test_get_path_with_invalid_path(self):
   pars = Params()
   pars.string('foo')
   self.assertIsNone(get_path(pars, '/bar'))