16
16
from argparse import Namespace
17
17
import ltp
18
18
from ltp .sut import SUT
19
- from ltp .tempfile import TempDir
20
19
from ltp .session import Session
21
20
from ltp .ui import SimpleUserInterface
22
21
from ltp .ui import VerboseUserInterface
@@ -136,33 +135,27 @@ def _discover_sut(folder: str) -> list:
136
135
LOADED_SUT .sort (key = lambda x : x .name )
137
136
138
137
139
- def _ltp_run ( parser : ArgumentParser , args : Namespace ) -> None :
138
+ def _get_sut ( sut_name : str ) -> SUT :
140
139
"""
141
- Handle runltp-ng command options .
140
+ Return the SUT with name `sut_name` .
142
141
"""
143
- if args .sut and "help" in args .sut :
144
- print (args .sut ["help" ])
145
- return
146
-
147
- if args .json_report and os .path .exists (args .json_report ):
148
- parser .error (f"JSON report file already exists: { args .json_report } " )
142
+ sut = None
143
+ for mysut in LOADED_SUT :
144
+ if mysut .name == sut_name :
145
+ sut = mysut
146
+ break
149
147
150
- if not args .run_suite and not args .run_cmd :
151
- parser .error ("--run-suite/--run-cmd are required" )
148
+ return sut
152
149
153
- if args .skip_file and not os .path .isfile (args .skip_file ):
154
- parser .error (f"'{ args .skip_file } ' skip file doesn't exist" )
155
-
156
- if args .tmp_dir and not os .path .isdir (args .tmp_dir ):
157
- parser .error (f"'{ args .tmp_dir } ' temporary folder doesn't exist" )
158
150
159
- # create regex of tests to skip
160
- skip_tests = args .skip_tests
161
-
162
- if args .skip_file :
151
+ def _get_skip_tests (skip_tests : str , skip_file : str ) -> str :
152
+ """
153
+ Return the skipped tests regexp.
154
+ """
155
+ if skip_file :
163
156
lines = None
164
- with open (args . skip_file , 'r' , encoding = "utf-8" ) as skip_file :
165
- lines = skip_file .readlines ()
157
+ with open (skip_file , 'r' , encoding = "utf-8" ) as skip_file_data :
158
+ lines = skip_file_data .readlines ()
166
159
167
160
toskip = [
168
161
line .rstrip ()
@@ -171,36 +164,49 @@ def _ltp_run(parser: ArgumentParser, args: Namespace) -> None:
171
164
]
172
165
skip_tests = '|' .join (toskip ) + '|' + skip_tests
173
166
167
+ return skip_tests
168
+
169
+
170
+ def _start_session (parser : ArgumentParser , args : Namespace ) -> None :
171
+ """
172
+ Handle runltp-ng command options.
173
+ """
174
+ # create regex of tests to skip
175
+ skip_tests = _get_skip_tests (args .skip_tests , args .skip_file )
174
176
if skip_tests :
175
177
try :
176
178
re .compile (skip_tests )
177
179
except re .error :
178
180
parser .error (f"'{ skip_tests } ' is not a valid regular expression" )
179
181
180
- ltp .events .start_event_loop ()
182
+ # get the current SUT communication object
183
+ sut_name = args .sut ["name" ]
184
+ sut = _get_sut (sut_name )
185
+ if not sut :
186
+ parser .error (f"'{ sut_name } ' is not an available SUT" )
181
187
182
- if args .verbose :
183
- VerboseUserInterface (args .no_colors )
184
- else :
185
- SimpleUserInterface (args .no_colors )
188
+ ltp .events .start_event_loop ()
186
189
187
190
session = Session (
188
- LOADED_SUT ,
191
+ sut = sut ,
192
+ sut_config = args .sut ,
193
+ tmpdir = args .tmp_dir ,
194
+ ltpdir = args .ltp_dir ,
189
195
suite_timeout = args .suite_timeout ,
190
196
exec_timeout = args .exec_timeout ,
191
- no_colors = args .no_colors )
197
+ no_colors = args .no_colors ,
198
+ skip_tests = skip_tests ,
199
+ env = args .env )
192
200
193
- tmpdir = TempDir (args .tmp_dir )
201
+ if args .verbose :
202
+ VerboseUserInterface (args .no_colors )
203
+ else :
204
+ SimpleUserInterface (args .no_colors )
194
205
195
206
exit_code = session .run_single (
196
- args .sut ,
197
- args .json_report ,
198
- args .run_suite ,
199
- args .run_cmd ,
200
- args .ltp_dir ,
201
- tmpdir ,
202
- skip_tests = skip_tests ,
203
- env = args .env )
207
+ command = args .run_cmd ,
208
+ suites = args .run_suite ,
209
+ report_path = args .json_report )
204
210
205
211
ltp .events .stop_event_loop ()
206
212
@@ -286,7 +292,23 @@ def run() -> None:
286
292
287
293
args = parser .parse_args ()
288
294
289
- _ltp_run (parser , args )
295
+ if args .sut and "help" in args .sut :
296
+ print (args .sut ["help" ])
297
+ return
298
+
299
+ if args .json_report and os .path .exists (args .json_report ):
300
+ parser .error (f"JSON report file already exists: { args .json_report } " )
301
+
302
+ if not args .run_suite and not args .run_cmd :
303
+ parser .error ("--run-suite/--run-cmd are required" )
304
+
305
+ if args .skip_file and not os .path .isfile (args .skip_file ):
306
+ parser .error (f"'{ args .skip_file } ' skip file doesn't exist" )
307
+
308
+ if args .tmp_dir and not os .path .isdir (args .tmp_dir ):
309
+ parser .error (f"'{ args .tmp_dir } ' temporary folder doesn't exist" )
310
+
311
+ _start_session (parser , args )
290
312
291
313
292
314
if __name__ == "__main__" :
0 commit comments