Esempio n. 1
0
 def _get_sensor_reading(self, sensor_name):
     req = mock_req('sensor-value', sensor_name)
     reply, informs = yield handle_mock_req(self.server, req)
     self.assertTrue(reply.reply_ok(), msg=reply)
     status, value = informs[0].arguments[-2:]
     value = type_converter(value)
     raise Return((status, value))
Esempio n. 2
0
 def _send_request_expect_fail(self, request_name, *args):
     if request_name == 'configure':
         reply, informs = yield self._configure_helper(*args)
     else:
         reply, informs = yield handle_mock_req(
             self.server, mock_req(request_name, *args))
     self.assertFalse(reply.reply_ok(), msg=reply)
     raise Return((reply, informs))
Esempio n. 3
0
    def test_request_timeout_hint(self):
        req = mock_req('request-timeout-hint')
        handle_mock_req(self.server, req)
        # Check that the default test server "slow command" request has the
        # expected timeout hint of 99 seconds
        self._assert_msgs_equal([req.reply_msg],
                                ['!request-timeout-hint ok 1'])
        self._assert_msgs_equal(req.inform_msgs,
                                ['#request-timeout-hint slow-command 99.0'])
        # Check that a request without a hint gives a timeout of 0 if explicitly
        # asked for
        req = mock_req('request-timeout-hint', 'help')
        handle_mock_req(self.server, req)
        self._assert_msgs_equal([req.reply_msg],
                                ['!request-timeout-hint ok 1'])
        self._assert_msgs_equal(req.inform_msgs,
                                ['#request-timeout-hint help 0.0'])

        # Now set hint on help command and check that it is reflected. Note, in
        # Python 3 the im_func would not be neccesary, but in Python 2 you
        # cannot add a new attribute to an instance method. For Python 2 we need
        # to make a copy of the original handler function using partial and then
        # mess with that copy.
        handler_original = self.server._request_handlers['help'].im_func
        handler_updated = wraps(handler_original)(partial(
            handler_original, self.server))
        self.server._request_handlers['help'] = kattypes.request_timeout_hint(
            25.5)(handler_updated)
        req = mock_req('request-timeout-hint', 'help')
        handle_mock_req(self.server, req)
        self._assert_msgs_equal([req.reply_msg],
                                ['!request-timeout-hint ok 1'])
        self._assert_msgs_equal(req.inform_msgs,
                                ['#request-timeout-hint help 25.5'])
        req = mock_req('request-timeout-hint')
        handle_mock_req(self.server, req)
        # Check that the default test server "slow command" request has the
        # expected timeout hint of 99 seconds
        self._assert_msgs_equal([req.reply_msg],
                                ['!request-timeout-hint ok 2'])
        self._assert_msgs_equal(req.inform_msgs, [
            '#request-timeout-hint help 25.5',
            '#request-timeout-hint slow-command 99.0'
        ])
Esempio n. 4
0
 def test_sensor_sampling(self):
     start_thread_with_cleanup(self, self.server)
     s = katcp.Sensor.boolean('a-sens')
     s.set(1234, katcp.Sensor.NOMINAL, True)
     self.server.add_sensor(s)
     self.server._send_message = WaitingMock()
     self.server.wait_running(timeout=1.)
     self.assertTrue(self.server.running())
     self.server._strategies = defaultdict(lambda: {})
     req = mock_req('sensor-sampling', 'a-sens', 'event')
     self.server.request_sensor_sampling(req, req.msg).result(timeout=1)
     inf = req.client_connection.inform
     inf.assert_wait_call_count(count=1)
     (inf_msg, ) = inf.call_args[0]
     self._assert_msgs_equal(
         [inf_msg], (r'#sensor-status 1234000 1 a-sens nominal 1', ))
     req = mock_req('sensor-sampling', 'a-sens', 'period', 1000)
     self.server.request_sensor_sampling(req, req.msg).result()
     client = req.client_connection
     strat = self.server._strategies[client][s]
     # Test that the periodic update period is converted to seconds
     self.assertEqual(strat._period, 1.)
     # test that parameters returned by the request matches v4 format.
     #
     # We need to pass in the same client_conn as used by the previous
     # request since strategies are bound to specific connections
     req = mock_req('sensor-sampling', 'a-sens', client_conn=client)
     reply = self.server.request_sensor_sampling(req, req.msg).result()
     self._assert_msgs_equal([reply],
                             ['!sensor-sampling ok a-sens period 1000'])
     # event-rate is not an allowed v4 strategy
     with self.assertRaises(FailReply):
         self.server.request_sensor_sampling(
             req,
             katcp.Message.request('sensor-sampling', 'a-sens',
                                   'event-rate', 1000, 2000)).result()
     # differential-rate is not an allowed v4 strategy
     with self.assertRaises(FailReply):
         self.server.request_sensor_sampling(
             req,
             katcp.Message.request('sensor-sampling', 'a-sens',
                                   'differential-rate', 1, 1000,
                                   2000)).result()
