gnome-desktop-testing r8 - in trunk: . bin



Author: apulido
Date: Wed Apr  1 10:20:00 2009
New Revision: 8
URL: http://svn.gnome.org/viewvc/gnome-desktop-testing?rev=8&view=rev

Log:
* Added the posibility of running particular test cases
* Report now includes errors in cleanup, teardown or startup methods.



Modified:
   trunk/bin/desktop-testing
   trunk/report.xsl

Modified: trunk/bin/desktop-testing
==============================================================================
--- trunk/bin/desktop-testing	(original)
+++ trunk/bin/desktop-testing	Wed Apr  1 10:20:00 2009
@@ -14,6 +14,7 @@
 from stat import ST_MODE, S_IMODE
 from subprocess import Popen, PIPE
 from time import time, gmtime, strftime
+from shutil import move
 
 # Globals
 TESTS_SHARE = "."
@@ -159,10 +160,10 @@
 
     return suite_files
 
-def run_suite_file(suite_file, log_file):
+def run_suite_file(suite_file, log_file, cases=None):
     conf_file = os.path.join(TESTS_SHARE, "conffile.ini")
     runner = TestSuiteRunner(suite_file)
-    results = runner.run()
+    results = runner.run(cases=cases)
     f = open(log_file, 'w')
     f.write(results)
     f.close()
@@ -199,7 +200,7 @@
         % (html_file, xsl_file, log_file)
     safe_run_command(command)
  
-def process_suite_file(suite_file, target_directory):
+def process_suite_file(suite_file, target_directory, cases=None):
     application_name = os.path.basename(os.path.dirname(suite_file))
     application_target = os.path.join(target_directory, application_name)
     safe_make_directory(application_target)
@@ -207,7 +208,7 @@
     suite_name = os.path.basename(suite_file)
     log_file = os.path.join(application_target,
         suite_name.replace(".xml", ".log"))
-    run_suite_file(suite_file, log_file)
+    run_suite_file(suite_file, log_file, cases)
 
     convert_log_file(log_file)
 
@@ -246,6 +247,11 @@
                       default=default_target,
                       help="Target directory for logs and reports. Defaults "
                            "to: %default")
+    parser.add_option("-c", "--case",
+                      action="append",
+                      type="string",
+                      default=None,
+                      help="Test cases to run (all, if not specified).")
 
     (options, args) = parser.parse_args(args[1:])
 
@@ -286,7 +292,7 @@
 
     # Run filtered suite file
     for suite_file in suite_files:
-        process_suite_file(suite_file, options.target)
+        process_suite_file(suite_file, options.target, options.case)
 
 
     return 0
@@ -315,11 +321,14 @@
     def set_result(self, key, value):
         self.result[key] = value
 
-    def append_screenshot(self):
+    def append_screenshot(self, screenshot_file=None):
         _logFile = "%s/screenshot-%s.png" % (SCREENSHOTS_SHARE,
                                              strftime ("%m-%d-%Y-%H-%M-%s"))
         safe_make_directory(SCREENSHOTS_SHARE)
-        ldtputils.imagecapture(outFile = _logFile)
+        if screenshot_file is None:
+            ldtputils.imagecapture(outFile = _logFile)
+        else:
+            move(screenshot_file, _logFile)
         self.append_result('screenshot', _logFile)
 
 
@@ -337,28 +346,45 @@
 
     def _get_args(self, node):
         for n in node.childNodes:
-            if n.nodeType != n.ELEMENT_NODE:
+            if n.nodeType != n.ELEMENT_NODE or not n.hasChildNodes():
                 continue
             self.args[n.tagName.encode('ascii')] = n.firstChild.data
 
     def run(self, logger):
         starttime = time()
         try:
-            self.test_func(**self.args)
+            rv = self.test_func(**self.args)
         except AssertionError, e:
             # The test failed.
-            self.append_result('message', str(e))
+            if len(e.args) > 1:
+                self.append_result('message', e.args[0])
+                self.append_screenshot(e.args[1])
+            else:
+                self.append_result('message', str(e))
+                self.append_screenshot()
             self.append_result('stacktrace', traceback.format_exc())
-            self.append_screenshot()
             self.set_result('pass', 0)
         except Exception, e:
             # There was an unrelated error.
-            self.append_result('message', str(e))
+            if len(e.args) > 1:
+                self.append_result('message', e.args[0])
+                self.append_screenshot(e.args[1])
+            else:
+                self.append_result('message', str(e))
+                self.append_screenshot()
             self.append_result('stacktrace', traceback.format_exc())
-            self.append_screenshot()
             self.set_result('error', 1)
         else:
             self.set_result('pass', 1)
+            try:
+                message, screenshot = rv
+            except:
+                pass
+            else:
+                if message:
+                    self.append_result('message', message)
+                if screenshot:
+                    self.append_screenshot(screenshot)
         finally:
             self.set_result('time', time() - starttime)
         
@@ -395,9 +421,9 @@
         self.case_runners = \
             [TestCaseRunner(self.testsuite, c) for c in case_runners]
     
-    def run(self, loggerclass=None, setup_once=True):
+    def run(self, loggerclass=None, setup_once=True, cases=None):
         try:
-            self._run(loggerclass, setup_once)
+            self._run(loggerclass, setup_once, cases)
         except Exception, e:
             # There was an unrelated error.
             self.append_result('message', str(e))
@@ -412,7 +438,7 @@
 
         return self.dom.toprettyxml('  ')
             
-    def _run(self, loggerclass, setup_once):
+    def _run(self, loggerclass, setup_once, cases):
         if loggerclass:
             logger = loggerclass()
         else:
@@ -424,6 +450,8 @@
 
         firsttest = True
         for testcase in self.case_runners:
+            if cases and testcase.name not in cases:
+                continue
             if not setup_once:
                 # Set up the app for each test, if requested.
                 self.testsuite.setup()

Modified: trunk/report.xsl
==============================================================================
--- trunk/report.xsl	(original)
+++ trunk/report.xsl	Wed Apr  1 10:20:00 2009
@@ -162,6 +162,23 @@
                         </xsl:for-each>
                       </tr>
                   </xsl:for-each>
+                  
+                  <xsl:for-each select="suite/result">
+                      <tr></tr>
+                      <tr>
+                          <td colspan="7"><font color="red"><h2><b>The suite had an error in the setup, teardown or cleanup methods.</b></h2></font></td>
+                          <td>
+                            <xsl:call-template name="stacktemplate">
+                                <xsl:with-param name="stackid">
+                                    <xsl:value-of select="string('testsuite_stacktrace')" />
+                                </xsl:with-param>
+                                <xsl:with-param name="stacktext">
+                                    <xsl:value-of select="child::stacktrace/child::text()" />
+                                </xsl:with-param>
+                            </xsl:call-template>
+                        </td>                        
+                      </tr>
+                  </xsl:for-each>
                 </tbody>
               </table>
               <p>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]