示例#1
0
    def test_differential(self):
        """Test SampleDifferential strategy."""
        diff = sampling.SampleDifferential(self.inform, self.sensor, 5)
        self.assertEqual(self.calls, [])

        diff.attach()
        self.assertEqual(len(self.calls), 1)
示例#2
0
    def test_sampling(self):
        """Test getting and setting the sampling."""
        s = self.sensor

        sampling.SampleNone(None, s)
        sampling.SampleAuto(None, s)
        sampling.SamplePeriod(None, s, 10)
        sampling.SampleEvent(None, s)
        sampling.SampleDifferential(None, s, 2)
        self.assertRaises(ValueError, sampling.SampleNone, None, s, "foo")
        self.assertRaises(ValueError, sampling.SampleAuto, None, s, "bar")
        self.assertRaises(ValueError, sampling.SamplePeriod, None, s)
        self.assertRaises(ValueError, sampling.SamplePeriod, None, s, "1.5")
        self.assertRaises(ValueError, sampling.SamplePeriod, None, s, "-1")
        self.assertRaises(ValueError, sampling.SampleEvent, None, s, "foo")
        self.assertRaises(ValueError, sampling.SampleDifferential, None, s)
        self.assertRaises(ValueError, sampling.SampleDifferential, None, s,
                          "-1")
        self.assertRaises(ValueError, sampling.SampleDifferential, None, s,
                          "1.5")

        sampling.SampleStrategy.get_strategy("none", None, s)
        sampling.SampleStrategy.get_strategy("auto", None, s)
        sampling.SampleStrategy.get_strategy("period", None, s, "15")
        sampling.SampleStrategy.get_strategy("event", None, s)
        sampling.SampleStrategy.get_strategy("differential", None, s, "2")
        self.assertRaises(ValueError, sampling.SampleStrategy.get_strategy,
                          "random", None, s)
        self.assertRaises(ValueError, sampling.SampleStrategy.get_strategy,
                          "period", None, s, "foo")
        self.assertRaises(ValueError, sampling.SampleStrategy.get_strategy,
                          "differential", None, s, "bar")
示例#3
0
 def test_differential(self):
     """Test SampleDifferential strategy."""
     t, status, value = self.sensor.read()
     delta = 3
     DUT = sampling.SampleDifferential(self.inform, self.sensor, delta)
     self.assertEqual(DUT.get_sampling_formatted(),
                      (b'differential', [b'3']))
     self.assertEqual(len(self.calls), 0)
     DUT.start()
     yield self.wake_ioloop()
     # Check initial update
     self.assertEqual(self.calls, [(self.sensor, (t, status, value))])
     self.calls = []
     # Some Updates less than delta from initial value
     self.sensor.set_value(value + 1)
     self.sensor.set_value(value + delta)
     self.sensor.set_value(value)
     self.sensor.set_value(value - 2)
     self.assertEqual(len(self.calls), 0)
     # Now an update bigger than delta from initial value
     self.sensor.set(t, status, value + delta + 1)
     yield self.wake_ioloop()
     self.assertEqual(self.calls,
                      [(self.sensor, (t, status, value + delta + 1))])
     self.calls = []
     # Now change only the status, should update
     t, status, value = self.sensor.read()
     self.sensor.set(t, Sensor.ERROR, value)
     self.assertEqual(self.calls, [(self.sensor, (t, Sensor.ERROR, value))])
     # Test threaded update
     yield self._thread_update_check(t, status, value)
     yield self._check_cancel(DUT)
示例#4
0
 def test_differential_timestamp(self):
     # Test that the timetamp differential is stored correctly as
     # seconds. This is mainly to check the conversion of the katcp spec from
     # milliseconds to seconds for katcp v5 spec.
     time_diff = 4.12                  # Time differential in seconds
     ts_sensor = Sensor(Sensor.TIMESTAMP, 'ts', 'ts sensor', '')
     diff = sampling.SampleDifferential(self.inform, ts_sensor, time_diff)
     self.assertEqual(diff._threshold, time_diff)