You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by dr...@apache.org on 2007/12/02 23:09:43 UTC

svn commit: r600387 - in /labs/badca: Makefile.in openssl/csrmodule.c tests/CSRTestCase.py tests/KeysTestCase.py tests/runTests.py

Author: dreid
Date: Sun Dec  2 14:09:41 2007
New Revision: 600387

URL: http://svn.apache.org/viewvc?rev=600387&view=rev
Log:
Add a script to run all the tests we add.
Return an exception for some error cases in the CSR extension
Change Makefile.in to use the new script

To add a new test script, just use the existing filenames as
a template and all should be fine.

Added:
    labs/badca/tests/CSRTestCase.py
    labs/badca/tests/runTests.py   (with props)
Modified:
    labs/badca/Makefile.in
    labs/badca/openssl/csrmodule.c
    labs/badca/tests/KeysTestCase.py

Modified: labs/badca/Makefile.in
URL: http://svn.apache.org/viewvc/labs/badca/Makefile.in?rev=600387&r1=600386&r2=600387&view=diff
==============================================================================
--- labs/badca/Makefile.in (original)
+++ labs/badca/Makefile.in Sun Dec  2 14:09:41 2007
@@ -10,5 +10,5 @@
 
 test:
 	PYTHONPATH="@EXT_PATH@:$$PYTHONPATH" \
-	@PYTHON@ @top_srcdir@/tests/KeysTestCase.py
+	@PYTHON@ @top_srcdir@/tests/runTests.py @top_srcdir@/tests
 

Modified: labs/badca/openssl/csrmodule.c
URL: http://svn.apache.org/viewvc/labs/badca/openssl/csrmodule.c?rev=600387&r1=600386&r2=600387&view=diff
==============================================================================
--- labs/badca/openssl/csrmodule.c (original)
+++ labs/badca/openssl/csrmodule.c Sun Dec  2 14:09:41 2007
@@ -49,12 +49,14 @@
         return NULL;
 
     in = BIO_new(BIO_s_file());
-    if (!in)
+    if (!in) {
+        PyErr_SetString(PyExc_MemoryError, "Unable to create a BIO object");
         return NULL;
-
+    }
     
     if (BIO_read_filename(in, fn) <= 0) {
         BIO_free_all(in);
+        PyErr_SetString(PyExc_IOError, "Unable to read CSR from filename");
         return NULL;
     }
 

Added: labs/badca/tests/CSRTestCase.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/CSRTestCase.py?rev=600387&view=auto
==============================================================================
--- labs/badca/tests/CSRTestCase.py (added)
+++ labs/badca/tests/CSRTestCase.py Sun Dec  2 14:09:41 2007
@@ -0,0 +1,21 @@
+import unittest
+
+from BaDCA import Keys, CSRs
+
+class BaDCAKeysTestCase(unittest.TestCase):
+    obj = None
+
+    def setUp(self):
+        """ Called prior to every test """
+        if self.obj is None:
+            self.obj = CSRs.CSR()
+        else:
+            self.Reset()
+
+    def testRead(self):
+        assert self.obj.readFromFile('tests/csr/test1.csr') == 1, \
+                                                "Failed to read the CSR"
+
+
+if __name__ == "__main__":
+    unittest.main()

Modified: labs/badca/tests/KeysTestCase.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/KeysTestCase.py?rev=600387&r1=600386&r2=600387&view=diff
==============================================================================
--- labs/badca/tests/KeysTestCase.py (original)
+++ labs/badca/tests/KeysTestCase.py Sun Dec  2 14:09:41 2007
@@ -43,6 +43,11 @@
         assert self.obj.hasPublic(), "Public key not available??"
         assert self.obj.hasPrivate(), "Private key not available??"
 
+    def suite():
+        suite = unittest.TestSuite()
+        suite.addTest(BaDCAKeysTestCase("testCreation"))
+        suite.addTest(BaDCAKeysTestCase("testInvalidCreation"))
+        return suite
 
 if __name__ == "__main__":
     unittest.main()

Added: labs/badca/tests/runTests.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/runTests.py?rev=600387&view=auto
==============================================================================
--- labs/badca/tests/runTests.py (added)
+++ labs/badca/tests/runTests.py Sun Dec  2 14:09:41 2007
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import re
+import imp
+
+import unittest
+
+class badcaTester():
+    directory = None
+    fileMatcher = None
+    loader = unittest.defaultTestLoader
+    testRunner = None
+
+    def __init__(self):
+        self.fileMatcher = re.compile("^\S*TestCase\.py$")
+        if len(sys.argv) != 2:
+            self.exitUsage('You MUST supply a directory to scan')
+        if not os.path.isdir(sys.argv[1]):
+            self.exitUsage('You must supply a directory to scan')
+        self.directory = os.path.abspath(sys.argv[1])
+        files = os.listdir(self.directory)
+        for f in files:
+            if self.fileMatcher.match(f):
+                print "\nRunning tests in " + f + "\n"
+                tests = self.getSuitesFromFilename(f)
+                if tests is not None:
+                    self.runTests(tests)
+
+    def getSuitesFromFilename(self, filename):
+        f = re.compile("(\S*)\.py").match(filename)
+        if f is not None:
+            filename = f.group(1)
+        file, pathname, description = imp.find_module(filename)
+        module = imp.load_module(filename, file, pathname, description)
+        if module is None:
+            return None
+        return self.loader.loadTestsFromModule(module)
+
+    def runTests(self, tests):
+        if self.testRunner is None:
+            self.testRunner = unittest.TextTestRunner(verbosity=2)
+        result = self.testRunner.run(tests)
+        if not result.wasSuccessful():
+            sys.exit(1)
+ 
+    def exitUsage(self, msg = None):
+        print """
+Usage: runTests.py <directory>
+"""
+        if msg is not None:
+            print "Error: %s" % msg
+        sys.exit(2)
+
+main = badcaTester
+    
+if __name__ == "__main__":
+    main()

Propchange: labs/badca/tests/runTests.py
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org