|
28 | 28 | from wtforms import BooleanField, Field, StringField
|
29 | 29 |
|
30 | 30 | from airflow.exceptions import AirflowOptionalProviderFeatureException
|
31 |
| -from airflow.providers_manager import HookClassProvider, ProviderInfo, ProvidersManager |
| 31 | +from airflow.providers_manager import HookClassProvider, LazyDictWithCache, ProviderInfo, ProvidersManager |
32 | 32 |
|
33 | 33 |
|
34 | 34 | class TestProviderManager:
|
@@ -372,3 +372,32 @@ def test_optional_feature_debug(self, mock_importlib_import_string):
|
372 | 372 | assert [
|
373 | 373 | "Optional provider feature disabled when importing 'HookClass' from 'test_package' package"
|
374 | 374 | ] == self._caplog.messages
|
| 375 | + |
| 376 | + |
| 377 | +@pytest.mark.parametrize( |
| 378 | + "value, expected_outputs,", |
| 379 | + [ |
| 380 | + ("a", "a"), |
| 381 | + (1, 1), |
| 382 | + (None, None), |
| 383 | + (lambda: 0, 0), |
| 384 | + (lambda: None, None), |
| 385 | + (lambda: "z", "z"), |
| 386 | + ], |
| 387 | +) |
| 388 | +def test_lazy_cache_dict_resolving(value, expected_outputs): |
| 389 | + lazy_cache_dict = LazyDictWithCache() |
| 390 | + lazy_cache_dict["key"] = value |
| 391 | + assert lazy_cache_dict["key"] == expected_outputs |
| 392 | + # Retrieve it again to see if it is correctly returned again |
| 393 | + assert lazy_cache_dict["key"] == expected_outputs |
| 394 | + |
| 395 | + |
| 396 | +def test_lazy_cache_dict_raises_error(): |
| 397 | + def raise_method(): |
| 398 | + raise Exception("test") |
| 399 | + |
| 400 | + lazy_cache_dict = LazyDictWithCache() |
| 401 | + lazy_cache_dict["key"] = raise_method |
| 402 | + with pytest.raises(Exception, match="test"): |
| 403 | + _ = lazy_cache_dict["key"] |
0 commit comments