Python3 compatible generate_test_code.py

This commit is contained in:
Mohammad Azim Khan 2018-04-11 23:46:37 +01:00
parent 78befd9019
commit 1ec7e6f3d9

24
tests/scripts/generate_test_code.py Normal file → Executable file
View file

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Test suites code generator. # Test suites code generator.
# #
# Copyright (C) 2018, ARM Limited, All Rights Reserved # Copyright (C) 2018, ARM Limited, All Rights Reserved
@ -33,8 +34,10 @@ helper .function - Read common reusable functions.
""" """
import io
import os import os
import re import re
import sys
import argparse import argparse
import shutil import shutil
@ -59,7 +62,7 @@ class InvalidFileFormat(Exception):
pass pass
class FileWrapper(file): class FileWrapper(io.FileIO):
""" """
File wrapper class. Provides reading with line no. tracking. File wrapper class. Provides reading with line no. tracking.
""" """
@ -73,24 +76,17 @@ class FileWrapper(file):
super(FileWrapper, self).__init__(file_name, 'r') super(FileWrapper, self).__init__(file_name, 'r')
self.line_no = 0 self.line_no = 0
def next(self): def __next__(self):
""" """
Iterator return impl. Iterator return impl.
:return: Line read from file. :return: Line read from file.
""" """
line = super(FileWrapper, self).next() line = super(FileWrapper, self).__next__()
if line: if line:
self.line_no += 1 self.line_no += 1
return line # Convert byte array to string with correct encoding
return line.decode(sys.getdefaultencoding())
def readline(self, limit=0): return None
"""
Wrap the base class readline.
:param limit: limit to match file.readline([limit])
:return: Line read from file.
"""
return self.next()
def split_dep(dep): def split_dep(dep):
@ -513,7 +509,7 @@ def write_parameters(out_data_f, test_args, func_args, unique_expressions):
:return: Returns expression check code. :return: Returns expression check code.
""" """
expression_code = '' expression_code = ''
for i in xrange(len(test_args)): for i in range(len(test_args)):
typ = func_args[i] typ = func_args[i]
val = test_args[i] val = test_args[i]