This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] A few more Python version related testsuite fixes


Here are a few more testsuite changes to handle Python version differences. 

The _iterator_except changes in py-pretttyprint.py are needed because the tests in py-mi.exp intended for that forced exception flag to apply only to the NoStringContainerPrinter class, 

Ok to commit?

	paul

testsuite/ChangeLog:

2012-12-11  Paul Koning  <paul_koning@dell.com>

	* gdb.python/py-prettyprint.py (_iterator): Remove exception_flag
	exception.
	(_iterator_except): New function.
	(ArrayPrinter): Use _iterator function instead of local _iterator
	class for Python 3 compatibility.
	(NoStringContainerPrinter): Use _iterator_except instead of
	_iterator. 
	* gdb.python/py-typeprint.exp: Use exec(open(...).read()) instead of
	execfile for Python 3 compatibility.
	* gdb.python/python.exp: Handle Python 2.4 exception traceback
	format in error_prompt test.

Index: gdb/testsuite/gdb.python/py-prettyprint.py
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-prettyprint.py,v
retrieving revision 1.17
diff -u -r1.17 py-prettyprint.py
--- gdb/testsuite/gdb.python/py-prettyprint.py	10 Dec 2012 21:22:21 -0000	1.17
+++ gdb/testsuite/gdb.python/py-prettyprint.py	11 Dec 2012 19:24:46 -0000
@@ -23,6 +23,14 @@
     start = pointer
     end = pointer + len
     while pointer != end:
+        yield ('[%d]' % int (pointer - start), pointer.dereference())
+        pointer += 1
+
+# Same as _iterator but can be told to raise an exception.
+def _iterator_except (pointer, len):
+    start = pointer
+    end = pointer + len
+    while pointer != end:
         if exception_flag:
             raise gdb.MemoryError ('hi bob')
         yield ('[%d]' % int (pointer - start), pointer.dereference())
@@ -49,23 +57,7 @@
         return _iterator(self.val['elements'], self.val['len'])
 
 # Treats a container as array.
-class ArrayPrinter:
-    class _iterator:
-        def __init__ (self, pointer, len):
-            self.start = pointer
-            self.pointer = pointer
-            self.end = pointer + len
-
-        def __iter__(self):
-            return self
-
-        def next(self):
-            if self.pointer == self.end:
-                raise StopIteration
-            result = self.pointer
-            self.pointer = self.pointer + 1
-            return ('[%d]' % int (result - self.start), result.dereference())
-
+class ArrayPrinter (object):
     def __init__(self, val):
         self.val = val
 
@@ -73,7 +65,7 @@
         return 'array %s with %d elements' % (self.val['name'], self.val['len'])
 
     def children(self):
-        return self._iterator(self.val['elements'], self.val['len'])
+        return _iterator(self.val['elements'], self.val['len'])
 
     def display_hint (self):
         return 'array'
@@ -90,7 +82,7 @@
         return None
 
     def children(self):
-        return _iterator(self.val['elements'], self.val['len'])
+        return _iterator_except (self.val['elements'], self.val['len'])
 
 class pp_s (object):
     def __init__(self, val):
Index: gdb/testsuite/gdb.python/py-typeprint.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-typeprint.exp,v
retrieving revision 1.1
diff -u -r1.1 py-typeprint.exp
--- gdb/testsuite/gdb.python/py-typeprint.exp	12 Nov 2012 17:41:59 -0000	1.1
+++ gdb/testsuite/gdb.python/py-typeprint.exp	11 Dec 2012 19:24:46 -0000
@@ -28,7 +28,7 @@
 
 set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
 
-gdb_test_no_output "python execfile ('${remote_python_file}')"
+gdb_test_no_output "python exec (open ('${remote_python_file}').read ())"
 
 cp_test_ptype_class s "basic test" "class" "templ<string>" {
     { field public "T x;" }
Index: gdb/testsuite/gdb.python/python.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/python.exp,v
retrieving revision 1.38
diff -u -r1.38 python.exp
--- gdb/testsuite/gdb.python/python.exp	10 Dec 2012 21:22:21 -0000	1.38
+++ gdb/testsuite/gdb.python/python.exp	11 Dec 2012 19:24:46 -0000
@@ -362,7 +362,7 @@
   "end" ""
 
 gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
-    -re "Python Exception <(type 'exceptions.|class ')RuntimeError'> Python exception called.*" {
+    -re "Python Exception (exceptions.RuntimeError|<(type 'exceptions.|class ')RuntimeError'>) Python exception called.*" {
 	pass "set hook"
     }
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]