66from databricks .sdk import oidc
77
88
9- class MockIdTokenSource (oidc .IdTokenSource ):
10- def __init__ (self , id_token : str , exception : Exception = None ):
11- self .id_token = id_token
12- self .exception = exception
13-
14- def id_token (self ) -> oidc .IdToken :
15- if self .exception :
16- raise self .exception
17- return oidc .IdToken (jwt = self .id_token )
18-
19-
209@dataclass
2110class EnvTestCase :
2211 name : str
@@ -90,6 +79,8 @@ class FileTestCase:
9079 ),
9180 FileTestCase (
9281 name = "file_does_not_exist" ,
82+ filepath = "nonexistent-file" ,
83+ wantException = ValueError ,
9384 ),
9485 FileTestCase (
9586 name = "file_exists" ,
@@ -106,9 +97,24 @@ def test_file_id_token_source(test_case: FileTestCase, tmp_path):
10697 token_file = tmp_path / test_case .file [0 ]
10798 token_file .write_text (test_case .file [1 ])
10899
109- source = oidc .FileIdTokenSource (test_case .filepath )
100+ fp = ""
101+ if test_case .filepath :
102+ fp = tmp_path / test_case .filepath
103+
104+ source = oidc .FileIdTokenSource (fp )
110105 if test_case .wantException :
111106 with pytest .raises (test_case .wantException ):
112107 source .id_token ()
113108 else :
114109 assert source .id_token () == test_case .want
110+
111+
112+ # class MockIdTokenSource(oidc.IdTokenSource):
113+ # def __init__(self, id_token: str, exception: Exception = None):
114+ # self.id_token = id_token
115+ # self.exception = exception
116+
117+ # def id_token(self) -> oidc.IdToken:
118+ # if self.exception:
119+ # raise self.exception
120+ # return oidc.IdToken(jwt=self.id_token)
0 commit comments