summaryrefslogtreecommitdiff
path: root/dev-python/pycryptodome/files/pycryptodome-3.19.0-fix-verbosity-in-tests.patch
blob: 7d54e5e4c2a70b8a9030c09b2c8ce44e02bc5314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
https://github.com/Legrandin/pycryptodome/issues/765
https://github.com/Legrandin/pycryptodome/commit/87ff66373a5b80cddc9b0dd76e9bb8c15f6a8e50

From 87ff66373a5b80cddc9b0dd76e9bb8c15f6a8e50 Mon Sep 17 00:00:00 2001
From: Helder Eijs <helderijs@gmail.com>
Date: Sun, 17 Sep 2023 23:32:02 +0200
Subject: [PATCH] Fix verbosity problem in tests

--- a/lib/Crypto/SelfTest/Protocol/test_ecdh.py
+++ b/lib/Crypto/SelfTest/Protocol/test_ecdh.py
@@ -72,6 +72,8 @@ def ecdh_test_rev(self,
 
 class TestVectorsECDHWycheproof(unittest.TestCase):
 
+    desc = "Wycheproof ECDH tests"
+
     def add_tests(self, filename):
 
         def curve(g):
@@ -107,7 +109,6 @@ def shortDescription(self):
         return self.desc
 
     def test_verify(self, tv):
-        self._id = "Wycheproof ECDH Verify Test #%d (%s, %s)" % (tv.id, tv.comment, tv.filename)
 
         if len(tv.public) == 0:
             return
@@ -138,7 +139,7 @@ def test_verify(self, tv):
 
     def runTest(self):
         for tv in self.tv:
-            self.desc = "Test #%d (%s) - %s" % (tv.id, tv.filename, tv.comment)
+            self.desc = "Wycheproof ECDH Verify Test #%d (%s, %s)" % (tv.id, tv.comment, tv.filename)
             self.test_verify(tv)
 
 
--- a/lib/Crypto/SelfTest/__init__.py
+++ b/lib/Crypto/SelfTest/__init__.py
@@ -28,18 +28,19 @@
 application runs.
 """
 
-__revision__ = "$Id$"
-
 import sys
 import unittest
+from importlib import import_module
 from Crypto.Util.py3compat import StringIO
 
+
 class SelfTestError(Exception):
     def __init__(self, message, result):
         Exception.__init__(self, message, result)
         self.message = message
         self.result = result
 
+
 def run(module=None, verbosity=0, stream=None, tests=None, config=None, **kwargs):
     """Execute self-tests.
 
@@ -77,21 +78,25 @@ def run(module=None, verbosity=0, stream=None, tests=None, config=None, **kwargs
         raise SelfTestError("Self-test failed", result)
     return result
 
+
 def get_tests(config={}):
     tests = []
-    from Crypto.SelfTest import Cipher; tests += Cipher.get_tests(config=config)
-    from Crypto.SelfTest import Hash;   tests += Hash.get_tests(config=config)
-    from Crypto.SelfTest import Protocol; tests += Protocol.get_tests(config=config)
-    from Crypto.SelfTest import PublicKey; tests += PublicKey.get_tests(config=config)
-    from Crypto.SelfTest import Random; tests += Random.get_tests(config=config)
-    from Crypto.SelfTest import Util;   tests += Util.get_tests(config=config)
-    from Crypto.SelfTest import Signature;   tests += Signature.get_tests(config=config)
-    from Crypto.SelfTest import IO;   tests += IO.get_tests(config=config)
-    from Crypto.SelfTest import Math;   tests += Math.get_tests(config=config)
+
+    module_names = [
+        "Cipher", "Hash", "Protocol", "PublicKey", "Random",
+        "Util", "Signature", "IO", "Math",
+        ]
+
+    for name in module_names:
+        module = import_module("Crypto.SelfTest." + name)
+        tests += module.get_tests(config=config)
+
     return tests
 
+
 if __name__ == '__main__':
-    suite = lambda: unittest.TestSuite(get_tests())
+    def suite():
+        return unittest.TestSuite(get_tests())
     unittest.main(defaultTest='suite')
 
 # vim:set ts=4 sw=4 sts=4 expandtab:
--- a/lib/Crypto/SelfTest/__main__.py
+++ b/lib/Crypto/SelfTest/__main__.py
@@ -26,7 +26,7 @@
 
 from Crypto import SelfTest
 
-slow_tests = not "--skip-slow-tests" in sys.argv
+slow_tests = not ("--skip-slow-tests" in sys.argv)
 if not slow_tests:
     print("Skipping slow tests")
 
@@ -34,5 +34,10 @@
 if wycheproof_warnings:
     print("Printing Wycheproof warnings")
 
-config = {'slow_tests' : slow_tests, 'wycheproof_warnings' : wycheproof_warnings }
-SelfTest.run(stream=sys.stdout, verbosity=1, config=config)
+if "-v" in sys.argv:
+    verbosity=2
+else:
+    verbosity=1
+
+config = {'slow_tests': slow_tests, 'wycheproof_warnings': wycheproof_warnings}
+SelfTest.run(stream=sys.stdout, verbosity=verbosity, config=config)