Skip to content

Commit

Permalink
Fix verbosity problem in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Sep 17, 2023
1 parent 18ca871 commit 87ff663
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ jobs:
shell: bash
run: |
if [[ -f .separate_namespace ]]; then
python -m Cryptodome.SelfTest
python -m Cryptodome.SelfTest -v
else
python -m Crypto.SelfTest
python -m Crypto.SelfTest -v
fi
mypy:
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions lib/Crypto/SelfTest/Protocol/test_ecdh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
29 changes: 17 additions & 12 deletions lib/Crypto/SelfTest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
11 changes: 8 additions & 3 deletions lib/Crypto/SelfTest/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@

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")

wycheproof_warnings = "--wycheproof-warnings" in sys.argv
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)

0 comments on commit 87ff663

Please sign in to comment.