22from  pydantic  import  ValidationError 
33
44from  zenml .utils .warnings .base  import  (
5-     WarningConfig ,
65    WarningCategory ,
6+     WarningConfig ,
77    WarningSeverity ,
88    WarningVerbosity ,
99)
@@ -16,7 +16,7 @@ def controller() -> WarningController:
1616
1717    We reuse the singleton instance but clear its internal state to ensure test isolation. 
1818    """ 
19-     c  =  WarningController ()
19+     c  =  WarningController . create ()
2020    # hard reset of internal state 
2121    c ._warning_configs .clear ()
2222    c ._warning_statistics .clear ()
@@ -109,7 +109,9 @@ def test_config_validations_reject_invalid_values():
109109        )
110110
111111
112- def  test_registration_merges_configs (controller : WarningController , sample_configs : dict [str , WarningConfig ]):
112+ def  test_registration_merges_configs (
113+     controller : WarningController , sample_configs : dict [str , WarningConfig ]
114+ ):
113115    controller .register (sample_configs )
114116    assert  controller ._warning_configs ["TEST001" ].code  ==  "TEST001" 
115117    assert  controller ._warning_configs ["TEST002" ].is_throttled  is  True 
@@ -120,7 +122,9 @@ def test_singleton_instance_is_shared(controller: WarningController):
120122    assert  controller  is  another 
121123
122124
123- def  test_statistics_increment_for_non_throttled (controller : WarningController , sample_configs : dict [str , WarningConfig ]):
125+ def  test_statistics_increment_for_non_throttled (
126+     controller : WarningController , sample_configs : dict [str , WarningConfig ]
127+ ):
124128    controller .register (sample_configs )
125129
126130    controller .warn (warning_code = "TEST001" , message = "once" )
@@ -130,7 +134,9 @@ def test_statistics_increment_for_non_throttled(controller: WarningController, s
130134    assert  controller ._warning_statistics ["TEST001" ] ==  3 
131135
132136
133- def  test_statistics_throttled_only_once (controller : WarningController , sample_configs : dict [str , WarningConfig ]):
137+ def  test_statistics_throttled_only_once (
138+     controller : WarningController , sample_configs : dict [str , WarningConfig ]
139+ ):
134140    controller .register (sample_configs )
135141
136142    controller .warn (warning_code = "TEST002" , message = "first" )
@@ -140,7 +146,9 @@ def test_statistics_throttled_only_once(controller: WarningController, sample_co
140146    assert  controller ._warning_statistics ["TEST002" ] ==  1 
141147
142148
143- def  test_warn_and_info_do_not_break_with_format_kwargs (controller , sample_configs ):
149+ def  test_warn_and_info_do_not_break_with_format_kwargs (
150+     controller : WarningController , sample_configs : dict [str , WarningConfig ]
151+ ):
144152    controller .register (sample_configs )
145153
146154    controller .warn (
@@ -159,24 +167,39 @@ def test_warn_and_info_do_not_break_with_format_kwargs(controller, sample_config
159167    assert  controller ._warning_statistics ["TEST001" ] ==  2 
160168
161169
162- def  test_unregistered_warning_no_crash_and_no_stats_increment (controller ):
163-     controller .warn (warning_code = "UNKNOWN" , message = "should fallback to default" )
170+ def  test_unregistered_warning_no_crash_and_no_stats_increment (
171+     controller : WarningController ,
172+ ):
173+     controller .warn (
174+         warning_code = "UNKNOWN" , message = "should fallback to default" 
175+     )
164176    controller .info (warning_code = "UNKNOWN" , message = "also fallback" )
165177
166178    assert  "UNKNOWN"  not  in   controller ._warning_statistics 
167179
168180
169- def  test_get_display_message_varies_by_verbosity (sample_configs ):
181+ def  test_get_display_message_varies_by_verbosity (
182+     sample_configs : dict [str , WarningConfig ],
183+ ):
170184    from  zenml .utils .warnings .controller  import  WarningController  as  WC 
185+ 
171186    module_name  =  "mod.path" 
172187    line_number  =  42 
173188
174-     low  =  sample_configs ["TEST001" ].model_copy (update = {"verbosity" : WarningVerbosity .LOW })
175-     med  =  sample_configs ["TEST001" ].model_copy (update = {"verbosity" : WarningVerbosity .MEDIUM })
176-     high  =  sample_configs ["TEST001" ].model_copy (update = {"verbosity" : WarningVerbosity .HIGH })
189+     low  =  sample_configs ["TEST001" ].model_copy (
190+         update = {"verbosity" : WarningVerbosity .LOW }
191+     )
192+     med  =  sample_configs ["TEST001" ].model_copy (
193+         update = {"verbosity" : WarningVerbosity .MEDIUM }
194+     )
195+     high  =  sample_configs ["TEST001" ].model_copy (
196+         update = {"verbosity" : WarningVerbosity .HIGH }
197+     )
177198
178199    msg_low  =  WC ._get_display_message ("hello" , module_name , line_number , low )
179-     assert  msg_low .startswith ("[TEST001](WarningCategory.USAGE)" ) or  msg_low .startswith ("[TEST001](USAGE)" )
200+     assert  msg_low .startswith (
201+         "[TEST001](WarningCategory.USAGE)" 
202+     ) or  msg_low .startswith ("[TEST001](USAGE)" )
180203    assert  "hello"  in  msg_low 
181204    assert  "mod.path"  not  in   msg_low  and  "42"  not  in   msg_low 
182205    assert  low .description  not  in   msg_low 
@@ -191,3 +214,26 @@ def test_get_display_message_varies_by_verbosity(sample_configs):
191214    assert  "[TEST001]"  in  msg_high  and  "hello"  in  msg_high 
192215    assert  "\n "  in  msg_high 
193216    assert  high .description .strip () in  msg_high 
217+ 
218+ 
219+ def  test_combined_registries (
220+     controller : WarningController , sample_configs : dict [str , WarningConfig ]
221+ ):
222+     from  zenml .utils .warnings .registry  import  (
223+         WARNING_CONFIG_REGISTRY ,
224+         WarningCodes ,
225+     )
226+ 
227+     controller .register (sample_configs )
228+     controller .register (WARNING_CONFIG_REGISTRY )
229+ 
230+     assert  WarningCodes .ZML001 .value  in  controller ._warning_configs 
231+     assert  "TEST001"  in  controller ._warning_configs 
232+ 
233+     controller .warn (
234+         warning_code = WarningCodes .ZML001 ,
235+         message = "You are warned {name}" ,
236+         name = "tester" ,
237+     )
238+ 
239+     assert  controller ._warning_statistics ["ZML001" ] >=  1 
0 commit comments