qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1442085 - in /qpid/proton/trunk/tests: java/org/apache/qpid/proton/JythonTest.java python/proton-test
Date Mon, 04 Feb 2013 11:53:02 GMT
Author: kwall
Date: Mon Feb  4 11:53:02 2013
New Revision: 1442085

URL: http://svn.apache.org/viewvc?rev=1442085&view=rev
Log:
PROTON-196: Enable XML formatted output from python tests for better intergration with Maven/Jenkins

Also:

* Junit xml output now uses <skipped/> element to indicate a skipped test
* Junit xml output now includes message and type attributes on <failure/> element (Maven
surefire module requires these).

Modified:
    qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java
    qpid/proton/trunk/tests/python/proton-test

Modified: qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java?rev=1442085&r1=1442084&r2=1442085&view=diff
==============================================================================
--- qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java (original)
+++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java Mon Feb  4 11:53:02
2013
@@ -42,6 +42,9 @@ public class JythonTest
 {
     private static final Logger LOGGER = Logger.getLogger(JythonTest.class.getName());
 
+    private static final String XML_REPORT_DIRECTORY = "surefire-reports";
+    private static final String XML_REPORT_NAME = "TEST-jython.xml";
+
     private static final String TEST_PATTERN_SYSTEM_PROPERTY = "proton.pythontest.pattern";
     private static final String PROTON_TEST_SCRIPT_CLASSPATH_LOCATION = "/proton-test";
 
@@ -50,8 +53,9 @@ public class JythonTest
     {
         File protonScriptFile = getPythonTestScript();
         String parentDirectory = protonScriptFile.getParent();
+        File xmlReportDirectory = getOptionalXmlReportDirectory(protonScriptFile);
 
-        PythonInterpreter interp = createInterpreterWithArgs();
+        PythonInterpreter interp = createInterpreterWithArgs(xmlReportDirectory);
 
         LOGGER.info("About to call Jython test script: " + protonScriptFile + " with parent
directory added to Jython path");
 
@@ -85,14 +89,23 @@ public class JythonTest
         }
     }
 
-    private PythonInterpreter createInterpreterWithArgs()
+    private PythonInterpreter createInterpreterWithArgs(File xmlReportDirectory)
     {
         PySystemState systemState = new PySystemState();
         String testPattern = System.getProperty(TEST_PATTERN_SYSTEM_PROPERTY);
+
+        if (xmlReportDirectory != null)
+        {
+            String xmlReportFile = new File(xmlReportDirectory, XML_REPORT_NAME).getAbsolutePath();
+            systemState.argv.append(new PyString("--xml"));
+            systemState.argv.append(new PyString(xmlReportFile));
+        }
+
         if(testPattern != null)
         {
             systemState.argv.append(new PyString(testPattern));
         }
+
         PythonInterpreter interp = new PythonInterpreter(null, systemState);
         return interp;
     }
@@ -103,4 +116,19 @@ public class JythonTest
         File protonScriptFile = new File(protonScriptUrl.toURI());
         return protonScriptFile;
     }
+
+    private File getOptionalXmlReportDirectory(File protonScriptFile)
+    {
+        File reportDirectory = new File(protonScriptFile.getParentFile().getParentFile(),
XML_REPORT_DIRECTORY);
+        if (reportDirectory.isDirectory())
+        {
+            return reportDirectory;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
 }

Modified: qpid/proton/trunk/tests/python/proton-test
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/python/proton-test?rev=1442085&r1=1442084&r2=1442085&view=diff
==============================================================================
--- qpid/proton/trunk/tests/python/proton-test (original)
+++ qpid/proton/trunk/tests/python/proton-test Mon Feb  4 11:53:02 2013
@@ -20,7 +20,7 @@
 
 # TODO: summarize, test harness preconditions (e.g. broker is alive)
 
-import logging, optparse, os, struct, sys, time, traceback, types
+import logging, optparse, os, struct, sys, time, traceback, types, cgi
 from fnmatch import fnmatchcase as match
 from getopt import GetoptError
 from logging import getLogger, StreamHandler, Formatter, Filter, \
@@ -189,7 +189,7 @@ class JunitXmlStyleReporter:
 
   def begin(self):
     self.f.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
-    self.f.write('<testsuite>\n')
+    self.f.write('<testsuite name="pythontests">\n')
 
   def report(self, name, result):
     parts = name.split(".")
@@ -197,11 +197,15 @@ class JunitXmlStyleReporter:
     module = '.'.join(parts[0:-1])
     self.f.write('<testcase classname="%s" name="%s" time="%f">\n' % (module, method,
result.time))
     if result.failed:
-      self.f.write('<failure>\n')
+      escaped_type = cgi.escape(str(result.exception_type))
+      escaped_message = cgi.escape(str(result.exception_message))
+      self.f.write('<failure type="%s" message="%s">\n' % (escaped_type, escaped_message))
       self.f.write('<![CDATA[\n')
-      self.f.write(result.exceptions)
+      self.f.write(result.formatted_exception_trace)
       self.f.write(']]>\n')
       self.f.write('</failure>\n')
+    if result.skipped:
+      self.f.write('<skipped/>\n')
     self.f.write('</testcase>\n')
 
   def end(self):
@@ -313,6 +317,8 @@ class Runner:
   def __init__(self):
     self.exceptions = []
     self.skip = False
+    self.exception_type = None
+    self.exception_message = None
 
   def passed(self):
     return not self.exceptions
@@ -333,6 +339,7 @@ class Runner:
       raise
     except:
       exi = sys.exc_info()
+      self.exception_type, self.exception_message = exi[0:2]
       self.skip = getattr(exi[0], "skipped", False)
       self.exceptions.append((name, exi))
 
@@ -346,7 +353,7 @@ class Runner:
     else:
       return None
 
-  def get_formatted_exceptions(self):
+  def get_formatted_exception_trace(self):
     for name, info in self.exceptions:
       if getattr(info[0], "skipped", False):
         output = indent("".join(traceback.format_exception_only(*info[:2]))).rstrip()
@@ -355,6 +362,12 @@ class Runner:
         output += indent("".join(traceback.format_exception(*info))).rstrip()
       return output
 
+  def get_exception_type(self):
+    return self.exception_type
+
+  def get_exception_message(self):
+    return self.exception_message
+
 ST_WIDTH = 8
 
 def run_test(name, test, config):
@@ -393,19 +406,27 @@ def run_test(name, test, config):
     sys.stdout.write(output)
   print " %s" % colorize_word(runner.status())
   if runner.failed() or runner.skipped():
-    print runner.get_formatted_exceptions()
+    print runner.get_formatted_exception_trace()
   root.setLevel(level)
   filter.patterns = patterns
-  return TestResult(end - start, runner.passed(), runner.skipped(), runner.failed(), runner.get_formatted_exceptions())
+  return TestResult(end - start,
+                    runner.passed(),
+                    runner.skipped(),
+                    runner.failed(),
+                    runner.get_exception_type(),
+                    runner.get_exception_message(),
+                    runner.get_formatted_exception_trace())
 
 class TestResult:
 
-  def __init__(self, time, passed, skipped, failed, exceptions):
+  def __init__(self, time, passed, skipped, failed, exception_type, exception_message, formatted_exception_trace):
     self.time = time
     self.passed = passed
     self.skipped = skipped
     self.failed = failed
-    self.exceptions = exceptions
+    self.exception_type =  exception_type
+    self.exception_message = exception_message
+    self.formatted_exception_trace = formatted_exception_trace
 
 class FunctionTest:
 



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


Mime
View raw message