Пример #1
0
  def test_set_values(self):
    pars = Params()
    pars.int('count').set(1)
    pars.float('price').set(9.99)

    subpars = Params()
    subpars.bool('flag').set(True)
    pars.group('subgroup', subpars)
    
    set_values(pars, {'count': 5, 'price': 0.5, 'subgroup': {'flag': False}})
    self.assertEqual(pars.get('count').val(), 5)
    self.assertEqual(pars.get('price').val(), 0.5)
    self.assertEqual(pars.get('subgroup').get('flag').val(), False)
Пример #2
0
  def test_get_values(self):
    pars = Params()
    pars.int('count').set(1)
    pars.float('price').set(9.99)

    vals = get_values(pars)

    self.assertEqual(vals['count'], 1)
    self.assertEqual(vals['price'], 9.99)
    self.assertEqual(json.loads(json.dumps(vals))['count'], 1)
    self.assertEqual(json.loads(json.dumps(vals))['price'], 9.99)

    pars.get('count').set(100)
    self.assertEqual(get_values(pars)['count'], 100)
Пример #3
0
 def test_group(self):
   p = Params()
   self.assertEqual(len(p), 0)
   p2 = Params()
   p.group('P2', p2)
   self.assertEqual(len(p), 1)
   self.assertEqual(p.get('P2'), p2)
Пример #4
0
    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')
Пример #5
0
    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')
Пример #6
0
 def test_get(self):
   params = Params()
   param = params.bool('check')
   self.assertEqual(params.get('check'), param)
   self.assertIsNone(params.get('foo'))
Пример #7
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', ())])