[GRASS-SVN] r61120 - sandbox/wenzeslaus/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 2 08:35:59 PDT 2014


Author: wenzeslaus
Date: 2014-07-02 08:35:59 -0700 (Wed, 02 Jul 2014)
New Revision: 61120

Modified:
   sandbox/wenzeslaus/gunittest/main.py
Log:
gunittest: proof of concept for report generation

Modified: sandbox/wenzeslaus/gunittest/main.py
===================================================================
--- sandbox/wenzeslaus/gunittest/main.py	2014-07-02 15:00:14 UTC (rev 61119)
+++ sandbox/wenzeslaus/gunittest/main.py	2014-07-02 15:35:59 UTC (rev 61120)
@@ -54,7 +54,7 @@
     cov.stop()
     cov.html_report(directory='testcodecoverage')
 
-    sys.exit(program.result.wasSuccessful())
+    sys.exit(not program.result.wasSuccessful())
 
 
 test = main
@@ -77,7 +77,7 @@
     cov.stop()
     cov.html_report(directory='testcodecoverage')
 
-    sys.exit(program.result.wasSuccessful())
+    sys.exit(not program.result.wasSuccessful())
 
 
 def ensure_dir(directory):
@@ -87,7 +87,7 @@
 
 def recursive_runs():
     grass_location = 'nc'
-    # here should never be the same as start_dir, it leads to confusing dir tree
+    # here should never be the same as start_dir, it leads to confusing (and dangerous) dir tree
     results_root = 'testresults'
     import subprocess
     modules = discover_modules(start_dir='.',
@@ -99,13 +99,50 @@
                                universal_location_value=GrassTestLoader.universal_tests_value,
                                import_modules=False)
     env = os.environ.copy()
+    main_index = open(os.path.join(results_root, 'index.html'), 'w')
+    main_index.write('<html><body>'
+                     '<ul>')
     for module in modules:
         cwd = os.path.join(results_root, module.tested_dir, module.name)
         ensure_dir(os.path.abspath(cwd))
+        # TODO: we don't do any HTML escaping, use txt file
+        stdout = open(os.path.join(cwd, 'stdout.html'), 'w')
+        stderr = open(os.path.join(cwd, 'stderr.html'), 'w')
+        stdout.write('<html><body><pre>')
+        stderr.write('<html><body><pre>')
+        stdout.flush()  # we need to flush to write our changes before stdout
+        stderr.flush()
         # TODO: we might clean the directory here before test if non-empty
-        p = subprocess.Popen([sys.executable, module.abs_file_path], cwd=cwd, env=env)
-        p.wait()
+        p = subprocess.Popen([sys.executable, module.abs_file_path],
+                             cwd=cwd, env=env,
+                             stdout=stdout, stderr=stderr)
+        returncode = p.wait()
+        stdout.flush()
+        stderr.flush()
+        stdout.write('</pre></body></html>')
+        stderr.write('</pre></body></html>')
+        file_index_path = os.path.join(cwd, 'index.html')        
+        if returncode:
+            sys.stderr.write('{d}/{m} failed (see {f})\n'.format(d=module.tested_dir,
+                                                                 m=module.name,
+                                                                 f=file_index_path))
+        main_index.write('<li><a href="{d}/{m}/index.html">{d}/{m}</a>'.format(d=module.tested_dir, m=module.name))
+        file_index = open(file_index_path, 'w')
+        file_index.write('<html><body>'
+                         '<ul>'
+                         '<li><a href="stdout.html">standard output (stdout)</a>'
+                         '<li><a href="stderr.html">standard error output (stderr)</a>'
+                         '<li><a href="testcodecoverage/index.html">code coverage</a>'
+                         '</ul>'
+                         '</body></html>')
+        stdout.close()
+        stderr.close()
+        file_index.close()
 
+    main_index.write('</ul>'
+                     '</body></html>')
+    main_index.close()
 
+
 if __name__ == '__main__':
     recursive_runs()



More information about the grass-commit mailing list