Fix generation of #line directives in Python 2
When using Python 2 (which is done in the Makefile), all #line
directives from the test code were generated with the line number 1.
This traces back to the change in the method name for generators in
Python 2 (next) vs Python 3 (__next__). Override both methods so that
the script remains compatible with both Python 2 and Python 3.
diff --git a/tests/scripts/generate_test_code.py b/tests/scripts/generate_test_code.py
index 45fb1f5..78bbaa3 100755
--- a/tests/scripts/generate_test_code.py
+++ b/tests/scripts/generate_test_code.py
@@ -76,17 +76,24 @@
super(FileWrapper, self).__init__(file_name, 'r')
self.line_no = 0
+ # Override the generator function in a way that works in both Python 2
+ # and Python 3.
def __next__(self):
"""
Iterator return impl.
:return: Line read from file.
"""
- line = super(FileWrapper, self).__next__()
+ parent = super(FileWrapper, self)
+ if hasattr(parent, '__next__'):
+ line = parent.__next__() # Python 3
+ else:
+ line = parent.next() # Python 2
if line:
self.line_no += 1
# Convert byte array to string with correct encoding
return line.decode(sys.getdefaultencoding())
return None
+ next = __next__
def split_dep(dep):