[asterisk-commits] russell: testsuite/asterisk/trunk r118 - /asterisk/trunk/runtests.py

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 24 05:43:47 CDT 2010


Author: russell
Date: Wed Mar 24 05:43:44 2010
New Revision: 118

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=118
Log:
Expand on exception handling when opening files.

Modified:
    asterisk/trunk/runtests.py

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=118&r1=117&r2=118
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Wed Mar 24 05:43:44 2010
@@ -90,10 +90,15 @@
         test_config = "tests/%s/test-config.yaml" % self.test_name
         try:
             f = open(test_config, "r")
-            self.config = yaml.load(f)
-            f.close()
+        except IOError as (errno, strerror):
+            print "Failed to open %s: %s" % (test_config, strerror)
+            return
         except:
-            print "Failed to open %s, does it exist?" % test_config
+            print "Unexpected error: %s" % sys.exc_info()[0]
+            return
+
+        self.config = yaml.load(f)
+        f.close()
 
         self.__process_testinfo()
         self.__process_properties()
@@ -124,7 +129,15 @@
 
 class TestSuite:
     def __init__(self, ast_version):
-        f = open(TESTS_CONFIG, "r")
+        try:
+            f = open(TESTS_CONFIG, "r")
+        except IOError as (errno, strerror):
+            print "Failed to open %s: %s" % (TESTS_CONFIG, strerror)
+            return
+        except:
+            print "Unexpected error: %s" % sys.exc_info()[0]
+            return
+
         self.config = yaml.load(f)
         f.close()
 
@@ -204,8 +217,11 @@
     def write_results_xml(self, fn, stdout=False):
         try:
             f = open(TEST_RESULTS, "w")
+        except IOError as (errno, strerror):
+            print "Failed to open test results output file: %s" % strerror
+            return
         except:
-            print "Failed to open test results output file."
+            print "Unexpected error: %s" % sys.exc_info()[0]
             return
 
         f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
@@ -224,9 +240,15 @@
         f.close()
 
         if stdout is True:
-            f = open(TEST_RESULTS, "r")
-            print f.read()
-            f.close()
+            try:
+                f = open(TEST_RESULTS, "r")
+            except IOError as (errno, strerror):
+                print "Failed to open test results output file: %s" % strerror
+            except:
+                print "Unexpected error: %s" % sys.exc_info()[0]
+            else:
+                print f.read()
+                f.close()
 
 
 def main(argv=None):




More information about the asterisk-commits mailing list