From 32cbcdac8fecf4709908372779a8f0fa160e6990 Mon Sep 17 00:00:00 2001 From: Mohammad Azim Khan Date: Fri, 6 Jul 2018 00:29:09 +0100 Subject: [PATCH] Fix Pylint errors in Python scripts --- tests/scripts/generate_test_code.py | 54 +++++++++++++++++++---------- tests/scripts/mbedtls_test.py | 2 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tests/scripts/generate_test_code.py b/tests/scripts/generate_test_code.py index ece35dfb4..2468063d1 100755 --- a/tests/scripts/generate_test_code.py +++ b/tests/scripts/generate_test_code.py @@ -499,6 +499,33 @@ def parse_function_arguments(line): return args, local_vars, args_dispatch +def generate_function_code(name, code, local_vars, args_dispatch, + dependencies): + """ + Generate function code with preprocessor checks and parameter dispatch + wrapper. + + :param name: Function name + :param code: Function code + :param local_vars: Local variables for function wrapper + :param args_dispatch: Argument dispatch code + :param dependencies: Preprocessor dependencies list + :return: Final function code + """ + # Add exit label if not present + if code.find('exit:') == -1: + split_code = code.rsplit('}', 1) + if len(split_code) == 2: + code = """exit: + ; +}""".join(split_code) + + code += gen_function_wrapper(name, local_vars, args_dispatch) + preprocessor_check_start, preprocessor_check_end = \ + gen_dependencies(dependencies) + return preprocessor_check_start + code + preprocessor_check_end + + def parse_function_code(funcs_f, dependencies, suite_dependencies): """ Parses out a function from function file object and generates @@ -552,21 +579,11 @@ def parse_function_code(funcs_f, dependencies, suite_dependencies): raise GeneratorInputError("file: %s - end case pattern [%s] not " "found!" % (funcs_f.name, END_CASE_REGEX)) - # Add exit label if not present - if code.find('exit:') == -1: - split_code = code.rsplit('}', 1) - if len(split_code) == 2: - code = """exit: - ; -}""".join(split_code) - - code = line_directive + code + gen_function_wrapper(name, local_vars, - args_dispatch) - preprocessor_check_start, preprocessor_check_end = \ - gen_dependencies(dependencies) + code = line_directive + code + code = generate_function_code(name, code, local_vars, args_dispatch, + dependencies) dispatch_code = gen_dispatch(name, suite_dependencies + dependencies) - return (name, args, preprocessor_check_start + code + - preprocessor_check_end, dispatch_code) + return (name, args, code, dispatch_code) def parse_functions(funcs_f): @@ -587,11 +604,10 @@ def parse_functions(funcs_f): dispatch_code = '' for line in funcs_f: if re.search(BEGIN_HEADER_REGEX, line): - headers = parse_until_pattern(funcs_f, END_HEADER_REGEX) - suite_helpers += headers + suite_helpers += parse_until_pattern(funcs_f, END_HEADER_REGEX) elif re.search(BEGIN_SUITE_HELPERS_REGEX, line): - helpers = parse_until_pattern(funcs_f, END_SUITE_HELPERS_REGEX) - suite_helpers += helpers + suite_helpers += parse_until_pattern(funcs_f, + END_SUITE_HELPERS_REGEX) elif re.search(BEGIN_DEP_REGEX, line): suite_dependencies += parse_suite_dependencies(funcs_f) elif re.search(BEGIN_CASE_REGEX, line): @@ -635,7 +651,7 @@ def escaped_split(inp_str, split_char): out = re.sub(r'(\\.)|' + split_char, lambda m: m.group(1) or '\n', inp_str, len(inp_str)).split('\n') - out = filter(lambda x: x or False, out) + out = [x for x in out if x] return out diff --git a/tests/scripts/mbedtls_test.py b/tests/scripts/mbedtls_test.py index 557031099..8e8a89ba9 100755 --- a/tests/scripts/mbedtls_test.py +++ b/tests/scripts/mbedtls_test.py @@ -80,7 +80,7 @@ class TestDataParser(object): out = re.sub(r'(\\.)|' + split_char, lambda m: m.group(1) or '\n', inp_str, len(inp_str)).split('\n') - out = filter(lambda x: x or False, out) + out = [x for x in out if x] return out def __parse(self, data_f):