fix f-strings in tests
Hanno Böck

Hanno Böck commited on 2022-01-29 18:06:17
Zeige 3 geänderte Dateien mit 15 Einfügungen und 14 Löschungen.

... ...
@@ -14,7 +14,7 @@ class TestCodingstyle(unittest.TestCase):
14 14
 
15 15
         pylint_disable = "missing-docstring,invalid-name,duplicate-code," \
16 16
                          + "too-many-arguments,consider-using-with"
17
-        subprocess.run(["pylint", "--disable=%s" % pylint_disable]
17
+        subprocess.run(["pylint", f"--disable={pylint_disable}"]
18 18
                        + pyfiles, check=True)
19 19
 
20 20
         subprocess.run(["flake8", "--select=DUO"] + pyfiles, check=True)
... ...
@@ -27,8 +27,9 @@ class TestFreewvsData(unittest.TestCase):
27 27
         for tdir in glob.glob(tmp + "/testdata/webapps/*"):
28 28
             bdir = os.path.basename(tdir)
29 29
             for tarball in glob.glob(tdir + "/dist/*"):
30
-                shutil.unpack_archive(tarball, "%s/%s/%s-src"
31
-                                      % (tmp, bdir, os.path.basename(tarball)))
30
+                tname = os.path.basename(tarball)
31
+                shutil.unpack_archive(tarball,
32
+                                      f"{tmp}/{bdir}/{tname}-src")
32 33
             fwrun = subprocess.run(["./freewvs", "-a", tmp + "/" + bdir],
33 34
                                    stdout=subprocess.PIPE, check=True)
34 35
             fwdata = re.sub(tmp, "[dir]", fwrun.stdout.decode("utf-8"))
... ...
@@ -42,7 +43,7 @@ class TestFreewvsData(unittest.TestCase):
42 43
             if refclean != fwclean:
43 44
                 print("\n".join(difflib.ndiff(refclean, fwclean)))
44 45
             self.assertEqual(refclean, fwclean,
45
-                             msg="Output in %s does not match" % bdir)
46
+                             msg=f"Output in {bdir} does not match")
46 47
 
47 48
         # misc tests, for read errors, garbage data etc.
48 49
         subprocess.run(["./freewvs", "-a", tmp + "/testdata/misc/"],
... ...
@@ -25,7 +25,7 @@ class TestJsonLint(unittest.TestCase):
25 25
             tmp = json.loads(orig)
26 26
             new = json.dumps(tmp, indent=2)
27 27
             if orig != new:
28
-                print("json %s not valid" % f)
28
+                print(f"json {f} not valid")
29 29
                 sys.stdout.writelines(difflib.unified_diff(orig, new))
30 30
                 valid = False
31 31
         self.assertTrue(valid)
... ...
@@ -41,17 +41,16 @@ class TestJsonLint(unittest.TestCase):
41 41
 
42 42
             # check for all mandatory keys
43 43
             self.assertEqual(mkeys.intersection(item.keys()), mkeys,
44
-                             msg="Missing key in %s" % item['name'])
44
+                             msg=f"Missing key in {item['name']}")
45 45
 
46 46
             # check we have at least one detection
47 47
             self.assertTrue(len(item['detection']) >= 1,
48
-                            msg="No detection in %s" % item['name'])
48
+                            msg=f"No detection in {item['name']}")
49 49
 
50 50
             # vuln needs to be CVE or HTTPS URL
51 51
             self.assertTrue(re.match("^CVE-[0-9]*-[0-9]*$", item['vuln'])
52 52
                             or item['vuln'].startswith("https://"),
53
-                            msg="%s: Invalid vuln %s" %
54
-                            (item['name'], item['vuln']))
53
+                            msg=f"{item['name']}: Invalid vuln {item['vuln']}")
55 54
 
56 55
             # make sure old_safe is properly sorted
57 56
             if 'old_safe' in item:
... ...
@@ -59,20 +58,21 @@ class TestJsonLint(unittest.TestCase):
59 58
                 for i in range(1, len(old_safe)):
60 59
                     self.assertTrue(versioncompare(old_safe[i - 1],
61 60
                                                    old_safe[i]),
62
-                                    msg="%s: Invalid old_safe ordering %s" %
63
-                                    (item['name'], item['old_safe']))
61
+                                    msg=f"{item['name']}: Invalid old_safe"
62
+                                        " ordering {item['old_safe']}")
64 63
 
65 64
             # make sure latest is not outdated
66 65
             if 'latest' in item and item['safe'] != "":
67 66
                 self.assertTrue(not versioncompare(item['safe'],
68 67
                                                    item['latest']),
69
-                                msg="%s: Safe version %s newer than latest %s"
70
-                                % (item['name'], item['safe'], item['latest']))
68
+                                msg=f"{item['name']}: Safe version "
69
+                                    "{item['safe']} newer than latest"
70
+                                    " {item['latest']}")
71 71
 
72 72
             # subdir needs to be integer
73 73
             for det in item['detection']:
74 74
                 self.assertTrue(isinstance(det['subdir'], int),
75
-                                msg="%s: subdir not int" % item['name'])
75
+                                msg=f"{item['name']}: subdir not int")
76 76
 
77 77
 
78 78
 if __name__ == '__main__':
79 79