22from pathlib import Path
33from unittest .mock import create_autospec
44
5+ import pytest
56from databricks .sdk .service .workspace import Language
67
78from databricks .labs .ucx .source_code .graph import Dependency
@@ -24,9 +25,19 @@ def detect_language(cls, path: Path, content: str):
2425 assert not NotebookLoaderForTesting .detect_language (Path ("hi" ), "stuff" )
2526
2627
27- def test_notebook_loader_loads_dependency_with_permission_error (caplog ) -> None :
28+ @pytest .mark .parametrize (
29+ "error, message" ,
30+ [
31+ (PermissionError ("Permission denied" ), "Permission error while reading notebook from workspace" ),
32+ (
33+ UnicodeDecodeError ("utf-8" , b"\x80 \x81 \x82 " , 0 , 1 , "invalid start byte" ),
34+ "Cannot decode non-UTF-8 encoded notebook from workspace" ,
35+ ),
36+ ],
37+ )
38+ def test_notebook_loader_loads_dependency_raises_error (caplog , error : Exception , message : str ) -> None :
2839 path = create_autospec (Path )
29- path .read_text .side_effect = PermissionError ( "Permission denied" )
40+ path .read_text .side_effect = error
3041 path_lookup = create_autospec (PathLookup )
3142 path_lookup .resolve .return_value = path
3243 dependency = create_autospec (Dependency )
@@ -35,5 +46,5 @@ def test_notebook_loader_loads_dependency_with_permission_error(caplog) -> None:
3546 with caplog .at_level (logging .WARNING , logger = "databricks.labs.ucx.source_code.notebooks.loaders" ):
3647 found = NotebookLoader ().load_dependency (path_lookup , dependency )
3748
38- assert f"Permission error while reading notebook from workspace : { path } " in caplog .text
49+ assert f"{ message } : { path } " in caplog .text
3950 assert found is None
0 commit comments