[GRASS-SVN] r61121 - sandbox/wenzeslaus/gunittest
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 2 10:16:24 PDT 2014
Author: wenzeslaus
Date: 2014-07-02 10:16:24 -0700 (Wed, 02 Jul 2014)
New Revision: 61121
Modified:
sandbox/wenzeslaus/gunittest/main.py
Log:
gunittest: first version of switching location and mapset (using existing GISDBASE and hardcoded mapset)
Modified: sandbox/wenzeslaus/gunittest/main.py
===================================================================
--- sandbox/wenzeslaus/gunittest/main.py 2014-07-02 15:35:59 UTC (rev 61120)
+++ sandbox/wenzeslaus/gunittest/main.py 2014-07-02 17:16:24 UTC (rev 61121)
@@ -2,6 +2,7 @@
import os
import sys
+import shutil
from unittest.main import TestProgram, USAGE_AS_MAIN
TestProgram.USAGE = USAGE_AS_MAIN
@@ -9,7 +10,10 @@
from loader import GrassTestLoader, discover_modules
from runner import GrassTestRunner
+import grass.script.setup as gsetup
+import grass.script.core as gcore
+
class GrassTestProgram(TestProgram):
def __init__(self, exit_at_end, grass_location, clean_outputs=True,
@@ -98,13 +102,36 @@
all_locations_value=GrassTestLoader.all_tests_value,
universal_location_value=GrassTestLoader.universal_tests_value,
import_modules=False)
- env = os.environ.copy()
+ ensure_dir(os.path.abspath(results_root))
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))
+
+ env = os.environ.copy()
+ # using path.sep but also / and \ for cases when it is confused
+ # (namely the case of Unix path on MS Windows)
+ # replace . to get rid of unclean path
+ # TODO: clean paths
+ dir_as_name = module.tested_dir.replace('.', '_').replace('/', '_').replace('\\', '_').replace(os.path.sep, '_')
+ mapset = dir_as_name + '_' + module.name
+ location = 'nc_spm_08_grass7_tests'
+ gisdbase = gcore.gisenv()['GISDBASE']
+ assert gisdbase
+ gisrc = gsetup.write_gisrc(gisdbase, location, mapset)
+ env['GISRC'] = gisrc
+ # TODO: use grass module to do this?
+ mapset_dir = os.path.join(gisdbase, location, mapset)
+ # TODO: perhaps remove dir if exists
+ os.mkdir(mapset_dir)
+ # copy WIND file from PERMANENT
+ # TODO: this should be a function in grass.script (used also in gis_set.py, PyGRASS alos has its way with Mapset)
+ # TODO: are premisions an issue here?
+ shutil.copy(os.path.join(gisdbase, location, 'PERMANENT', 'WIND'),
+ os.path.join(mapset_dir))
+
# 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')
@@ -112,6 +139,7 @@
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,
@@ -138,6 +166,9 @@
stdout.close()
stderr.close()
file_index.close()
+ os.remove(gisrc)
+ # TODO: only if clean up
+ shutil.rmtree(mapset_dir)
main_index.write('</ul>'
'</body></html>')
More information about the grass-commit
mailing list