[tests] use f-strings (##7671)

This commit is contained in:
Mike Fährmann
2025-08-14 10:22:42 +02:00
parent a87c447af2
commit b9429de774
10 changed files with 117 additions and 111 deletions

View File

@@ -234,7 +234,7 @@ class TestExtractorResults(unittest.TestCase):
if isinstance(count, str):
self.assertRegex(
count, r"^ *(==|!=|<|<=|>|>=) *\d+ *$", msg="#count")
expr = "{} {}".format(len_urls, count)
expr = f"{len_urls} {count}"
self.assertTrue(eval(expr), msg=expr)
elif isinstance(count, range):
self.assertRange(len_urls, count, msg="#count")
@@ -284,7 +284,7 @@ class TestExtractorResults(unittest.TestCase):
else:
subtest = False
path = "{}.{}".format(parent, key) if parent else key
path = f"{parent}.{key}" if parent else key
if key.startswith("!"):
self.assertNotIn(key[1:], kwdict, msg=path)
@@ -296,7 +296,7 @@ class TestExtractorResults(unittest.TestCase):
if subtest:
self.assertNotIsInstance(value, str, msg=path)
for idx, item in enumerate(value):
subpath = "{}[{}]".format(path, idx)
subpath = f"{path}[{idx}]"
self._test_kwdict_value(item, test, subpath)
else:
self._test_kwdict_value(value, test, path)
@@ -318,7 +318,7 @@ class TestExtractorResults(unittest.TestCase):
for idx, item in enumerate(test):
if isinstance(item, dict):
subtest = True
subpath = "{}[{}]".format(path, idx)
subpath = f"{path}[{idx}]"
try:
obj = value[idx]
except Exception as exc:
@@ -340,7 +340,7 @@ class TestExtractorResults(unittest.TestCase):
cls, _, length = test[4:].rpartition(":")
if cls:
self.assertEqual(
cls, type(value).__name__, msg=path + "/type")
cls, type(value).__name__, msg=f"{path}/type")
try:
len_value = len(value)
except Exception:
@@ -519,8 +519,7 @@ def load_test_config():
except FileNotFoundError:
pass
except Exception as exc:
sys.exit("Error when loading {}: {}: {}".format(
path, exc.__class__.__name__, exc))
sys.exit(f"Error when loading {path}: {exc.__class__.__name__}: {exc}")
def result_categories(result):
@@ -583,12 +582,12 @@ def generate_tests():
enum = collections.defaultdict(int)
for result in tests:
base, cat, sub = result_categories(result)
name = "{}_{}".format(cat, sub)
name = f"{cat}_{sub}"
enum[name] += 1
method = _generate_method(result)
method.__doc__ = result["#url"]
method.__name__ = "test_{}_{}".format(name, enum[name])
method.__name__ = f"test_{name}_{enum[name]}"
setattr(TestExtractorResults, method.__name__, method)