1717
1818import asyncio
1919import importlib
20- import os
2120import sys
2221from pathlib import Path
2322from unittest .mock import MagicMock
@@ -33,11 +32,12 @@ async def __call__(self, *args, **kwargs):
3332
3433class MockTestRunner ():
3534
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 ):
3737 self .kvs_storage = 'kvs_admin.json'
3838 self .config = MatterTestConfig (endpoint = endpoint , paa_trust_store_path = paa_trust_store_path ,
3939 pics = pics , storage_path = self .kvs_storage )
40- self .set_test (filename , classname , test )
40+ self .set_test (abs_filename , classname , test )
4141
4242 self .set_test_config (self .config )
4343
@@ -48,17 +48,16 @@ def __init__(self, filename: str, classname: str, test: str, endpoint: int = Non
4848 catTags = self .config .controller_cat_tags
4949 )
5050
51- def set_test (self , filename : str , classname : str , test : str ):
51+ def set_test (self , abs_filename : str , classname : str , test : str ):
5252 self .test = test
5353 self .config .tests = [self .test ]
5454
55- module_name = Path (os .path .basename (filename )).stem
56-
5755 try :
58- module = importlib .import_module (module_name )
56+ filename_path = Path (abs_filename )
57+ module = importlib .import_module (filename_path .stem )
5958 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 )
6261
6362 self .test_class = getattr (module , classname )
6463
@@ -72,7 +71,7 @@ def set_test_config(self, test_config: MatterTestConfig = MatterTestConfig()):
7271 def Shutdown (self ):
7372 self .stack .Shutdown ()
7473
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 ):
7675 self .default_controller .Read = AsyncMock (return_value = read_cache )
7776 # This doesn't need to do anything since we are overriding the read anyway
7877 self .default_controller .FindOrEstablishPASESession = AsyncMock (return_value = None )
0 commit comments