19
19
import os
20
20
from pathlib import Path
21
21
from unittest .mock import MagicMock
22
+ import sys
22
23
23
24
from chip .clusters import Attribute
24
25
from matter_testing_support .matter_testing import MatterStackState , MatterTestConfig , run_tests_no_exit
25
26
26
- # import sys
27
- # try:
28
- # from matter_testing_support.matter_testing import MatterStackState, MatterTestConfig, run_tests_no_exit
29
- # except ImportError:
30
- # sys.path.append(os.path.abspath(
31
- # os.path.join(os.path.dirname(__file__), '..')))
32
- # from matter_testing_support.matter_testing import MatterStackState, MatterTestConfig, run_tests_no_exit
33
-
34
27
35
28
class AsyncMock (MagicMock ):
36
29
async def __call__ (self , * args , ** kwargs ):
@@ -56,7 +49,15 @@ def __init__(self, filename: str, classname: str, test: str, endpoint: int = 0,
56
49
def set_test (self , filename : str , classname : str , test : str ):
57
50
self .test = test
58
51
self .set_test_config ()
59
- module = importlib .import_module (Path (os .path .basename (filename )).stem )
52
+
53
+ module_name = Path (os .path .basename (filename )).stem
54
+
55
+ try :
56
+ module = importlib .import_module (module_name )
57
+ except ModuleNotFoundError :
58
+ sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
59
+ module = importlib .import_module (module_name )
60
+
60
61
self .test_class = getattr (module , classname )
61
62
62
63
def set_test_config (self , test_config : MatterTestConfig = MatterTestConfig ()):
@@ -73,7 +74,7 @@ def set_test_config(self, test_config: MatterTestConfig = MatterTestConfig()):
73
74
def Shutdown (self ):
74
75
self .stack .Shutdown ()
75
76
76
- def run_test_with_mock_read (self , read_cache : Attribute .AsyncReadTransaction .ReadResponse , hooks = None ):
77
+ def run_test_with_mock_read (self , read_cache : Attribute .AsyncReadTransaction .ReadResponse , hooks = None ):
77
78
self .default_controller .Read = AsyncMock (return_value = read_cache )
78
79
# This doesn't need to do anything since we are overriding the read anyway
79
80
self .default_controller .FindOrEstablishPASESession = AsyncMock (return_value = None )
0 commit comments