diff options
author | Sebastian Ramacher <s.ramacher@gmx.at> | 2012-06-28 16:13:22 +0200 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2016-04-01 23:53:55 -0700 |
commit | 3e7cff9c20e95f8d0b56e6a17d27fcc8ba5e25cd (patch) | |
tree | d2e18cab59f495489e6265ea5b3dfb717bba9584 | |
parent | 9abcbc10f83c920db2823ce511e45a9f119aff0b (diff) | |
download | pycrypto-3e7cff9c20e95f8d0b56e6a17d27fcc8ba5e25cd.tar.gz |
Run test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ only if _fastmath
is available.
-rw-r--r-- | lib/Crypto/SelfTest/Util/test_number.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Crypto/SelfTest/Util/test_number.py b/lib/Crypto/SelfTest/Util/test_number.py index 0502e9e..bdbc9b1 100644 --- a/lib/Crypto/SelfTest/Util/test_number.py +++ b/lib/Crypto/SelfTest/Util/test_number.py @@ -276,6 +276,11 @@ class MiscTests(unittest.TestCase): self.assertEqual(number.size(0xa2ba40),8*3) self.assertEqual(number.size(0xa2ba40ee07e3b2bd2f02ce227f36a195024486e49c19cb41bbbdfbba98b22b0e577c2eeaffa20d883a76e65e394c69d4b3c05a1e8fadda27edb2a42bc000fe888b9b32c22d15add0cd76b3e7936e19955b220dd17d4ea904b1ec102b2e4de7751222aa99151024c7cb41cc5ea21d00eeb41f7c800834d2c6e06bce3bce7ea9a5L), 1024) +class FastmathTests(unittest.TestCase): + def setUp(self): + global number + from Crypto.Util import number + def test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ(self): """Test that mpzToLongObj and longObjToMPZ (internal functions) roundtrip negative numbers correctly.""" n = -100000000000000000000000000000000000L @@ -286,7 +291,21 @@ class MiscTests(unittest.TestCase): def get_tests(config={}): from Crypto.SelfTest.st_common import list_test_cases - return list_test_cases(MiscTests) + tests = list_test_cases(MiscTests) + try: + from Crypto.PublicKey import _fastmath + tests += list_test_cases(FastmathTests) + except ImportError: + from distutils.sysconfig import get_config_var + import inspect, os.path + _fm_path = os.path.normpath(os.path.dirname(os.path.abspath( + inspect.getfile(inspect.currentframe()))) + +"/../../PublicKey/_fastmath"+get_config_var("SO")) + if os.path.exists(_fm_path): + raise ImportError("While the _fastmath module exists, importing "+ + "it failed. This may point to the gmp or mpir shared library "+ + "not being in the path. _fastmath was found at "+_fm_path) + return tests if __name__ == '__main__': suite = lambda: unittest.TestSuite(get_tests()) |