@@ -39,7 +39,6 @@ def setUp(self):
39
39
self .skipTest ("OpenVINO not available" )
40
40
41
41
def test_get_device_returns_valid_device (self ):
42
- """Test that get_device returns a valid device."""
43
42
device = get_device ()
44
43
45
44
self .assertIn (device , ["GPU" , "CPU" ])
@@ -48,14 +47,12 @@ def test_get_device_returns_valid_device(self):
48
47
self .assertIn (device , core .available_devices )
49
48
50
49
def test_get_device_consistency (self ):
51
- """Test that get_device returns consistent results."""
52
50
device1 = get_device ()
53
51
device2 = get_device ()
54
52
55
53
self .assertEqual (device1 , device2 )
56
54
57
55
def test_compile_model_with_mock_params (self ):
58
- """Test compile_model function interface with mocking."""
59
56
# We mock the OpenVINO components because
60
57
# creating real OpenVINO operations
61
58
# is complex and requires proper parameter
@@ -103,7 +100,6 @@ def output(self):
103
100
mock_core .compile_model .assert_called_once ()
104
101
105
102
def test_compile_model_precision_hints (self ):
106
- """Test compile_model with different precision hints."""
107
103
# Mock the entire compilation process to test precision hint behavior
108
104
with unittest .mock .patch (
109
105
"keras_hub.src.utils.openvino_utils.ov.Model"
@@ -150,8 +146,6 @@ def output(self):
150
146
self .assertEqual (mock_core .compile_model .call_count , 2 )
151
147
152
148
def test_get_outputs_basic_functionality (self ):
153
- """Test get_outputs with a mocked compiled model."""
154
-
155
149
# Mock result needs to_tuple() method as expected by get_outputs
156
150
class MockResult :
157
151
def __init__ (self , data ):
@@ -195,7 +189,6 @@ def mock_unpack_singleton(x):
195
189
np .testing .assert_array_almost_equal (outputs , expected )
196
190
197
191
def test_ov_infer_model_caching (self ):
198
- """Test that ov_infer properly handles model caching attributes."""
199
192
# Use current device to match ov_infer's device check for caching
200
193
current_device = get_device ()
201
194
@@ -235,8 +228,6 @@ def mock_fn(struct_params, stop_token_ids):
235
228
self .assertIsNotNone (result )
236
229
237
230
def test_ov_infer_dtype_selection (self ):
238
- """Test that ov_infer handles different dtypes correctly."""
239
-
240
231
class MockModel :
241
232
def __init__ (self , dtype ):
242
233
self .dtype = dtype
@@ -284,7 +275,6 @@ def mock_fn(struct_params, stop_token_ids):
284
275
self .assertEqual (args [3 ], expected_ov_dtype )
285
276
286
277
def test_load_openvino_supported_tools_valid_file (self ):
287
- """Test loading supported tools from a valid file."""
288
278
with tempfile .NamedTemporaryFile (
289
279
mode = "w" , delete = False , suffix = ".txt"
290
280
) as f :
@@ -308,12 +298,10 @@ def test_load_openvino_supported_tools_valid_file(self):
308
298
os .unlink (temp_file )
309
299
310
300
def test_load_openvino_supported_tools_nonexistent_file (self ):
311
- """Test loading supported tools from a nonexistent file."""
312
301
result = load_openvino_supported_tools ("/nonexistent/file.txt" )
313
302
self .assertEqual (result , [])
314
303
315
304
def test_load_openvino_supported_tools_empty_file (self ):
316
- """Test loading supported tools from an empty file."""
317
305
with tempfile .NamedTemporaryFile (
318
306
mode = "w" , delete = False , suffix = ".txt"
319
307
) as f :
@@ -325,38 +313,21 @@ def test_load_openvino_supported_tools_empty_file(self):
325
313
finally :
326
314
os .unlink (temp_file )
327
315
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
-
339
316
def test_setup_openvino_test_config_openvino_backend (self ):
340
- """Test setup_openvino_test_config with OpenVINO backend."""
341
317
with tempfile .TemporaryDirectory () as temp_dir :
342
318
config_file = os .path .join (temp_dir , "openvino_supported_tests.txt" )
343
319
with open (config_file , "w" ) as f :
344
320
f .write ("keras_hub/src/models/gemma\n " )
345
321
f .write ("keras_hub/src/tokenizers\n " )
346
322
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 )
356
329
357
330
def test_contains_training_methods_with_training_code (self ):
358
- """Test _contains_training_methods with file containing training
359
- methods."""
360
331
training_code = """
361
332
import keras
362
333
@@ -384,7 +355,6 @@ def test_other_method():
384
355
os .unlink (temp_file )
385
356
386
357
def test_contains_training_methods_nonexistent_file (self ):
387
- """Test _contains_training_methods with nonexistent file."""
388
358
result = _contains_training_methods (
389
359
"/nonexistent/file.py" , "test_method"
390
360
)
@@ -393,8 +363,6 @@ def test_contains_training_methods_nonexistent_file(self):
393
363
self .assertTrue (result )
394
364
395
365
def test_should_auto_skip_training_test_non_python_file (self ):
396
- """Test should_auto_skip_training_test with non-Python file."""
397
-
398
366
class MockItem :
399
367
def __init__ (self , fspath ):
400
368
self .fspath = type ("MockPath" , (), {"basename" : fspath })()
@@ -404,51 +372,7 @@ def __init__(self, fspath):
404
372
result = should_auto_skip_training_test (item )
405
373
self .assertFalse (result )
406
374
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
-
450
375
def test_should_auto_skip_training_test_with_training_methods (self ):
451
- """Test should_auto_skip_training_test with training methods."""
452
376
training_code = """
453
377
def test_fit_method():
454
378
model.fit(x, y)
@@ -476,57 +400,31 @@ def __init__(self, fspath, name):
476
400
self .name = name
477
401
478
402
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 )
485
405
finally :
486
406
os .unlink (temp_file )
487
407
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
-
503
408
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
-
507
409
class MockItem :
508
410
def __init__ (self , test_name ):
509
411
self .name = test_name
510
412
self .fspath = type ("MockPath" , (), {})()
511
413
setattr (self .fspath , "__str__" , lambda : "test_file.py" )
512
414
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 )
527
426
528
427
def test_get_openvino_skip_reason_training_skip (self ):
529
- """Test get_openvino_skip_reason with training methods."""
530
428
training_code = """
531
429
def test_training_method():
532
430
model.fit(x, y)
@@ -554,18 +452,12 @@ def __init__(self, fspath, name):
554
452
self .name = name
555
453
556
454
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" )
563
457
finally :
564
458
os .unlink (temp_file )
565
459
566
460
def test_get_openvino_skip_reason_whitelist_supported (self ):
567
- """Test get_openvino_skip_reason with supported path in whitelist."""
568
-
569
461
class MockFspath :
570
462
def __init__ (self , path ):
571
463
self .path = path
@@ -584,17 +476,10 @@ def __init__(self, fspath, name):
584
476
supported_paths = ["keras_hub/src/models/gemma" ]
585
477
586
478
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 )
593
481
594
482
def test_get_openvino_skip_reason_whitelist_not_supported (self ):
595
- """Test get_openvino_skip_reason with unsupported path not in
596
- whitelist."""
597
-
598
483
class MockFspath :
599
484
def __init__ (self , path ):
600
485
self .path = path
@@ -613,16 +498,10 @@ def __init__(self, fspath, name):
613
498
supported_paths = ["keras_hub/src/models/gemma" ]
614
499
615
500
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" )
622
503
623
504
def test_get_openvino_skip_reason_no_whitelist (self ):
624
- """Test get_openvino_skip_reason with empty whitelist."""
625
-
626
505
class MockFspath :
627
506
def __init__ (self , path ):
628
507
self .path = path
@@ -637,11 +516,6 @@ def __init__(self, fspath, name):
637
516
self .name = name
638
517
639
518
test_path = "/some/path/keras_hub/src/models/gemma/gemma_test.py"
640
-
641
519
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