17
17
18
18
import asyncio
19
19
import importlib
20
- import os
21
20
import sys
22
21
from pathlib import Path
23
22
from unittest .mock import MagicMock
@@ -33,11 +32,12 @@ async def __call__(self, *args, **kwargs):
33
32
34
33
class MockTestRunner ():
35
34
36
- def __init__ (self , filename : str , classname : str , test : str , endpoint : int = None , pics : dict [str , bool ] = None , paa_trust_store_path = None ):
35
+ def __init__ (self , abs_filename : str , classname : str , test : str , endpoint : int = None ,
36
+ pics : dict [str , bool ] = None , paa_trust_store_path = None ):
37
37
self .kvs_storage = 'kvs_admin.json'
38
38
self .config = MatterTestConfig (endpoint = endpoint , paa_trust_store_path = paa_trust_store_path ,
39
39
pics = pics , storage_path = self .kvs_storage )
40
- self .set_test (filename , classname , test )
40
+ self .set_test (abs_filename , classname , test )
41
41
42
42
self .set_test_config (self .config )
43
43
@@ -48,17 +48,16 @@ def __init__(self, filename: str, classname: str, test: str, endpoint: int = Non
48
48
catTags = self .config .controller_cat_tags
49
49
)
50
50
51
- def set_test (self , filename : str , classname : str , test : str ):
51
+ def set_test (self , abs_filename : str , classname : str , test : str ):
52
52
self .test = test
53
53
self .config .tests = [self .test ]
54
54
55
- module_name = Path (os .path .basename (filename )).stem
56
-
57
55
try :
58
- module = importlib .import_module (module_name )
56
+ filename_path = Path (abs_filename )
57
+ module = importlib .import_module (filename_path .stem )
59
58
except ModuleNotFoundError :
60
- sys .path .append (os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ), '..' )))
61
- module = importlib .import_module (module_name )
59
+ sys .path .append (str ( filename_path . parent . resolve ( )))
60
+ module = importlib .import_module (filename_path . stem )
62
61
63
62
self .test_class = getattr (module , classname )
64
63
@@ -72,7 +71,7 @@ def set_test_config(self, test_config: MatterTestConfig = MatterTestConfig()):
72
71
def Shutdown (self ):
73
72
self .stack .Shutdown ()
74
73
75
- def run_test_with_mock_read (self , read_cache : Attribute .AsyncReadTransaction .ReadResponse , hooks = None ):
74
+ def run_test_with_mock_read (self , read_cache : Attribute .AsyncReadTransaction .ReadResponse , hooks = None ):
76
75
self .default_controller .Read = AsyncMock (return_value = read_cache )
77
76
# This doesn't need to do anything since we are overriding the read anyway
78
77
self .default_controller .FindOrEstablishPASESession = AsyncMock (return_value = None )
0 commit comments