2016-09-13 04:16:14 +02:00
|
|
|
"""Test methods in __main__."""
|
|
|
|
from homeassistant import __main__ as main
|
2019-10-05 21:20:11 +02:00
|
|
|
from homeassistant.const import REQUIRED_PYTHON_VER
|
2016-09-13 04:16:14 +02:00
|
|
|
|
2020-05-03 20:27:19 +02:00
|
|
|
from tests.async_mock import PropertyMock, patch
|
|
|
|
|
2016-09-13 04:16:14 +02:00
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
@patch("sys.exit")
|
2016-09-13 04:16:14 +02:00
|
|
|
def test_validate_python(mock_exit):
|
|
|
|
"""Test validate Python version method."""
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch("sys.version_info", new_callable=PropertyMock(return_value=(2, 7, 8))):
|
2016-09-13 04:16:14 +02:00
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is True
|
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch("sys.version_info", new_callable=PropertyMock(return_value=(3, 2, 0))):
|
2016-09-13 04:16:14 +02:00
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is True
|
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch("sys.version_info", new_callable=PropertyMock(return_value=(3, 4, 2))):
|
2016-09-13 04:16:14 +02:00
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is True
|
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
with patch("sys.version_info", new_callable=PropertyMock(return_value=(3, 5, 2))):
|
2016-09-13 04:16:14 +02:00
|
|
|
main.validate_python()
|
2018-02-23 08:22:27 +01:00
|
|
|
assert mock_exit.called is True
|
2016-09-13 04:16:14 +02:00
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
2019-10-05 21:20:11 +02:00
|
|
|
with patch(
|
|
|
|
"sys.version_info",
|
|
|
|
new_callable=PropertyMock(
|
|
|
|
return_value=(REQUIRED_PYTHON_VER[0] - 1,) + REQUIRED_PYTHON_VER[1:]
|
|
|
|
),
|
|
|
|
):
|
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is True
|
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"sys.version_info", new_callable=PropertyMock(return_value=REQUIRED_PYTHON_VER)
|
|
|
|
):
|
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is False
|
|
|
|
|
|
|
|
mock_exit.reset_mock()
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"sys.version_info",
|
|
|
|
new_callable=PropertyMock(
|
|
|
|
return_value=(REQUIRED_PYTHON_VER[:2]) + (REQUIRED_PYTHON_VER[2] + 1,)
|
|
|
|
),
|
|
|
|
):
|
2016-09-13 04:16:14 +02:00
|
|
|
main.validate_python()
|
|
|
|
assert mock_exit.called is False
|
2019-10-05 21:20:11 +02:00
|
|
|
|
|
|
|
mock_exit.reset_mock()
|