fix test commented in #20678 (#20680)

This commit is contained in:
Diogo Gomes 2019-02-02 06:11:50 +00:00 committed by Paulus Schoutsen
parent fcccf133ba
commit 384a9625c9

View File

@ -1,8 +1,11 @@
"""The test for the History Statistics sensor platform.""" """The test for the History Statistics sensor platform."""
# pylint: disable=protected-access # pylint: disable=protected-access
from datetime import timedelta from datetime import datetime, timedelta
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
import pytest
import pytz
from homeassistant.helpers import template
from homeassistant.const import STATE_UNKNOWN from homeassistant.const import STATE_UNKNOWN
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
@ -12,7 +15,6 @@ from homeassistant.helpers.template import Template
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.common import init_recorder_component, get_test_home_assistant from tests.common import init_recorder_component, get_test_home_assistant
import pytest
class TestHistoryStatsSensor(unittest.TestCase): class TestHistoryStatsSensor(unittest.TestCase):
@ -50,6 +52,9 @@ class TestHistoryStatsSensor(unittest.TestCase):
def test_period_parsing(self): def test_period_parsing(self):
"""Test the conversion from templates to period.""" """Test the conversion from templates to period."""
now = datetime(2019, 1, 1, 23, 30, 0, tzinfo=pytz.utc)
with patch.dict(template.ENV.globals, {'now': lambda: now}):
print(dt_util.now())
today = Template('{{ now().replace(hour=0).replace(minute=0)' today = Template('{{ now().replace(hour=0).replace(minute=0)'
'.replace(second=0) }}', self.hass) '.replace(second=0) }}', self.hass)
duration = timedelta(hours=2, minutes=1) duration = timedelta(hours=2, minutes=1)
@ -70,9 +75,9 @@ class TestHistoryStatsSensor(unittest.TestCase):
assert sensor1_start.second == 0 assert sensor1_start.second == 0
# End = 02:01:00 # End = 02:01:00
# assert sensor1_end.hour == 2 assert sensor1_end.hour == 2
# assert sensor1_end.minute == 1 assert sensor1_end.minute == 1
# assert sensor1_end.second == 0 assert sensor1_end.second == 0
# Start = 21:59:00 # Start = 21:59:00
assert sensor2_start.hour == 21 assert sensor2_start.hour == 21