[GRASS-SVN] r61324 - grass/trunk/lib/python/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 22 09:24:03 PDT 2014


Author: wenzeslaus
Date: 2014-07-22 09:24:03 -0700 (Tue, 22 Jul 2014)
New Revision: 61324

Modified:
   grass/trunk/lib/python/gunittest/invoker.py
   grass/trunk/lib/python/gunittest/reporters.py
Log:
gunittest: summary of test files (count and percentage)

Modified: grass/trunk/lib/python/gunittest/invoker.py
===================================================================
--- grass/trunk/lib/python/gunittest/invoker.py	2014-07-22 14:05:17 UTC (rev 61323)
+++ grass/trunk/lib/python/gunittest/invoker.py	2014-07-22 16:24:03 UTC (rev 61324)
@@ -84,6 +84,7 @@
         cwd = os.path.join(results_dir, module.tested_dir, module.name)
         data_dir = os.path.join(module.file_dir, 'data')
         if os.path.exists(data_dir):
+            # TODO: link dir intead of copy tree
             shutil.copytree(data_dir, os.path.join(cwd, 'data'),
                             ignore=shutil.ignore_patterns('*.svn*'))
         ensure_dir(os.path.abspath(cwd))

Modified: grass/trunk/lib/python/gunittest/reporters.py
===================================================================
--- grass/trunk/lib/python/gunittest/reporters.py	2014-07-22 14:05:17 UTC (rev 61323)
+++ grass/trunk/lib/python/gunittest/reporters.py	2014-07-22 16:24:03 UTC (rev 61324)
@@ -167,16 +167,51 @@
                                   svn=svn_text))
         self.file_start_time = None
         self._start_file_test_called = False
+        self.test_files = 0
+        self.files_failed = 0
+        self.files_succeeded = 0
 
     def finish(self):
-        self.main_index.write('<tbody></table>'
-                              '</body></html>')
+        main_end_time = datetime.datetime.now()
+        main_time = main_end_time - self.main_start_time
+        assert self.test_files == self.files_failed + self.files_succeeded
+
+        file_success_per = 100 * float(self.files_succeeded) / self.test_files
+        file_fail_per = 100 * float(self.files_failed) / self.test_files
+        tfoot = ('<tfoot>'
+                 '<tr>'
+                 '<td>Summary</td>'
+                 '<td>{nfiles} test files</td>'
+                 '<td>{nsper:.2f}% successful</td>'
+                 '</tr>'
+                 '</tfoot>'.format(nfiles=self.test_files,
+                                   nsper=file_success_per))
+
+        summary_sentence = ('Executed {nfiles} test files in {time:}.'
+                            ' From them'
+                            ' {nsfiles} files ({nsper:.2f}%) were successful'
+                            ' and {nffiles} files ({nfper:.2f}%) failed.'
+                            .format(
+                                nfiles=self.test_files,
+                                time=main_time,
+                                nsfiles=self.files_succeeded,
+                                nffiles=self.files_failed,
+                                nsper=file_success_per,
+                                nfper=file_fail_per))
+
+        self.main_index.write('<tbody>{tfoot}</table>'
+                              '<p>{summary}</p>'
+                              '</body></html>'
+                              .format(
+                                  tfoot=tfoot,
+                                  summary=summary_sentence))
         self.main_index.close()
 
     def start_file_test(self, module):
         self.file_start_time = datetime.datetime.now()
         self._start_file_test_called = True
         self.main_index.flush()  # to get previous ones to the report
+        self.test_files += 1
 
     def wrap_stdstream_to_html(self, infile, outfile, module, stream):
         before = '<html><body><h1>%s</h1><pre>' % (module.name + ' ' + stream)
@@ -237,4 +272,8 @@
             sys.stderr.write('{d}/{m} failed (see {f})\n'.format(d=module.tested_dir,
                                                                  m=module.name,
                                                                  f=file_index_path))
+            self.files_failed += 1
+        else:
+            self.files_succeeded += 1
+
         self._start_file_test_called = False



More information about the grass-commit mailing list