Skip to content

Commit 8a82252

Browse files
committed
Reformatting
Signed-off-by: Daniel Madej <[email protected]>
1 parent e5913b7 commit 8a82252

File tree

4 files changed

+40
-31
lines changed

4 files changed

+40
-31
lines changed

common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright(c) 2023 Intel Corporation
3+
# Copyright(c) 2024 Huawei Technologies
34
# SPDX-License-Identifier: BSD-3-Clause
45
#
56

@@ -10,9 +11,7 @@
1011
import hashlib
1112
import json
1213
import os
13-
import random
1414
import re
15-
import sys
1615
import time
1716
import yaml
1817

@@ -173,7 +172,7 @@ def duration(self):
173172
start_time = self['start-timestamp']
174173
end_time = self.get('end-timestamp', time.time())
175174
return timedelta(seconds=int(end_time-start_time))
176-
except:
175+
except KeyError:
177176
return timedelta(0)
178177

179178
def __eq__(self, other):
@@ -196,6 +195,7 @@ def new(cls, test_case, data={}):
196195
**data
197196
})
198197

198+
199199
class JournalParser:
200200
def __init__(self, journal_file):
201201
self.journal_file = journal_file

jogger

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
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

910
from datetime import datetime
1011
from functools import reduce
1112
from tabulate import tabulate
1213
from tempfile import NamedTemporaryFile
1314
import argparse
1415
import daemon
15-
import hashlib
1616
import json
1717
import os
1818
import shutil
@@ -27,27 +27,27 @@ def error(*args, **kwargs):
2727
class 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

4545
class 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-
307305
class 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+
328327
usage = """%(prog)s command [args]
329328
330329
Supported 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"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ python-daemon>=2.2.4
33
setproctitle>=1.1.10
44
tabulate>=0.8.7
55
watchdog>=0.10.3
6+
pyyaml>=5.4

runnerd

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

@@ -25,7 +26,6 @@ import os
2526
import sys
2627
import time
2728

28-
2929
logging.basicConfig(
3030
filename="runnerd.log",
3131
level=logging.ERROR,
@@ -39,6 +39,7 @@ scriptdir = os.path.dirname(__file__)
3939
class EventHandler(FileSystemEventHandler):
4040
def __init__(self, callback):
4141
self.callback = callback
42+
4243
def on_modified(self, event):
4344
self.callback()
4445

@@ -95,7 +96,7 @@ class Dut:
9596
def run_in_thread(self, test_event, on_complete):
9697
self.config['meta'] = {
9798
**test_event,
98-
'test-case' : {**test_event['test-case']}
99+
'test-case': {**test_event['test-case']}
99100
}
100101
tmp_conf_file = NamedTemporaryFile(prefix="dut_config_", suffix=".yml")
101102
ConfigFile(tmp_conf_file.name).save(self.config)
@@ -104,9 +105,9 @@ class Dut:
104105
test_case = test_event['test-case']
105106
log.info(f"Start {test_case} @ {self.ip}")
106107
runner = PytestRunner(
107-
test_dir = test_case['dir'],
108-
log_dir = self.log_path,
109-
stdout_path = self.stdout_path
108+
test_dir=test_case['dir'],
109+
log_dir=self.log_path,
110+
stdout_path=self.stdout_path
110111
)
111112
runner.run(tmp_conf_file.name, test_case)
112113
log.info(f"Complete {test_case} @ {self.ip}")
@@ -188,7 +189,7 @@ class TestManager:
188189
def __load_progress(self):
189190
self.test_events_complete.clear()
190191
with self.progress_file.edit() as progress:
191-
if not 'test-events' in progress:
192+
if 'test-events' not in progress:
192193
return
193194
progress['test-events'] = list(filter(
194195
lambda entry: entry['status'] == "complete",
@@ -283,6 +284,7 @@ class MasterRunner:
283284
test_event['end-timestamp'] = time.time()
284285
self.test_manager.mark_complete(test_event)
285286
self.results_collector.collect()
287+
286288
while True:
287289
self.duts_manager.collect_duts()
288290
log.debug("Looking for free DUT... ")
@@ -301,6 +303,7 @@ class ScopeParser:
301303
scope_config_path = "configs/scope_config.yml"
302304

303305
def __init__(self):
306+
self.observer = None
304307
self.scope_config_file = ConfigFile(self.scope_config_path)
305308
self.scope_file = StatusFile("meta/scope.json")
306309

@@ -346,6 +349,7 @@ class ScopeParser:
346349
def stop(self):
347350
self.observer.join()
348351

352+
349353
def daemonize(enabled):
350354
if enabled:
351355
print("Starting daemon")
@@ -355,6 +359,7 @@ def daemonize(enabled):
355359
print("Starting in non-daemon mode")
356360
return contextlib.suppress()
357361

362+
358363
if __name__ == '__main__':
359364
setproctitle('runnerd')
360365
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)