From 0996b717ce0023802cac1b3c15324a38a6a04e83 Mon Sep 17 00:00:00 2001 From: Santobert Date: Sat, 16 Nov 2019 13:27:54 +0100 Subject: [PATCH] Improve coverage of input_datetime/reproduce_state (#28272) * Improve coverage of input_datetime/reproduce_state * Improve tests --- .../components/input_datetime/reproduce_state.py | 10 ++-------- .../components/input_datetime/test_reproduce_state.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/input_datetime/reproduce_state.py b/homeassistant/components/input_datetime/reproduce_state.py index 09a30e65210..17c7fcb9d56 100644 --- a/homeassistant/components/input_datetime/reproduce_state.py +++ b/homeassistant/components/input_datetime/reproduce_state.py @@ -31,18 +31,12 @@ def is_valid_datetime(string: str) -> bool: def is_valid_date(string: str) -> bool: """Test if string dt is a valid date.""" - try: - return dt_util.parse_date(string) is not None - except ValueError: - return False + return dt_util.parse_date(string) is not None def is_valid_time(string: str) -> bool: """Test if string dt is a valid time.""" - try: - return dt_util.parse_time(string) is not None - except ValueError: - return False + return dt_util.parse_time(string) is not None async def _async_reproduce_state( diff --git a/tests/components/input_datetime/test_reproduce_state.py b/tests/components/input_datetime/test_reproduce_state.py index 71f0658923c..428b5189117 100644 --- a/tests/components/input_datetime/test_reproduce_state.py +++ b/tests/components/input_datetime/test_reproduce_state.py @@ -36,10 +36,19 @@ async def test_reproducing_states(hass, caplog): # Test invalid state is handled await hass.helpers.state.async_reproduce_state( - [State("input_datetime.entity_datetime", "not_supported")], blocking=True + [ + State("input_datetime.entity_datetime", "not_supported"), + State("input_datetime.entity_datetime", "not-valid-date"), + State("input_datetime.entity_datetime", "not:valid:time"), + State("input_datetime.entity_datetime", "1234-56-78 90:12:34"), + ], + blocking=True, ) assert "not_supported" in caplog.text + assert "not-valid-date" in caplog.text + assert "not:valid:time" in caplog.text + assert "1234-56-78 90:12:34" in caplog.text assert len(datetime_calls) == 0 # Make sure correct services are called