Don't allow hass.config.config_dir to be None (#98442)

This commit is contained in:
Erik Montnemery 2023-08-16 13:00:14 +02:00 committed by GitHub
parent 5ed3e90607
commit 91faa53843
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 28 additions and 56 deletions

View file

@ -1428,7 +1428,7 @@ async def test_serviceregistry_return_response_optional(
async def test_config_defaults() -> None:
"""Test config defaults."""
hass = Mock()
config = ha.Config(hass)
config = ha.Config(hass, "/test/ha-config")
assert config.hass is hass
assert config.latitude == 0
assert config.longitude == 0
@ -1442,7 +1442,7 @@ async def test_config_defaults() -> None:
assert config.skip_pip_packages == []
assert config.components == set()
assert config.api is None
assert config.config_dir is None
assert config.config_dir == "/test/ha-config"
assert config.allowlist_external_dirs == set()
assert config.allowlist_external_urls == set()
assert config.media_dirs == {}
@ -1455,22 +1455,19 @@ async def test_config_defaults() -> None:
async def test_config_path_with_file() -> None:
"""Test get_config_path method."""
config = ha.Config(None)
config.config_dir = "/test/ha-config"
config = ha.Config(None, "/test/ha-config")
assert config.path("test.conf") == "/test/ha-config/test.conf"
async def test_config_path_with_dir_and_file() -> None:
"""Test get_config_path method."""
config = ha.Config(None)
config.config_dir = "/test/ha-config"
config = ha.Config(None, "/test/ha-config")
assert config.path("dir", "test.conf") == "/test/ha-config/dir/test.conf"
async def test_config_as_dict() -> None:
"""Test as dict."""
config = ha.Config(None)
config.config_dir = "/test/ha-config"
config = ha.Config(None, "/test/ha-config")
config.hass = MagicMock()
type(config.hass.state).value = PropertyMock(return_value="RUNNING")
expected = {
@ -1501,7 +1498,7 @@ async def test_config_as_dict() -> None:
async def test_config_is_allowed_path() -> None:
"""Test is_allowed_path method."""
config = ha.Config(None)
config = ha.Config(None, "/test/ha-config")
with TemporaryDirectory() as tmp_dir:
# The created dir is in /tmp. This is a symlink on OS X
# causing this test to fail unless we resolve path first.
@ -1533,7 +1530,7 @@ async def test_config_is_allowed_path() -> None:
async def test_config_is_allowed_external_url() -> None:
"""Test is_allowed_external_url method."""
config = ha.Config(None)
config = ha.Config(None, "/test/ha-config")
config.allowlist_external_urls = [
"http://x.com/",
"https://y.com/bla/",
@ -1584,7 +1581,7 @@ async def test_start_taking_too_long(
event_loop, caplog: pytest.LogCaptureFixture
) -> None:
"""Test when async_start takes too long."""
hass = ha.HomeAssistant()
hass = ha.HomeAssistant("/test/ha-config")
caplog.set_level(logging.WARNING)
hass.async_create_task(asyncio.sleep(0))
@ -1751,7 +1748,7 @@ async def test_additional_data_in_core_config(
hass: HomeAssistant, hass_storage: dict[str, Any]
) -> None:
"""Test that we can handle additional data in core configuration."""
config = ha.Config(hass)
config = ha.Config(hass, "/test/ha-config")
hass_storage[ha.CORE_STORAGE_KEY] = {
"version": 1,
"data": {"location_name": "Test Name", "additional_valid_key": "value"},
@ -1764,7 +1761,7 @@ async def test_incorrect_internal_external_url(
hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture
) -> None:
"""Test that we warn when detecting invalid internal/external url."""
config = ha.Config(hass)
config = ha.Config(hass, "/test/ha-config")
hass_storage[ha.CORE_STORAGE_KEY] = {
"version": 1,
@ -1777,7 +1774,7 @@ async def test_incorrect_internal_external_url(
assert "Invalid external_url set" not in caplog.text
assert "Invalid internal_url set" not in caplog.text
config = ha.Config(hass)
config = ha.Config(hass, "/test/ha-config")
hass_storage[ha.CORE_STORAGE_KEY] = {
"version": 1,