'Test the conversion from templates to period.'

def test_period_parsing(self):

    today = Template('{{    now().replace(hour=0).replace(minute=0).replace(second=0)    }}', self.hass)
    duration = timedelta(hours=2, minutes=1)
    sensor1 = HistoryStatsSensor(self.hass, 'test', 'on', today, None, duration, 'time', 'test')
    sensor2 = HistoryStatsSensor(self.hass, 'test', 'on', None, today, duration, 'time', 'test')
    sensor1.update_period()
    (sensor1_start, sensor1_end) = sensor1._period
    sensor2.update_period()
    (sensor2_start, sensor2_end) = sensor2._period
    self.assertEqual(sensor1_start.hour, 0)
    self.assertEqual(sensor1_start.minute, 0)
    self.assertEqual(sensor1_start.second, 0)
    self.assertEqual(sensor1_end.hour, 2)
    self.assertEqual(sensor1_end.minute, 1)
    self.assertEqual(sensor1_end.second, 0)
    self.assertEqual(sensor2_start.hour, 21)
    self.assertEqual(sensor2_start.minute, 59)
    self.assertEqual(sensor2_start.second, 0)
    self.assertEqual(sensor2_end.hour, 0)
    self.assertEqual(sensor2_end.minute, 0)
    self.assertEqual(sensor2_end.second, 0)
