Checks to make sure XML path is writable before making the XML runner. Ignores it...
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr_unittest.py
index 29a73194313412f5a8500a8871e144da0bd03dc2..50d484a76e69c79688a47536022f1ae164a87f95 100755 (executable)
@@ -117,21 +117,42 @@ def run(PUT, filename=None):
 
     # Run this is given a file name
     if(filename is not None):
-        path = os.getenv("HOME") + "/.gnuradio/unittests/python"
-
-        # Test if path exists; if not, build it
-        try:
-            st = os.stat(path)
-        except OSError:
-            os.makedirs(path, 0750)
-
-        # Create an XML runner to filename
-        fout = file(path+"/"+filename, "w")
-        runner = gr_xmlrunner.XMLTestRunner(fout)
+        homepath = os.getenv("HOME")
+        basepath = homepath + "/.gnuradio"
+        path = homepath + "/.gnuradio/unittests/python"
+
+        xmlrunner = None
+        if os.path.exists(basepath):
+            # only proceed if $HOME/.gnuradio is writable
+            st = os.stat(basepath)[stat.ST_MODE]
+            if(st & stat.S_IWUSR > 0):
+                # Test if path exists; if not, build it
+                if not os.path.exists(path):
+                    os.makedirs(path, 0750)
+
+                # Just for safety: make sure we can write here, too
+                st = os.stat(path)[stat.ST_MODE]
+                if(st & stat.S_IWUSR > 0):
+                    # Create an XML runner to filename
+                    fout = file(path+"/"+filename, "w")
+                    xmlrunner = gr_xmlrunner.XMLTestRunner(fout)
+
+        txtrunner = TextTestRunner(verbosity=1)
 
         # Run the test; runner also creates XML output file
+        # FIXME: make xmlrunner output to screen so we don't have to do run and main
         suite = TestLoader().loadTestsFromTestCase(PUT)
-        runner.run(suite)
+
+        # use the xmlrunner if we can write the the directory
+        if(xmlrunner is not None):
+            xmlrunner.run(suite)
+
+        main()
+        
+        # This will run and fail make check if problem
+        # but does not output to screen.
+        #main(testRunner = xmlrunner)
+
     else:
         # If no filename is given, just run the test
         main()