mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	fixes
This commit is contained in:
		| @@ -156,3 +156,10 @@ def mock_load_yaml() -> Generator[Any]: | ||||
|         # Default return value | ||||
|         mock_func.return_value = OrderedDict({"sensor": []}) | ||||
|         yield mock_func | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def mock_install_meta_finder() -> Generator[Any]: | ||||
|     """Mock loader.install_meta_finder for testing.""" | ||||
|     with mock.patch("esphome.loader.install_meta_finder") as mock_func: | ||||
|         yield mock_func | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| from pathlib import Path | ||||
| from typing import Any | ||||
| from unittest.mock import MagicMock, patch | ||||
| from unittest.mock import MagicMock | ||||
|  | ||||
| from esphome.components.external_components import do_external_components_pass | ||||
| from esphome.const import ( | ||||
| @@ -15,7 +15,7 @@ from esphome.const import ( | ||||
|  | ||||
|  | ||||
| def test_external_components_skip_update_true( | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock, mock_install_meta_finder: MagicMock | ||||
| ) -> None: | ||||
|     """Test that external components don't update when skip_update=True.""" | ||||
|     # Create a components directory structure | ||||
| @@ -30,31 +30,30 @@ def test_external_components_skip_update_true( | ||||
|     # Set up mock to return our tmp_path | ||||
|     mock_clone_or_update.return_value = (tmp_path, None) | ||||
|  | ||||
|     with patch("esphome.loader.install_meta_finder"): | ||||
|         config: dict[str, Any] = { | ||||
|             CONF_EXTERNAL_COMPONENTS: [ | ||||
|                 { | ||||
|                     CONF_SOURCE: { | ||||
|                         "type": TYPE_GIT, | ||||
|                         CONF_URL: "https://github.com/test/components", | ||||
|                     }, | ||||
|                     CONF_REFRESH: "1d", | ||||
|                     "components": "all", | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     config: dict[str, Any] = { | ||||
|         CONF_EXTERNAL_COMPONENTS: [ | ||||
|             { | ||||
|                 CONF_SOURCE: { | ||||
|                     "type": TYPE_GIT, | ||||
|                     CONF_URL: "https://github.com/test/components", | ||||
|                 }, | ||||
|                 CONF_REFRESH: "1d", | ||||
|                 "components": "all", | ||||
|             } | ||||
|         ] | ||||
|     } | ||||
|  | ||||
|         # Call with skip_update=True | ||||
|         do_external_components_pass(config, skip_update=True) | ||||
|     # Call with skip_update=True | ||||
|     do_external_components_pass(config, skip_update=True) | ||||
|  | ||||
|         # Verify clone_or_update was called with refresh=None | ||||
|         mock_clone_or_update.assert_called_once() | ||||
|         call_args = mock_clone_or_update.call_args | ||||
|         assert call_args.kwargs["refresh"] is None | ||||
|     # Verify clone_or_update was called with refresh=None | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] is None | ||||
|  | ||||
|  | ||||
| def test_external_components_skip_update_false( | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock, mock_install_meta_finder: MagicMock | ||||
| ) -> None: | ||||
|     """Test that external components update when skip_update=False.""" | ||||
|     # Create a components directory structure | ||||
| @@ -69,31 +68,30 @@ def test_external_components_skip_update_false( | ||||
|     # Set up mock to return our tmp_path | ||||
|     mock_clone_or_update.return_value = (tmp_path, None) | ||||
|  | ||||
|     with patch("esphome.loader.install_meta_finder"): | ||||
|         config: dict[str, Any] = { | ||||
|             CONF_EXTERNAL_COMPONENTS: [ | ||||
|                 { | ||||
|                     CONF_SOURCE: { | ||||
|                         "type": TYPE_GIT, | ||||
|                         CONF_URL: "https://github.com/test/components", | ||||
|                     }, | ||||
|                     CONF_REFRESH: "1d", | ||||
|                     "components": "all", | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     config: dict[str, Any] = { | ||||
|         CONF_EXTERNAL_COMPONENTS: [ | ||||
|             { | ||||
|                 CONF_SOURCE: { | ||||
|                     "type": TYPE_GIT, | ||||
|                     CONF_URL: "https://github.com/test/components", | ||||
|                 }, | ||||
|                 CONF_REFRESH: "1d", | ||||
|                 "components": "all", | ||||
|             } | ||||
|         ] | ||||
|     } | ||||
|  | ||||
|         # Call with skip_update=False | ||||
|         do_external_components_pass(config, skip_update=False) | ||||
|     # Call with skip_update=False | ||||
|     do_external_components_pass(config, skip_update=False) | ||||
|  | ||||
|         # Verify clone_or_update was called with actual refresh value | ||||
|         mock_clone_or_update.assert_called_once() | ||||
|         call_args = mock_clone_or_update.call_args | ||||
|         assert call_args.kwargs["refresh"] == "1d" | ||||
|     # Verify clone_or_update was called with actual refresh value | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] == "1d" | ||||
|  | ||||
|  | ||||
| def test_external_components_default_no_skip( | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock | ||||
|     tmp_path: Path, mock_clone_or_update: MagicMock, mock_install_meta_finder: MagicMock | ||||
| ) -> None: | ||||
|     """Test that external components update by default when skip_update not specified.""" | ||||
|     # Create a components directory structure | ||||
| @@ -108,24 +106,23 @@ def test_external_components_default_no_skip( | ||||
|     # Set up mock to return our tmp_path | ||||
|     mock_clone_or_update.return_value = (tmp_path, None) | ||||
|  | ||||
|     with patch("esphome.loader.install_meta_finder"): | ||||
|         config: dict[str, Any] = { | ||||
|             CONF_EXTERNAL_COMPONENTS: [ | ||||
|                 { | ||||
|                     CONF_SOURCE: { | ||||
|                         "type": TYPE_GIT, | ||||
|                         CONF_URL: "https://github.com/test/components", | ||||
|                     }, | ||||
|                     CONF_REFRESH: "1d", | ||||
|                     "components": "all", | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|     config: dict[str, Any] = { | ||||
|         CONF_EXTERNAL_COMPONENTS: [ | ||||
|             { | ||||
|                 CONF_SOURCE: { | ||||
|                     "type": TYPE_GIT, | ||||
|                     CONF_URL: "https://github.com/test/components", | ||||
|                 }, | ||||
|                 CONF_REFRESH: "1d", | ||||
|                 "components": "all", | ||||
|             } | ||||
|         ] | ||||
|     } | ||||
|  | ||||
|         # Call without skip_update parameter | ||||
|         do_external_components_pass(config) | ||||
|     # Call without skip_update parameter | ||||
|     do_external_components_pass(config) | ||||
|  | ||||
|         # Verify clone_or_update was called with actual refresh value | ||||
|         mock_clone_or_update.assert_called_once() | ||||
|         call_args = mock_clone_or_update.call_args | ||||
|         assert call_args.kwargs["refresh"] == "1d" | ||||
|     # Verify clone_or_update was called with actual refresh value | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] == "1d" | ||||
|   | ||||
| @@ -732,96 +732,3 @@ def test_remote_packages_with_files_and_vars( | ||||
|  | ||||
|     actual = do_packages_pass(config) | ||||
|     assert actual == expected | ||||
|  | ||||
|  | ||||
| @patch("esphome.git.clone_or_update") | ||||
| @patch("esphome.yaml_util.load_yaml") | ||||
| @patch("pathlib.Path.is_file") | ||||
| def test_packages_skip_update_true( | ||||
|     mock_is_file: MagicMock, mock_load_yaml: MagicMock, mock_clone_or_update: MagicMock | ||||
| ) -> None: | ||||
|     """Test that packages don't update when skip_update=True.""" | ||||
|     # Setup mocks | ||||
|     mock_clone_or_update.return_value = (Path("/tmp/test"), None) | ||||
|     mock_is_file.return_value = True | ||||
|     mock_load_yaml.return_value = OrderedDict({"sensor": []}) | ||||
|  | ||||
|     config = { | ||||
|         CONF_PACKAGES: { | ||||
|             "test_package": { | ||||
|                 CONF_URL: "https://github.com/test/repo", | ||||
|                 CONF_FILES: ["test.yaml"], | ||||
|                 CONF_REFRESH: "1d", | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     # Call with skip_update=True | ||||
|     do_packages_pass(config, skip_update=True) | ||||
|  | ||||
|     # Verify clone_or_update was called with refresh=None | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] is None | ||||
|  | ||||
|  | ||||
| @patch("esphome.git.clone_or_update") | ||||
| @patch("esphome.yaml_util.load_yaml") | ||||
| @patch("pathlib.Path.is_file") | ||||
| def test_packages_skip_update_false( | ||||
|     mock_is_file: MagicMock, mock_load_yaml: MagicMock, mock_clone_or_update: MagicMock | ||||
| ) -> None: | ||||
|     """Test that packages update when skip_update=False.""" | ||||
|     # Setup mocks | ||||
|     mock_clone_or_update.return_value = (Path("/tmp/test"), None) | ||||
|     mock_is_file.return_value = True | ||||
|     mock_load_yaml.return_value = OrderedDict({"sensor": []}) | ||||
|  | ||||
|     config = { | ||||
|         CONF_PACKAGES: { | ||||
|             "test_package": { | ||||
|                 CONF_URL: "https://github.com/test/repo", | ||||
|                 CONF_FILES: ["test.yaml"], | ||||
|                 CONF_REFRESH: "1d", | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     # Call with skip_update=False (default) | ||||
|     do_packages_pass(config, skip_update=False) | ||||
|  | ||||
|     # Verify clone_or_update was called with actual refresh value | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] == "1d" | ||||
|  | ||||
|  | ||||
| @patch("esphome.git.clone_or_update") | ||||
| @patch("esphome.yaml_util.load_yaml") | ||||
| @patch("pathlib.Path.is_file") | ||||
| def test_packages_default_no_skip( | ||||
|     mock_is_file: MagicMock, mock_load_yaml: MagicMock, mock_clone_or_update: MagicMock | ||||
| ) -> None: | ||||
|     """Test that packages update by default when skip_update not specified.""" | ||||
|     # Setup mocks | ||||
|     mock_clone_or_update.return_value = (Path("/tmp/test"), None) | ||||
|     mock_is_file.return_value = True | ||||
|     mock_load_yaml.return_value = OrderedDict({"sensor": []}) | ||||
|  | ||||
|     config = { | ||||
|         CONF_PACKAGES: { | ||||
|             "test_package": { | ||||
|                 CONF_URL: "https://github.com/test/repo", | ||||
|                 CONF_FILES: ["test.yaml"], | ||||
|                 CONF_REFRESH: "1d", | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     # Call without skip_update parameter | ||||
|     do_packages_pass(config) | ||||
|  | ||||
|     # Verify clone_or_update was called with actual refresh value | ||||
|     mock_clone_or_update.assert_called_once() | ||||
|     call_args = mock_clone_or_update.call_args | ||||
|     assert call_args.kwargs["refresh"] == "1d" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user