Reformat python code style with black

This commit is contained in:
Kate Hsuan 2025-01-07 15:52:06 +08:00
parent 2678cb00d4
commit 17e5903670
4 changed files with 3143 additions and 1708 deletions

View file

@ -3,24 +3,38 @@
from lxml import etree from lxml import etree
import sys import sys
def format_title(title): def format_title(title):
"""Put title in a box""" """Put title in a box"""
box = { box = {
'tl': '', 'tr': '', 'bl': '', 'br': '', 'h': '', 'v': '', "tl": "",
"tr": "",
"bl": "",
"br": "",
"h": "",
"v": "",
} }
hline = box['h'] * (len(title) + 2) hline = box["h"] * (len(title) + 2)
return "\n".join(
[
f"{box['tl']}{hline}{box['tr']}",
f"{box['v']} {title} {box['v']}",
f"{box['bl']}{hline}{box['br']}",
]
)
return '\n'.join([
f"{box['tl']}{hline}{box['tr']}",
f"{box['v']} {title} {box['v']}",
f"{box['bl']}{hline}{box['br']}",
])
# The log coloring causes the XML to be invalid, so set recover=True # The log coloring causes the XML to be invalid, so set recover=True
tree = etree.parse(sys.argv[1], etree.XMLParser(recover=True)) tree = etree.parse(sys.argv[1], etree.XMLParser(recover=True))
for suite in tree.xpath('/testsuites/testsuite'): for suite in tree.xpath("/testsuites/testsuite"):
skipped = suite.get('skipped') skipped = suite.get("skipped")
if int(skipped) != 0: if int(skipped) != 0:
print(format_title('Tests were skipped when they should not have been. All the tests must be run in the CI'), print(
end='\n\n', flush=True) format_title(
"Tests were skipped when they should not have been. All the tests must be run in the CI"
),
end="\n\n",
flush=True,
)
sys.exit(1) sys.exit(1)

File diff suppressed because it is too large Load diff

View file

