Quellcode durchsuchen

gunittest: support older version of svn by getting relative URL from absolute one (ticket https://trac.osgeo.org/grass/ticket/2364), also improve documentation about data directory (ticket https://trac.osgeo.org/grass/ticket/2365)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61244 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras vor 10 Jahren
Ursprung
Commit
c4e84521c9

+ 13 - 0
lib/python/docs/src/gunittest_testing.rst

@@ -292,6 +292,19 @@ with special data.
     GRASS module).
 
 
+Data specific to one test
+-------------------------
+
+If the data required by the test are not part of standard location
+and cannot be part of the test file itself, this data should be stored
+in files in ``data`` subdirectory of ``testsuite`` directory.
+The test should access the data using a relative path from its location,
+i.e. all data will be accessed using ``data/...``. This ``data`` directory
+might be used directly when running test file directly in the directory
+in the source code or might be copied to the test current working directory
+when running tests by the main test invoking tool.
+
+
 Analyzing quality of source code
 --------------------------------
 

+ 3 - 1
lib/python/gunittest/invoker.py

@@ -101,7 +101,9 @@ class GrassTestFilesInvoker(object):
         self.reporter.start_file_test(module)
         # TODO: we might clean the directory here before test if non-empty
         # TODO: use some grass function to run?
-        p = subprocess.Popen([sys.executable, module.abs_file_path],
+        # add also '-Qwarn'?
+        p = subprocess.Popen([sys.executable, '-tt', '-3',
+                              module.abs_file_path],
                              cwd=cwd, env=env,
                              stdout=stdout, stderr=stderr)
         returncode = p.wait()

+ 4 - 0
lib/python/gunittest/main.py

@@ -75,6 +75,8 @@ def test():
 
     # TODO: enable passing omit to exclude also gunittest or nothing
     program = GrassTestProgram(module='__main__', exit_at_end=False, grass_location='all')
+    # TODO: check if we are in the directory where the test file is
+    # this will ensure that data directory is available when it is requested
 
     if doing_coverage:
         cov.stop()
@@ -137,6 +139,8 @@ if __name__ == '__main__':
     silent_rmtree(results_dir)  # TODO: too brute force?
 
     invoker = GrassTestFilesInvoker(start_dir='.')
+    # we can just iterate over all locations available in database
+    # but the we don't know the right location label/shortcut
     invoker.run_in_location(gisdbase=gisdbase,
                             location=location,
                             location_shortcut=location_shortcut,

+ 14 - 5
lib/python/gunittest/reporters.py

@@ -103,14 +103,23 @@ def get_svn_info():
         if not rc:
             root = et.fromstring(stdout)
             # TODO: get also date if this make sense
-            # expecting only one <entry>
+            # expecting only one <entry> element
             entry = root.find('entry')
             info['revision'] = entry.get('revision')
             info['url'] = entry.find('url').text
-            relurl = entry.find('relative-url').text
-            # relative path has ^ at the beginning
-            if relurl.startswith('^'):
-                relurl = relurl[1:]
+            relurl = entry.find('relative-url')
+            # element which is not found is None
+            # empty element would be bool(el) == False
+            if relurl is not None:
+                relurl = relurl.text
+                # relative path has ^ at the beginning in SVN version 1.8.8
+                if relurl.startswith('^'):
+                    relurl = relurl[1:]
+            else:
+                # SVN version 1.8.8 supports relative-url but older do not
+                # so, get relative part from absolute URL
+                const_url_part = 'https://svn.osgeo.org/grass/'
+                relurl = info['url'][len(const_url_part):]
             info['relative-url'] = relurl
             return info
     # TODO: add this to svnversion function