Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up unit test runner: import+call rather than use subprocess.Pop…

…en()
  • Loading branch information...
commit 9e21c3388cc98ba90877a1e4dbc2aaf66c67d365 1 parent 6430bb7
@warner authored
View
5 ecdsa/ecdsa.py
@@ -263,7 +263,7 @@ def point_is_valid( generator, x, y ):
-if __name__ == "__main__":
+def __main__():
class TestFailure(Exception): pass
def test_point_validity( generator, x, y, expected ):
@@ -555,3 +555,6 @@ def test_signature_validity( Msg, Qx, Qy, R, S, expected ):
raise TestFailure( "**** Demo verification failed to reject tampered hash.")
else:
print "Demo verification correctly rejected tampered hash."
+
+if __name__ == "__main__":
+ __main__()
View
5 ecdsa/ellipticcurve.py
@@ -178,7 +178,7 @@ def order( self ):
# This one point is the Point At Infinity for all purposes:
INFINITY = Point( None, None, None )
-if __name__ == "__main__":
+def __main__():
class FailedTest(Exception): pass
def test_add( c, x1, y1, x2, y2, x3, y3 ):
@@ -285,3 +285,6 @@ def test_multiply( c, x1, y1, m, x3, y3 ):
raise FailedTest("u1 * p192 + u2 * Q came out wrong.")
else:
print "u1 * p192 + u2 * Q came out right."
+
+if __name__ == "__main__":
+ __main__()
View
6 ecdsa/numbertheory.py
@@ -492,8 +492,8 @@ def next_prime( starting_value ):
miller_rabin_test_count = 0
-if __name__ == '__main__':
-
+def __main__():
+
# Making sure locally defined exceptions work:
# p = modular_exp( 2, -2, 3 )
# p = square_root_mod_prime( 2, 3 )
@@ -610,3 +610,5 @@ class FailedTest(Exception): pass
if error_tally != 0:
raise FailedTest("%d errors detected" % error_tally)
+if __name__ == '__main__':
+ __main__()
View
4 ecdsa/test_pyecdsa.py
@@ -437,5 +437,7 @@ def OFF_test_prove_uniformity(self):
print "%3d: %s" % (i, "*"*(counts[i]//100))
-if __name__ == "__main__":
+def __main__():
unittest.main()
+if __name__ == "__main__":
+ __main__()
View
28 setup.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import os, sys, subprocess, re
+import os, subprocess, re
from distutils.core import setup, Command
from distutils.command.sdist import sdist as _sdist
@@ -13,23 +13,15 @@ def initialize_options(self):
def finalize_options(self):
pass
def run(self):
- for t in ["ecdsa/numbertheory.py",
- "ecdsa/ellipticcurve.py",
- "ecdsa/ecdsa.py",
- "ecdsa/test_pyecdsa.py",
- ]:
- rc = self.do_test(t)
- if rc != 0:
- sys.exit(rc)
-
- def do_test(self, which):
- print "======= running %s" % which
- p = subprocess.Popen([sys.executable, which])
- rc = p.wait()
- if rc != 0:
- print >>sys.stderr, "Test (%s) FAILED" % which
- print "== finished %s" % which
- return rc
+ from ecdsa import numbertheory
+ numbertheory.__main__()
+ from ecdsa import ellipticcurve
+ ellipticcurve.__main__()
+ from ecdsa import ecdsa
+ ecdsa.__main__()
+ from ecdsa import test_pyecdsa
+ test_pyecdsa.unittest.main(module=test_pyecdsa, argv=["dummy"])
+ # all tests os.exit(1) upon failure
VERSION_PY = """
# This file is originally generated from Git information by running 'setup.py
Please sign in to comment.
Something went wrong with that request. Please try again.