13
13
# limitations under the License.
14
14
15
15
import os
16
- import tempfile
17
16
import unittest
17
+ import tempfile
18
18
from typing import List
19
19
20
- from metadata import MetadataReader
21
-
20
+ from metadata import MetadataReader , Metadata
22
21
23
22
class TestMetadataReader (unittest .TestCase ):
24
23
@@ -39,47 +38,40 @@ class TestMetadataReader(unittest.TestCase):
39
38
TRACE_TEST_PERFETTO: out/trace_data/test-{SCRIPT_BASE_NAME}
40
39
'''
41
40
41
+ expected_metadata = Metadata (
42
+ script_args = "--commissioning-method on-network --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto" ,
43
+ py_script_path = "" ,
44
+ app_args = "--discriminator 1234 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" ,
45
+ run = "run1" ,
46
+ app = "out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app" ,
47
+ factoryreset = True
48
+ )
49
+
42
50
def generate_temp_file (self , directory : str , file_content : str ) -> str :
43
51
fd , temp_file_path = tempfile .mkstemp (dir = directory )
44
52
with os .fdopen (fd , 'w' ) as fp :
45
53
fp .write (file_content )
46
54
return temp_file_path
47
55
48
- def generate_run_commands (self , reader : MetadataReader , script_path : str ) -> List [str ]:
49
- metadata_list = reader .parse_script (script_path )
50
- commands = []
51
-
52
- for metadata in metadata_list :
53
- cmd = (
54
- "scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py "
55
- f"--app { metadata .app } "
56
- f"{ '--factoryreset' if metadata .factoryreset else '' } "
57
- f"--app-args \" { metadata .app_args } \" "
58
- f"--script \" { metadata .py_script_path } \" "
59
- f"--script-args \" { metadata .script_args } \" '"
60
- )
61
- commands .append (cmd .strip ())
62
-
63
- return commands
64
-
65
56
def test_run_arg_generation (self ):
66
57
with tempfile .TemporaryDirectory () as temp_dir :
67
58
temp_file = self .generate_temp_file (temp_dir , self .test_file_content )
68
59
env_file = self .generate_temp_file (temp_dir , self .env_file_content )
69
-
60
+
70
61
reader = MetadataReader (env_file )
71
62
self .maxDiff = None
72
-
63
+
73
64
test_file_expected_arg_string = (
74
65
"scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py "
75
66
"--app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app "
76
67
"--factoryreset --app-args \" --discriminator 1234 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json\" "
77
68
"--script \" " + temp_file + "\" --script-args \" --commissioning-method on-network "
78
69
"--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto\" '"
79
70
)
80
-
81
- actual = self .generate_run_commands (reader , temp_file )[0 ]
82
- self .assertEqual (test_file_expected_arg_string , actual )
71
+
72
+ self .expected_metadata .py_script_path = temp_file
73
+ actual = reader .parse_script (temp_file )[0 ]
74
+ self .assertEqual (self .expected_metadata , actual )
83
75
84
76
85
77
if __name__ == "__main__" :
0 commit comments