@@ -39,7 +39,6 @@ def setUp(self):
3939            self .skipTest ("OpenVINO not available" )
4040
4141    def  test_get_device_returns_valid_device (self ):
42-         """Test that get_device returns a valid device.""" 
4342        device  =  get_device ()
4443
4544        self .assertIn (device , ["GPU" , "CPU" ])
@@ -48,14 +47,12 @@ def test_get_device_returns_valid_device(self):
4847        self .assertIn (device , core .available_devices )
4948
5049    def  test_get_device_consistency (self ):
51-         """Test that get_device returns consistent results.""" 
5250        device1  =  get_device ()
5351        device2  =  get_device ()
5452
5553        self .assertEqual (device1 , device2 )
5654
5755    def  test_compile_model_with_mock_params (self ):
58-         """Test compile_model function interface with mocking.""" 
5956        # We mock the OpenVINO components because 
6057        # creating real OpenVINO operations 
6158        # is complex and requires proper parameter 
@@ -103,7 +100,6 @@ def output(self):
103100                mock_core .compile_model .assert_called_once ()
104101
105102    def  test_compile_model_precision_hints (self ):
106-         """Test compile_model with different precision hints.""" 
107103        # Mock the entire compilation process to test precision hint behavior 
108104        with  unittest .mock .patch (
109105            "keras_hub.src.utils.openvino_utils.ov.Model" 
@@ -150,8 +146,6 @@ def output(self):
150146                self .assertEqual (mock_core .compile_model .call_count , 2 )
151147
152148    def  test_get_outputs_basic_functionality (self ):
153-         """Test get_outputs with a mocked compiled model.""" 
154- 
155149        # Mock result needs to_tuple() method as expected by get_outputs 
156150        class  MockResult :
157151            def  __init__ (self , data ):
@@ -195,7 +189,6 @@ def mock_unpack_singleton(x):
195189        np .testing .assert_array_almost_equal (outputs , expected )
196190
197191    def  test_ov_infer_model_caching (self ):
198-         """Test that ov_infer properly handles model caching attributes.""" 
199192        # Use current device to match ov_infer's device check for caching 
200193        current_device  =  get_device ()
201194
@@ -235,8 +228,6 @@ def mock_fn(struct_params, stop_token_ids):
235228        self .assertIsNotNone (result )
236229
237230    def  test_ov_infer_dtype_selection (self ):
238-         """Test that ov_infer handles different dtypes correctly.""" 
239- 
240231        class  MockModel :
241232            def  __init__ (self , dtype ):
242233                self .dtype  =  dtype 
@@ -284,7 +275,6 @@ def mock_fn(struct_params, stop_token_ids):
284275                        self .assertEqual (args [3 ], expected_ov_dtype )
285276
286277    def  test_load_openvino_supported_tools_valid_file (self ):
287-         """Test loading supported tools from a valid file.""" 
288278        with  tempfile .NamedTemporaryFile (
289279            mode = "w" , delete = False , suffix = ".txt" 
290280        ) as  f :
@@ -308,12 +298,10 @@ def test_load_openvino_supported_tools_valid_file(self):
308298            os .unlink (temp_file )
309299
310300    def  test_load_openvino_supported_tools_nonexistent_file (self ):
311-         """Test loading supported tools from a nonexistent file.""" 
312301        result  =  load_openvino_supported_tools ("/nonexistent/file.txt" )
313302        self .assertEqual (result , [])
314303
315304    def  test_load_openvino_supported_tools_empty_file (self ):
316-         """Test loading supported tools from an empty file.""" 
317305        with  tempfile .NamedTemporaryFile (
318306            mode = "w" , delete = False , suffix = ".txt" 
319307        ) as  f :
@@ -325,38 +313,21 @@ def test_load_openvino_supported_tools_empty_file(self):
325313        finally :
326314            os .unlink (temp_file )
327315
328-     def  test_setup_openvino_test_config_non_openvino_backend (self ):
329-         """Test setup_openvino_test_config with non-OpenVINO backend.""" 
330-         try :
331-             with  unittest .mock .patch (
332-                 "keras.config.backend" , return_value = "tensorflow" 
333-             ):
334-                 result  =  setup_openvino_test_config ("/some/path" )
335-                 self .assertEqual (result , [])
336-         finally :
337-             pass 
338- 
339316    def  test_setup_openvino_test_config_openvino_backend (self ):
340-         """Test setup_openvino_test_config with OpenVINO backend.""" 
341317        with  tempfile .TemporaryDirectory () as  temp_dir :
342318            config_file  =  os .path .join (temp_dir , "openvino_supported_tests.txt" )
343319            with  open (config_file , "w" ) as  f :
344320                f .write ("keras_hub/src/models/gemma\n " )
345321                f .write ("keras_hub/src/tokenizers\n " )
346322
347-             with  unittest .mock .patch (
348-                 "keras.config.backend" , return_value = "openvino" 
349-             ):
350-                 result  =  setup_openvino_test_config (temp_dir )
351-                 expected  =  [
352-                     "keras_hub/src/models/gemma" ,
353-                     "keras_hub/src/tokenizers" ,
354-                 ]
355-                 self .assertEqual (result , expected )
323+             result  =  setup_openvino_test_config (temp_dir )
324+             expected  =  [
325+                 "keras_hub/src/models/gemma" ,
326+                 "keras_hub/src/tokenizers" ,
327+             ]
328+             self .assertEqual (result , expected )
356329
357330    def  test_contains_training_methods_with_training_code (self ):
358-         """Test _contains_training_methods with file containing training 
359-         methods.""" 
360331        training_code  =  """ 
361332        import keras 
362333
@@ -384,7 +355,6 @@ def test_other_method():
384355            os .unlink (temp_file )
385356
386357    def  test_contains_training_methods_nonexistent_file (self ):
387-         """Test _contains_training_methods with nonexistent file.""" 
388358        result  =  _contains_training_methods (
389359            "/nonexistent/file.py" , "test_method" 
390360        )
@@ -393,8 +363,6 @@ def test_contains_training_methods_nonexistent_file(self):
393363        self .assertTrue (result )
394364
395365    def  test_should_auto_skip_training_test_non_python_file (self ):
396-         """Test should_auto_skip_training_test with non-Python file.""" 
397- 
398366        class  MockItem :
399367            def  __init__ (self , fspath ):
400368                self .fspath  =  type ("MockPath" , (), {"basename" : fspath })()
@@ -404,51 +372,7 @@ def __init__(self, fspath):
404372        result  =  should_auto_skip_training_test (item )
405373        self .assertFalse (result )
406374
407-     def  test_should_auto_skip_training_test_non_openvino_backend (self ):
408-         """Test should_auto_skip_training_test function behavior. 
409- 
410-         Note: This function doesn't check the backend - it only analyzes 
411-         code for training methods. Backend checking is done in 
412-         get_openvino_skip_reason.""" 
413- 
414-         # Create a temporary file with simple test code (no training methods) 
415-         simple_test_code  =  """ 
416- def test_method(): 
417-     # A simple test without training methods 
418-     assert True 
419- """ 
420-         with  tempfile .NamedTemporaryFile (
421-             mode = "w" , delete = False , suffix = ".py" 
422-         ) as  f :
423-             f .write (simple_test_code )
424-             temp_file  =  f .name 
425- 
426-         try :
427- 
428-             class  MockFspath :
429-                 def  __init__ (self , path ):
430-                     self .path  =  path 
431-                     self .basename  =  os .path .basename (path )
432- 
433-                 def  __str__ (self ):
434-                     return  self .path 
435- 
436-             class  MockItem :
437-                 def  __init__ (self , fspath , name ):
438-                     self .fspath  =  MockFspath (fspath )
439-                     self .name  =  name 
440- 
441-             item  =  MockItem (temp_file , "test_method" )
442- 
443-             # This function should return False for a simple test without 
444-             # training methods, regardless of backend 
445-             result  =  should_auto_skip_training_test (item )
446-             self .assertFalse (result )
447-         finally :
448-             os .unlink (temp_file )
449- 
450375    def  test_should_auto_skip_training_test_with_training_methods (self ):
451-         """Test should_auto_skip_training_test with training methods.""" 
452376        training_code  =  """ 
453377        def test_fit_method(): 
454378            model.fit(x, y) 
@@ -476,57 +400,31 @@ def __init__(self, fspath, name):
476400                    self .name  =  name 
477401
478402            item  =  MockItem (temp_file , "test_fit_method" )
479- 
480-             with  unittest .mock .patch (
481-                 "keras.config.backend" , return_value = "openvino" 
482-             ):
483-                 result  =  should_auto_skip_training_test (item )
484-                 self .assertTrue (result )
403+             result  =  should_auto_skip_training_test (item )
404+             self .assertTrue (result )
485405        finally :
486406            os .unlink (temp_file )
487407
488-     def  test_get_openvino_skip_reason_non_openvino_backend (self ):
489-         """Test get_openvino_skip_reason with non-OpenVINO backend.""" 
490- 
491-         class  MockItem :
492-             def  __init__ (self ):
493-                 self .name  =  "test_method" 
494-                 self .fspath  =  type ("MockPath" , (), {})()
495- 
496-         item  =  MockItem ()
497-         with  unittest .mock .patch (
498-             "keras.config.backend" , return_value = "tensorflow" 
499-         ):
500-             result  =  get_openvino_skip_reason (item , [], True )
501-             self .assertIsNone (result )
502- 
503408    def  test_get_openvino_skip_reason_specific_test_skip (self ):
504-         """Test get_openvino_skip_reason with specific test methods that 
505-         should be skipped.""" 
506- 
507409        class  MockItem :
508410            def  __init__ (self , test_name ):
509411                self .name  =  test_name 
510412                self .fspath  =  type ("MockPath" , (), {})()
511413                setattr (self .fspath , "__str__" , lambda : "test_file.py" )
512414
513-         with  unittest .mock .patch (
514-             "keras.config.backend" , return_value = "openvino" 
515-         ):
516-             # Define expected skip reasons matching the implementation 
517-             expected_reasons  =  {
518-                 "test_backbone_basics" : "Requires trainable backend" ,
519-                 "test_score_loss" : "Non-implemented roll operation" ,
520-                 "test_layer_behaviors" : "Requires trainable backend" ,
521-             }
522- 
523-             for  test_name , expected_reason  in  expected_reasons .items ():
524-                 item  =  MockItem (test_name )
525-                 result  =  get_openvino_skip_reason (item , [], True )
526-                 self .assertEqual (result , expected_reason )
415+         # Define expected skip reasons matching the implementation 
416+         expected_reasons  =  {
417+             "test_backbone_basics" : "Requires trainable backend" ,
418+             "test_score_loss" : "Non-implemented roll operation" ,
419+             "test_layer_behaviors" : "Requires trainable backend" ,
420+         }
421+ 
422+         for  test_name , expected_reason  in  expected_reasons .items ():
423+             item  =  MockItem (test_name )
424+             result  =  get_openvino_skip_reason (item , [], True )
425+             self .assertEqual (result , expected_reason )
527426
528427    def  test_get_openvino_skip_reason_training_skip (self ):
529-         """Test get_openvino_skip_reason with training methods.""" 
530428        training_code  =  """ 
531429        def test_training_method(): 
532430            model.fit(x, y) 
@@ -554,18 +452,12 @@ def __init__(self, fspath, name):
554452                    self .name  =  name 
555453
556454            item  =  MockItem (temp_file , "test_training_method" )
557- 
558-             with  unittest .mock .patch (
559-                 "keras.config.backend" , return_value = "openvino" 
560-             ):
561-                 result  =  get_openvino_skip_reason (item , [], True )
562-                 self .assertEqual (result , "Training operations not supported" )
455+             result  =  get_openvino_skip_reason (item , [], True )
456+             self .assertEqual (result , "Training operations not supported" )
563457        finally :
564458            os .unlink (temp_file )
565459
566460    def  test_get_openvino_skip_reason_whitelist_supported (self ):
567-         """Test get_openvino_skip_reason with supported path in whitelist.""" 
568- 
569461        class  MockFspath :
570462            def  __init__ (self , path ):
571463                self .path  =  path 
@@ -584,17 +476,10 @@ def __init__(self, fspath, name):
584476        supported_paths  =  ["keras_hub/src/models/gemma" ]
585477
586478        item  =  MockItem (test_path , "test_inference" )
587- 
588-         with  unittest .mock .patch (
589-             "keras.config.backend" , return_value = "openvino" 
590-         ):
591-             result  =  get_openvino_skip_reason (item , supported_paths , False )
592-             self .assertIsNone (result )
479+         result  =  get_openvino_skip_reason (item , supported_paths , False )
480+         self .assertIsNone (result )
593481
594482    def  test_get_openvino_skip_reason_whitelist_not_supported (self ):
595-         """Test get_openvino_skip_reason with unsupported path not in 
596-         whitelist.""" 
597- 
598483        class  MockFspath :
599484            def  __init__ (self , path ):
600485                self .path  =  path 
@@ -613,16 +498,10 @@ def __init__(self, fspath, name):
613498        supported_paths  =  ["keras_hub/src/models/gemma" ]
614499
615500        item  =  MockItem (test_path , "test_inference" )
616- 
617-         with  unittest .mock .patch (
618-             "keras.config.backend" , return_value = "openvino" 
619-         ):
620-             result  =  get_openvino_skip_reason (item , supported_paths , False )
621-             self .assertEqual (result , "File/directory not in OpenVINO whitelist" )
501+         result  =  get_openvino_skip_reason (item , supported_paths , False )
502+         self .assertEqual (result , "File/directory not in OpenVINO whitelist" )
622503
623504    def  test_get_openvino_skip_reason_no_whitelist (self ):
624-         """Test get_openvino_skip_reason with empty whitelist.""" 
625- 
626505        class  MockFspath :
627506            def  __init__ (self , path ):
628507                self .path  =  path 
@@ -637,11 +516,6 @@ def __init__(self, fspath, name):
637516                self .name  =  name 
638517
639518        test_path  =  "/some/path/keras_hub/src/models/gemma/gemma_test.py" 
640- 
641519        item  =  MockItem (test_path , "test_inference" )
642- 
643-         with  unittest .mock .patch (
644-             "keras.config.backend" , return_value = "openvino" 
645-         ):
646-             result  =  get_openvino_skip_reason (item , [], False )
647-             self .assertIsNone (result )
520+         result  =  get_openvino_skip_reason (item , [], False )
521+         self .assertIsNone (result )
0 commit comments