@ -26,21 +26,27 @@ import threading
import select import select
import errno import errno
class OutputChecker(object):
class OutputChecker(object):
def __init__(self, out=sys.stdout): def __init__(self, out=sys.stdout):
self._output = out self._output = out
self._pipe_fd_r, self._pipe_fd_w = os.pipe() self._pipe_fd_r, self._pipe_fd_w = os.pipe()
self._partial_buf = b'' self._partial_buf = b""
self._lines_sem = threading.Semaphore() self._lines_sem = threading.Semaphore()
self._lines = [] self._lines = []
self._reader_io = io.StringIO() self._reader_io = io.StringIO()
# Just to be sure, shouldn't be a problem even if we didn't set it # Just to be sure, shouldn't be a problem even if we didn't set it
fcntl.fcntl(self._pipe_fd_r, fcntl.F_SETFL, fcntl.fcntl(
fcntl.fcntl(self._pipe_fd_r, fcntl.F_GETFL) | os.O_CLOEXEC | os.O_NONBLOCK) self._pipe_fd_r,
fcntl.fcntl(self._pipe_fd_w, fcntl.F_SETFL, fcntl.F_SETFL,
fcntl.fcntl(self._pipe_fd_w, fcntl.F_GETFL) | os.O_CLOEXEC) fcntl.fcntl(self._pipe_fd_r, fcntl.F_GETFL) | os.O_CLOEXEC | os.O_NONBLOCK,
)
fcntl.fcntl(
self._pipe_fd_w,
fcntl.F_SETFL,
fcntl.fcntl(self._pipe_fd_w, fcntl.F_GETFL) | os.O_CLOEXEC,
)
# Start copier thread # Start copier thread
self._thread = threading.Thread(target=self._copy, daemon=True) self._thread = threading.Thread(target=self._copy, daemon=True)
@ -73,7 +79,7 @@ class OutputChecker(object):
self._lines_sem.release() self._lines_sem.release()
return return
l = r.split(b'\n') l = r.split(b"\n")
l[0] = self._partial_buf + l[0] l[0] = self._partial_buf + l[0]
self._lines.extend(l[:-1]) self._lines.extend(l[:-1])
self._partial_buf = l[-1] self._partial_buf = l[-1]
@ -86,7 +92,7 @@ class OutputChecker(object):
deadline = time.time() + timeout deadline = time.time() + timeout
if isinstance(needle_re, str): if isinstance(needle_re, str):
needle_re = needle_re.encode('ascii') needle_re = needle_re.encode("ascii")
r = re.compile(needle_re) r = re.compile(needle_re)
ret = [] ret = []
@ -98,16 +104,23 @@ class OutputChecker(object):
# EOF, throw error # EOF, throw error
if self._pipe_fd_r == -1: if self._pipe_fd_r == -1:
if failmsg: if failmsg:
raise AssertionError("No further messages: " % failmsg) from None raise AssertionError(
"No further messages: " % failmsg
) from None
else: else:
raise AssertionError('No client waiting for needle %s' % (str(needle_re))) from None raise AssertionError(
"No client waiting for needle %s" % (str(needle_re))
) from None
# Check if should wake up # Check if should wake up
if not self._lines_sem.acquire(timeout = deadline - time.time()): if not self._lines_sem.acquire(timeout=deadline - time.time()):
if failmsg: if failmsg:
raise AssertionError(failmsg) from None raise AssertionError(failmsg) from None
else: else:
raise AssertionError('Timed out waiting for needle %s (timeout: %0.2f)' % (str(needle_re), timeout)) from None raise AssertionError(
"Timed out waiting for needle %s (timeout: %0.2f)"
% (str(needle_re), timeout)
) from None
continue continue
ret.append(l) ret.append(l)
@ -116,7 +129,7 @@ class OutputChecker(object):
def check_line(self, needle, timeout=0, failmsg=None): def check_line(self, needle, timeout=0, failmsg=None):
if isinstance(needle, str): if isinstance(needle, str):
needle = needle.encode('ascii') needle = needle.encode("ascii")
needle_re = re.escape(needle) needle_re = re.escape(needle)
@ -126,7 +139,7 @@ class OutputChecker(object):
deadline = time.time() + wait deadline = time.time() + wait
if isinstance(needle_re, str): if isinstance(needle_re, str):
needle_re = needle_re.encode('ascii') needle_re = needle_re.encode("ascii")
r = re.compile(needle_re) r = re.compile(needle_re)
ret = [] ret = []
@ -140,7 +153,7 @@ class OutputChecker(object):
break break
# Check if should wake up # Check if should wake up
if not self._lines_sem.acquire(timeout = deadline - time.time()): if not self._lines_sem.acquire(timeout=deadline - time.time()):
# Timed out, so everything is good # Timed out, so everything is good
break break
continue continue
@ -150,13 +163,16 @@ class OutputChecker(object):
if failmsg: if failmsg:
raise AssertionError(failmsg) raise AssertionError(failmsg)
else: else:
raise AssertionError('Found needle %s but shouldn\'t have been there (timeout: %0.2f)' % (str(needle_re), wait)) raise AssertionError(
"Found needle %s but shouldn't have been there (timeout: %0.2f)"
% (str(needle_re), wait)
)
return ret return ret
def check_no_line(self, needle, wait=0, failmsg=None): def check_no_line(self, needle, wait=0, failmsg=None):
if isinstance(needle, str): if isinstance(needle, str):
needle = needle.encode('ascii') needle = needle.encode("ascii")
needle_re = re.escape(needle) needle_re = re.escape(needle)
@ -174,7 +190,6 @@ class OutputChecker(object):
raise AssertionError("OutputCheck: Write side has not been closed yet!") raise AssertionError("OutputCheck: Write side has not been closed yet!")
def force_close(self): def force_close(self):
fd = self._pipe_fd_r fd = self._pipe_fd_r
self._pipe_fd_r = -1 self._pipe_fd_r = -1
if fd >= 0: if fd >= 0:

View file

@ -22,23 +22,25 @@ import inspect
import os import os
import unittest import unittest
def list_tests(module): def list_tests(module):
tests = [] tests = []
for name, obj in inspect.getmembers(module): for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and issubclass(obj, unittest.TestCase): if inspect.isclass(obj) and issubclass(obj, unittest.TestCase):
cases = unittest.defaultTestLoader.getTestCaseNames(obj) cases = unittest.defaultTestLoader.getTestCaseNames(obj)
tests += [ (obj, '{}.{}'.format(name, t)) for t in cases ] tests += [(obj, "{}.{}".format(name, t)) for t in cases]
return tests return tests
if __name__ == '__main__': if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('unittest_source', type=argparse.FileType('r')) parser.add_argument("unittest_source", type=argparse.FileType("r"))
args = parser.parse_args() args = parser.parse_args()
source_path = args.unittest_source.name source_path = args.unittest_source.name
spec = importlib.util.spec_from_file_location( spec = importlib.util.spec_from_file_location(
os.path.basename(source_path), source_path) os.path.basename(source_path), source_path
)
module = importlib.util.module_from_spec(spec) module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) spec.loader.exec_module(module)