11#!/usr/bin/env python3
22#
33# Copyright(c) 2023 Intel Corporation
4+ # Copyright(c) 2024 Huawei Technologies
45# SPDX-License-Identifier: BSD-3-Clause
56#
67
7- from common import ConfigFile , JournalFile , StatusFile , TestCase , TestEvent , JournalParser
8+ from common import JournalFile , StatusFile , TestCase , TestEvent , JournalParser
89
910from datetime import datetime
1011from functools import reduce
1112from tabulate import tabulate
1213from tempfile import NamedTemporaryFile
1314import argparse
1415import daemon
15- import hashlib
1616import json
1717import os
1818import shutil
@@ -27,27 +27,27 @@ def error(*args, **kwargs):
2727class Printer :
2828 @staticmethod
2929 def red (string ):
30- return "\033 [0;31m" + string + "\033 [0m"
30+ return "\033 [0;31m" + string + "\033 [0m"
3131
3232 @staticmethod
3333 def green (string ):
34- return "\033 [0;32m" + string + "\033 [0m"
34+ return "\033 [0;32m" + string + "\033 [0m"
3535
3636 @staticmethod
3737 def yellow (string ):
38- return "\033 [0;33m" + string + "\033 [0m"
38+ return "\033 [0;33m" + string + "\033 [0m"
3939
4040 @staticmethod
4141 def blue (string ):
42- return "\033 [0;34m" + string + "\033 [0m"
42+ return "\033 [0;34m" + string + "\033 [0m"
4343
4444
4545class DataPrinter :
4646 def __init__ (self , output_format = 'table' ):
4747 if output_format not in ['table' , 'json' ]:
4848 raise ValueError (f"Invalid output format '{ output_format } '" )
4949 self .output_format = output_format
50- self .caption = None
50+ self .captions = None
5151 self .data = None
5252
5353 def setCaptions (self , captions ):
@@ -188,7 +188,7 @@ class ScopeHandler:
188188 )
189189
190190 def run (self , req ):
191- tests = reduce (lambda acc , sha : acc + self .__tests_by_sha (sha ), req , [])
191+ tests = reduce (lambda acc , sha : acc + self .__tests_by_sha (sha ), req , [])
192192 test_events = []
193193 with self .journal_file .record () as journal :
194194 for test_case in tests :
@@ -238,7 +238,6 @@ class ScopeHandler:
238238 for res in results :
239239 results_dict [res ['sha' ]] = res
240240
241- scope_status = []
242241 for test_case in tests :
243242 queued_events = filter (
244243 lambda e : e ['test-case' ] == test_case ,
@@ -303,7 +302,6 @@ class ScopeHandler:
303302 )
304303
305304
306-
307305class TestSelector :
308306 def __init__ (self , tests ):
309307 self .tests = tests
@@ -325,6 +323,7 @@ class TestSelector:
325323 tmpf .seek (0 )
326324 return [line .split ()[0 ] for line in tmpf .readlines ()]
327325
326+
328327usage = """%(prog)s command [args]
329328
330329Supported commands:
@@ -355,13 +354,15 @@ class SuperRunnerCli:
355354 self .scope_handler = ScopeHandler ()
356355 getattr (self , command )(f"{ parser .prog } { args .command } " , argv [1 :])
357356
358- def __color_result (self , string ):
357+ @staticmethod
358+ def __color_result (string ):
359359 return {
360360 'PASSED' : Printer .green ,
361361 'FAILED' : Printer .red ,
362362 }.get (string , Printer .yellow )(string )
363363
364- def __print_test_events (self , args , test_events ):
364+ @staticmethod
365+ def __print_test_events (args , test_events ):
365366 p = ListPrinter (args .format )
366367 id_field = ('id' , 'sha' )[args .long ]
367368 test_field = ('function' , 'test' )[args .long ]
@@ -383,16 +384,17 @@ class SuperRunnerCli:
383384 })
384385 p .print ()
385386
386- def init (self , prog , argv ):
387+ @staticmethod
388+ def init (prog , argv ):
387389 parser = argparse .ArgumentParser (
388390 prog = prog ,
389391 description = "Initialize new test scope"
390392 )
391- args = parser .parse_args (argv )
393+ _ = parser .parse_args (argv )
392394
393395 runner_path = os .getenv ('RUNNER_PATH' )
394396 if not runner_path :
395- error ("Enrvironment variable 'RUNNER_PATH' is not set!" )
397+ error ("Environment variable 'RUNNER_PATH' is not set!" )
396398 exit (1 )
397399 if os .path .isdir ("meta" ):
398400 error ("Existing runner scope found in this directory!" )
@@ -426,7 +428,7 @@ class SuperRunnerCli:
426428 'sha' : test_case ['sha' ],
427429 'function' : test_case .function (),
428430 'test' : test_case .test ()
429- })
431+ })
430432 p .print ()
431433
432434 def run (self , prog , argv ):
@@ -487,7 +489,7 @@ class SuperRunnerCli:
487489 args = parser .parse_args (argv )
488490
489491 test_event = self .scope_handler .test_event_by_sha ({'sha' : args .id })
490- deleted_event = self .scope_handler .delete ({'test-event' : test_event })
492+ self .scope_handler .delete ({'test-event' : test_event })
491493
492494 def queue (self , prog , argv ):
493495 parser = argparse .ArgumentParser (
@@ -556,8 +558,8 @@ class SuperRunnerCli:
556558 last_event_result = self .__color_result (last_event ['result' ])
557559 last_event_id = last_event ['sha' ][:16 ]
558560 last_event_sha = last_event ['sha' ]
559- last_event_date = datetime .fromtimestamp (last_event ['end-timestamp' ]) \
560- .strftime ("%Y-%m-%d %H:%M:%S" )
561+ last_event_date = ( datetime .fromtimestamp (last_event ['end-timestamp' ])
562+ .strftime ("%Y-%m-%d %H:%M:%S" ) )
561563 except :
562564 last_event_result = last_event_id = last_event_sha = last_event_date = ""
563565 p .addEntry ({
@@ -571,7 +573,7 @@ class SuperRunnerCli:
571573 'last-result-id' : last_event_id ,
572574 'last-result-sha' : last_event_sha ,
573575 'last-result-date' : last_event_date
574- })
576+ })
575577 p .print ()
576578
577579 def results (self , prog , argv ):
@@ -620,7 +622,7 @@ class SuperRunnerCli:
620622 'test' : test_case .test (),
621623 'result' : self .__color_result (test_event ['result' ]),
622624 'duration' : test_event .duration ()
623- })
625+ })
624626 p .print ()
625627
626628 def show (self , prog , argv ):
@@ -701,7 +703,8 @@ class SuperRunnerCli:
701703 with daemon .DaemonContext ():
702704 webbrowser .open_new_tab (os .path .join (test_case ['logs' ], "main.html" ))
703705
704- def stdout (self , prog , argv ):
706+ @staticmethod
707+ def stdout (prog , argv ):
705708 parser = argparse .ArgumentParser (
706709 prog = prog ,
707710 description = "Show pytest standard output on selected DUT"
0 commit comments