mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Merge branch 'fix_clean_build_files_not_removing_platformio_cache' into integration
This commit is contained in:
		| @@ -660,3 +660,37 @@ class TestEsphomeCore: | ||||
|             os.environ.pop("ESPHOME_IS_HA_ADDON", None) | ||||
|             os.environ.pop("ESPHOME_DATA_DIR", None) | ||||
|             assert target.data_dir == expected_default | ||||
|  | ||||
|     def test_platformio_cache_dir_with_env_var(self): | ||||
|         """Test platformio_cache_dir when PLATFORMIO_CACHE_DIR env var is set.""" | ||||
|         target = core.EsphomeCore() | ||||
|         test_cache_dir = "/custom/cache/dir" | ||||
|  | ||||
|         with patch.dict(os.environ, {"PLATFORMIO_CACHE_DIR": test_cache_dir}): | ||||
|             assert target.platformio_cache_dir == test_cache_dir | ||||
|  | ||||
|     def test_platformio_cache_dir_without_env_var(self): | ||||
|         """Test platformio_cache_dir defaults to ~/.platformio/.cache.""" | ||||
|         target = core.EsphomeCore() | ||||
|  | ||||
|         with patch.dict(os.environ, {}, clear=True): | ||||
|             # Ensure env var is not set | ||||
|             os.environ.pop("PLATFORMIO_CACHE_DIR", None) | ||||
|             expected = os.path.expanduser("~/.platformio/.cache") | ||||
|             assert target.platformio_cache_dir == expected | ||||
|  | ||||
|     def test_platformio_cache_dir_empty_env_var(self): | ||||
|         """Test platformio_cache_dir with empty env var falls back to default.""" | ||||
|         target = core.EsphomeCore() | ||||
|  | ||||
|         with patch.dict(os.environ, {"PLATFORMIO_CACHE_DIR": ""}): | ||||
|             expected = os.path.expanduser("~/.platformio/.cache") | ||||
|             assert target.platformio_cache_dir == expected | ||||
|  | ||||
|     def test_platformio_cache_dir_docker_addon_path(self): | ||||
|         """Test platformio_cache_dir in Docker/HA addon environment.""" | ||||
|         target = core.EsphomeCore() | ||||
|         addon_cache = "/data/cache/platformio" | ||||
|  | ||||
|         with patch.dict(os.environ, {"PLATFORMIO_CACHE_DIR": addon_cache}): | ||||
|             assert target.platformio_cache_dir == addon_cache | ||||
|   | ||||
| @@ -349,15 +349,25 @@ def test_clean_build( | ||||
|     dependencies_lock = tmp_path / "dependencies.lock" | ||||
|     dependencies_lock.write_text("lock file") | ||||
|  | ||||
|     # Create PlatformIO cache directory | ||||
|     platformio_cache_dir = tmp_path / ".platformio" / ".cache" | ||||
|     platformio_cache_dir.mkdir(parents=True) | ||||
|     (platformio_cache_dir / "downloads").mkdir() | ||||
|     (platformio_cache_dir / "http").mkdir() | ||||
|     (platformio_cache_dir / "tmp").mkdir() | ||||
|     (platformio_cache_dir / "downloads" / "package.tar.gz").write_text("package") | ||||
|  | ||||
|     # Setup mocks | ||||
|     mock_core.relative_pioenvs_path.return_value = str(pioenvs_dir) | ||||
|     mock_core.relative_piolibdeps_path.return_value = str(piolibdeps_dir) | ||||
|     mock_core.relative_build_path.return_value = str(dependencies_lock) | ||||
|     mock_core.platformio_cache_dir = str(platformio_cache_dir) | ||||
|  | ||||
|     # Verify all exist before | ||||
|     assert pioenvs_dir.exists() | ||||
|     assert piolibdeps_dir.exists() | ||||
|     assert dependencies_lock.exists() | ||||
|     assert platformio_cache_dir.exists() | ||||
|  | ||||
|     # Call the function | ||||
|     with caplog.at_level("INFO"): | ||||
| @@ -367,12 +377,14 @@ def test_clean_build( | ||||
|     assert not pioenvs_dir.exists() | ||||
|     assert not piolibdeps_dir.exists() | ||||
|     assert not dependencies_lock.exists() | ||||
|     assert not platformio_cache_dir.exists() | ||||
|  | ||||
|     # Verify logging | ||||
|     assert "Deleting" in caplog.text | ||||
|     assert ".pioenvs" in caplog.text | ||||
|     assert ".piolibdeps" in caplog.text | ||||
|     assert "dependencies.lock" in caplog.text | ||||
|     assert "PlatformIO cache" in caplog.text | ||||
|  | ||||
|  | ||||
| @patch("esphome.writer.CORE") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user