def test_invalid_path_warning(self):
        """Test warning for an invalid path during archive extraction."""
        invalid_path = os.path.join(os.getcwd(), "invalid.txt")
        with open(invalid_path, "w") as f:
            f.write("invalid")
        with tarfile.open(self.tar_path, "w") as tar:
            tar.add(
                invalid_path, arcname="../../invalid.txt"
            )  # Path intended to be outside of base dir
        with tarfile.open(self.tar_path, "r") as tar:
            with patch("warnings.warn") as mock_warn:
                _ = list(file_utils.filter_safe_paths(tar.getmembers()))
                warning_msg = (
                    "Skipping invalid path during archive extraction: "
                    "'../../invalid.txt'."
                )
                mock_warn.assert_called_with(warning_msg, stacklevel=2)
        os.remove(invalid_path)
Test warning for an invalid path during archive extraction.
keras/src/utils/file_utils_test.py