From 90c49c83a0f89bf4fadea63e1a1d795eda2978e1 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 16 Jan 2025 00:39:20 +0100 Subject: [PATCH] test/crossrunner: merge in old Py2vs3 compat.py --- test/crossrunner/compat.py | 7 ------- test/crossrunner/report.py | 21 ++++++++++++--------- test/crossrunner/run.py | 3 +-- test/crossrunner/test.py | 5 ++--- 4 files changed, 15 insertions(+), 21 deletions(-) delete mode 100644 test/crossrunner/compat.py diff --git a/test/crossrunner/compat.py b/test/crossrunner/compat.py deleted file mode 100644 index a670c33f266..00000000000 --- a/test/crossrunner/compat.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -path_join = os.path.join -str_join = str.join - -def logfile_open(*args): - return open(*args, errors='replace') diff --git a/test/crossrunner/report.py b/test/crossrunner/report.py index 7e1b0c747e9..9231a8b1ace 100644 --- a/test/crossrunner/report.py +++ b/test/crossrunner/report.py @@ -28,7 +28,6 @@ import time import traceback -from .compat import logfile_open, path_join, str_join from .test import TestEntry LOG_DIR = 'log' @@ -37,6 +36,10 @@ FAIL_JSON = 'known_failures_%s.json' +def logfile_open(*args): + return open(*args, errors='replace') + + def generate_known_failures(testdir, overwrite, save, out): def collect_failures(results): success_index = 5 @@ -44,7 +47,7 @@ def collect_failures(results): if not r[success_index]: yield TestEntry.get_name(*r) try: - with logfile_open(path_join(testdir, RESULT_JSON), 'r') as fp: + with logfile_open(os.path.join(testdir, RESULT_JSON), 'r') as fp: results = json.load(fp) except IOError: sys.stderr.write('Unable to load last result. Did you run tests ?\n') @@ -67,7 +70,7 @@ def collect_failures(results): def load_known_failures(testdir): try: - with logfile_open(path_join(testdir, FAIL_JSON % platform.system()), 'r') as fp: + with logfile_open(os.path.join(testdir, FAIL_JSON % platform.system()), 'r') as fp: return json.load(fp) except IOError: return [] @@ -84,8 +87,8 @@ def __init__(self): @classmethod def test_logfile(cls, test_name, prog_kind, dir=None): - relpath = path_join('log', '%s_%s.log' % (test_name, prog_kind)) - return relpath if not dir else os.path.realpath(path_join(dir, relpath)) + relpath = os.path.join('log', '%s_%s.log' % (test_name, prog_kind)) + return relpath if not dir else os.path.realpath(os.path.join(dir, relpath)) def _start(self): self._start_time = time.time() @@ -199,7 +202,7 @@ def _close(self): def _print_header(self): self._print_date() - print('Executing: %s' % str_join(' ', self._prog.command), file=self.out) + print('Executing: %s' % ' '.join(self._prog.command), file=self.out) print('Directory: %s' % self._prog.workdir, file=self.out) print('config:delay: %s' % self._test.delay, file=self.out) print('config:timeout: %s' % self._test.timeout, file=self.out) @@ -221,8 +224,8 @@ def __init__(self, basedir, testdir_relative, concurrent=True): super(SummaryReporter, self).__init__() self._basedir = basedir self._testdir_rel = testdir_relative - self.logdir = path_join(self.testdir, LOG_DIR) - self.out_path = path_join(self.testdir, RESULT_JSON) + self.logdir = os.path.join(self.testdir, LOG_DIR) + self.out_path = os.path.join(self.testdir, RESULT_JSON) self.concurrent = concurrent self.out = sys.stdout self._platform = platform.system() @@ -239,7 +242,7 @@ def __init__(self, basedir, testdir_relative, concurrent=True): @property def testdir(self): - return path_join(self._basedir, self._testdir_rel) + return os.path.join(self._basedir, self._testdir_rel) def _result_string(self, test): if test.success: diff --git a/test/crossrunner/run.py b/test/crossrunner/run.py index 126b7ec886a..3ccc6e32bd3 100644 --- a/test/crossrunner/run.py +++ b/test/crossrunner/run.py @@ -28,7 +28,6 @@ import sys import time -from .compat import str_join from .report import ExecReporter, SummaryReporter from .test import TestEntry from .util import domain_socket_path @@ -72,7 +71,7 @@ def _popen_args(self): return args def start(self): - joined = str_join(' ', self.cmd) + joined = ' '.join(self.cmd) self._log.debug('COMMAND: %s', joined) self._log.debug('WORKDIR: %s', self.cwd) self._log.debug('LOGFILE: %s', self.report.logpath) diff --git a/test/crossrunner/test.py b/test/crossrunner/test.py index 0e912843ab7..2a1a4da7c48 100644 --- a/test/crossrunner/test.py +++ b/test/crossrunner/test.py @@ -21,7 +21,6 @@ import multiprocessing import os import sys -from .compat import path_join from .util import merge_dict, domain_socket_path @@ -50,7 +49,7 @@ def __init__(self, kind, name, protocol, transport, socket, workdir, stop_signal def _fix_cmd_path(self, cmd): # if the arg is a file in the current directory, make it path def abs_if_exists(arg): - p = path_join(self.workdir, arg) + p = os.path.join(self.workdir, arg) return p if os.path.exists(p) else arg if cmd[0] == 'python': @@ -125,7 +124,7 @@ def _fix_workdir(self, config): if os.path.isabs(path): path = os.path.realpath(path) else: - path = os.path.realpath(path_join(self.testdir, path)) + path = os.path.realpath(os.path.join(self.testdir, path)) config.update({key: path}) return config