Esempio n. 5
0
 def test_sensor_sampling(self):
     start_thread_with_cleanup(self, self.server)
     s = katcp.Sensor.boolean('a-sens')
     s.set(1234, katcp.Sensor.NOMINAL, True)
     self.server.add_sensor(s)
     self.server._send_message = WaitingMock()
     self.server.wait_running(timeout=1.)
     self.assertTrue(self.server.running())
     self.server._strategies = defaultdict(lambda : {})
     req = mock_req('sensor-sampling', 'a-sens', 'event')
     self.server.request_sensor_sampling(req, req.msg)
     inf = req.client_connection.inform
     inf.assert_wait_call_count(count=1)
     (inf_msg, ) = inf.call_args[0]
     self._assert_msgs_equal([inf_msg], (
         r'#sensor-status 1234000 1 a-sens nominal 1',))
     req = mock_req('sensor-sampling', 'a-sens', 'period', 1000)
     self.server.request_sensor_sampling(req, req.msg)
     client = req.client_connection
     strat = self.server._strategies[client][s]
     # Test that the periodic update period is converted to seconds
     self.assertEqual(strat._period, 1.)
     # test that parameters returned by the request matches v4 format.
     #
     # We need to pass in the same client_conn as used by the previous
     # request since strategies are bound to specific connections
     req = mock_req('sensor-sampling', 'a-sens', client_conn=client)
     reply = self.server.request_sensor_sampling(req, req.msg)
     self._assert_msgs_equal([reply],
                             ['!sensor-sampling ok a-sens period 1000'])
     # event-rate is not an allowed v4 strategy
     with self.assertRaises(FailReply):
         self.server.request_sensor_sampling(req, katcp.Message.request(
             'sensor-sampling', 'a-sens', 'event-rate', 1000, 2000))
     # differential-rate is not an allowed v4 strategy
     with self.assertRaises(FailReply):
         self.server.request_sensor_sampling(req, katcp.Message.request(
          'sensor-sampling', 'a-sens', 'differential-rate', 1, 1000, 2000))
Esempio n. 6
0
 def _send_request_expect_fail(self, request_name, *args):
     reply, informs = yield handle_mock_req(self.server,
                                            mock_req(request_name, *args))
     self.assertFalse(reply.reply_ok(), msg=reply)
     raise Return((reply, informs))
Esempio n. 7
0
 def _check_sensor_exists(self, sensor_name):
     #Test that the products sensor has been updated
     req = mock_req('sensor-list', sensor_name)
     reply, informs = yield handle_mock_req(self.server, req)
     raise Return(reply.reply_ok())
Esempio n. 8
0
 def _configure_helper(self, product_name, antennas, nchans, streams_json,
                       proxy_name):
     req = mock_req('configure', product_name, antennas, nchans,
                    streams_json, proxy_name)
     reply, informs = yield handle_mock_req(self.server, req)
     raise Return((reply, informs))