Example #1
0
 def test_one_day(self):
     """Test storing data for the same day."""
     dh = plant.DailyHistory(3)
     values = [-2, 10, 0, 5, 20]
     for i in range(len(values)):
         dh.add_measurement(values[i])
         max_value = max(values[0:i + 1])
         assert 1 == len(dh._days)
         assert dh.max == max_value
Example #2
0
    def test_multiple_days(self):
        """Test storing data for different days."""
        dh = plant.DailyHistory(3)
        today = datetime.now()
        today_minus_1 = today - timedelta(days=1)
        today_minus_2 = today_minus_1 - timedelta(days=1)
        today_minus_3 = today_minus_2 - timedelta(days=1)
        days = [today_minus_3, today_minus_2, today_minus_1, today]
        values = [10, 1, 7, 3]
        max_values = [10, 10, 10, 7]

        for i in range(len(days)):
            dh.add_measurement(values[i], days[i])
            assert max_values[i] == dh.max
Example #3
0
 def test_no_data(self):
     """Test with empty history."""
     dh = plant.DailyHistory(3)
     assert dh.max is None