Esempio n. 1
0
 def setUp(self):
     self.tree = RecordingTree()
     self.calls = self.tree.calls
     self.sensor1 = katcp.Sensor(int, "sensor1", "First sensor", "",
                                 [0, 100])
     self.sensor2 = katcp.Sensor(int, "sensor2", "Second sensor", "",
                                 [0, 100])
     self.sensor3 = katcp.Sensor(int, "sensor3", "Third sensor", "",
                                 [0, 100])
Esempio n. 2
0
 def setup_sensors(self):
     self._ping_counter = -1
     self._pong_counter = -1
     self.restarted = False
     self.ping_sensor = katcp.Sensor(int, 'ping_counter', 'In', '', None)
     self.add_sensor(self.ping_sensor)
     self.pong_sensor = katcp.Sensor(int, 'pong_counter', 'Out', '', None)
     self.add_sensor(self.pong_sensor)
     self._inc_ping()
     self._inc_pong()
Esempio n. 3
0
    def test_float_sensor(self):
        """Test float sensor."""
        s = DeviceTestSensor(
                katcp.Sensor.FLOAT, "a.float", "A float.", "power",
                [0.0, 5.0],
                timestamp=12345, status=katcp.Sensor.WARN, value=3.0
        )
        self.assertEqual(s.read_formatted(), ("12345000", "warn", "3"))
        self.assertEquals(s.parse_value("3"), 3.0)
        self.assertRaises(ValueError, s.parse_value, "10")
        self.assertRaises(ValueError, s.parse_value, "-10")
        self.assertRaises(ValueError, s.parse_value, "asd")

        s = katcp.Sensor(katcp.Sensor.FLOAT, "a.float", "A float.", "", [-20.0, 20.0])
        self.assertEquals(s.value(), 0.0)
        s = katcp.Sensor(katcp.Sensor.FLOAT, "a.float", "A float.", "", [2.0, 20.0])
        self.assertEquals(s.value(), 2.0)
        s = katcp.Sensor(katcp.Sensor.FLOAT, "a.float", "A float.", "", [2.0, 20.0], default=5.0)
        self.assertEquals(s.value(), 5.0)
Esempio n. 4
0
    def test_int_sensor(self):
        """Test integer sensor."""
        s = DeviceTestSensor(
                katcp.Sensor.INTEGER, "an.int", "An integer.", "count",
                [-4, 3],
                timestamp=12345, status=katcp.Sensor.NOMINAL, value=3
        )
        self.assertEqual(s.read_formatted(), ("12345000", "nominal", "3"))
        self.assertEquals(s.parse_value("3"), 3)
        self.assertRaises(ValueError, s.parse_value, "4")
        self.assertRaises(ValueError, s.parse_value, "-10")
        self.assertRaises(ValueError, s.parse_value, "asd")

        s = katcp.Sensor(katcp.Sensor.INTEGER, "an.int", "An integer.", "count", [-20, 20])
        self.assertEquals(s.value(), 0)
        s = katcp.Sensor(katcp.Sensor.INTEGER, "an.int", "An integer.", "count", [2, 20])
        self.assertEquals(s.value(), 2)
        s = katcp.Sensor(katcp.Sensor.INTEGER, "an.int", "An integer.", "count", [2, 20], default=5)
        self.assertEquals(s.value(), 5)
Esempio n. 5
0
 def make_sensors(number, stype, params=None):
     """Create a number of sensors of the same type."""
     sensors = []
     for i in range(number):
         sensors.append(
             katcp.Sensor(stype,
                          "sensor%d" % i,
                          "Boolean Sensor %d" % i,
                          "",
                          params=params))
     return sensors