diff --git a/xml_converter/.gitignore b/xml_converter/.gitignore index ee6c06c7..7978cf59 100644 --- a/xml_converter/.gitignore +++ b/xml_converter/.gitignore @@ -11,3 +11,4 @@ web_docs __pycache__/ build/ export_packs/ +.cache/clangd diff --git a/xml_converter/generators/presubmit.sh b/xml_converter/generators/presubmit.sh index a7b5e1cc..e1bf02a7 100755 --- a/xml_converter/generators/presubmit.sh +++ b/xml_converter/generators/presubmit.sh @@ -2,7 +2,7 @@ error_count=0 -source ./venv/bin/activate +source ../venv/bin/activate readarray -d '' FILES < <(find . -type f -name "*.py" -not -path "*/venv/*" -print0) diff --git a/xml_converter/intigration_tests/presubmit.sh b/xml_converter/intigration_tests/presubmit.sh new file mode 100755 index 00000000..e1bf02a7 --- /dev/null +++ b/xml_converter/intigration_tests/presubmit.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +error_count=0 + +source ../venv/bin/activate + +readarray -d '' FILES < <(find . -type f -name "*.py" -not -path "*/venv/*" -print0) + +# Lint Python Files +flake8 --ignore=E501,E266,W503 "${FILES[@]}" +if (( $? > 0 )); then + echo "Flake8 Error" + error_count=`expr $error_count + 1` +fi + +# Type Check Python Files +mypy --strict "${FILES[@]}" +if (( $? > 0 )); then + echo "mypy error" + error_count=`expr $error_count + 1` +fi + + +exit $error_count diff --git a/xml_converter/intigration_tests/run_tests.py b/xml_converter/intigration_tests/run_tests.py index f9378204..965e63e0 100755 --- a/xml_converter/intigration_tests/run_tests.py +++ b/xml_converter/intigration_tests/run_tests.py @@ -2,7 +2,6 @@ import argparse import difflib -import json import subprocess import re import os @@ -70,8 +69,6 @@ def len_diff(lines: List[str]) -> int: return diffcount - - ################################################################################ # remove_ansii_color_escapecodes # @@ -82,7 +79,7 @@ def len_diff(lines: List[str]) -> int: def remove_ansii_color_escapecodes(lines: List[str]) -> List[str]: - return [ re.sub(pattern_for_color_escape_codes, '', line) for line in lines ] + return [re.sub(pattern_for_color_escape_codes, '', line) for line in lines] ################################################################################ @@ -91,7 +88,7 @@ def remove_ansii_color_escapecodes(lines: List[str]) -> List[str]: # Recompiles the XML Converter binary. If the compilation returns an error code # then this function throws an error ################################################################################ -def rebuild_xml_converter_binary(): +def rebuild_xml_converter_binary() -> None: cmake_build_directory = "../build" # Store the current working directory @@ -115,6 +112,7 @@ def rebuild_xml_converter_binary(): else: print(f"Directory '{cmake_build_directory}' does not exist.") + ################################################################################ # remove_ignored_lines # @@ -161,7 +159,6 @@ def main() -> None: xml_output_dir_path = os.path.join(output_parent_dirpath, "xml", testcase.name) proto_output_dir_path = os.path.join(output_parent_dirpath, "proto", testcase.name) - os.makedirs(xml_output_dir_path, exist_ok=True) os.makedirs(proto_output_dir_path, exist_ok=True) @@ -183,7 +180,7 @@ def main() -> None: print(" return_code : {}".format(returncode)) all_tests_passed: bool = True - + stdout_diff: List[str] = list(difflib.unified_diff(testcase.expected_stdout, stdout, fromfile="Expected stdout", tofile="Actual stdout", lineterm="")) if len_diff(stdout_diff) != 0: print(f"Standard output did not match for test {testcase.name}") @@ -198,7 +195,7 @@ def main() -> None: print(line) all_tests_passed = False - if testcase.expected_returncode is not None and testcase.expected_returncode != returncode : + if testcase.expected_returncode is not None and testcase.expected_returncode != returncode: print(f"Expected a return code of {testcase.expected_returncode} for {testcase.name} but got {returncode}") if testcase.expected_output_xml_path is not None: @@ -208,7 +205,7 @@ def main() -> None: output_xml_filepath = os.path.join(xml_output_dir_path, "xml_file.xml") expected_output_xml_filepath = os.path.join(testcase.expected_output_xml_path, "xml_file.xml") - xml_diff = compare_text_files(expected_output_xml_filepath , output_xml_filepath) + xml_diff = compare_text_files(expected_output_xml_filepath, output_xml_filepath) if len_diff(xml_diff) != 0: print(f"XML output was incorrect for test {testcase.name}") diff --git a/xml_converter/intigration_tests/src/__init__.py b/xml_converter/intigration_tests/src/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/xml_converter/intigration_tests/src/proto_utils.py b/xml_converter/intigration_tests/src/proto_utils.py index 1e1957dc..a170a89c 100644 --- a/xml_converter/intigration_tests/src/proto_utils.py +++ b/xml_converter/intigration_tests/src/proto_utils.py @@ -2,6 +2,7 @@ import subprocess import difflib + def compare_protos( outputs_directory: str, expected_outputs_directory: str, @@ -34,6 +35,7 @@ def compare_protos( return False + def compare_binary_file(file_path_1: str, file_path_2: str) -> bool: if not os.path.exists(file_path_1): return False diff --git a/xml_converter/intigration_tests/src/testcase_loader.py b/xml_converter/intigration_tests/src/testcase_loader.py index ba95ee95..aa85b442 100644 --- a/xml_converter/intigration_tests/src/testcase_loader.py +++ b/xml_converter/intigration_tests/src/testcase_loader.py @@ -48,7 +48,7 @@ def load_testcases() -> List[Testcase]: # A simple loader that loads the testcase from a specific directory, doing # typechecking on the testcase data to be sure it is properly structured. ################################################################################ -def load_testcase(path) -> Optional[Testcase]: +def load_testcase(path: str) -> Optional[Testcase]: test_info_path = os.path.join(path, "testcase.yaml") with open(test_info_path) as f: data = yaml.safe_load(f) @@ -61,13 +61,13 @@ def load_testcase(path) -> Optional[Testcase]: for pack_name, pack_type in data["input_paths"].items(): if not isinstance(pack_name, str): print(f"Invalid pack name, expecting a string but got {pack_name}") - return + return None pack_path = os.path.join(inputs_path, pack_name) if not os.path.exists(pack_path): print(f"Input pack path {pack_path} not found") - return + return None if pack_type == "xml": xml_input_paths.append(pack_path) @@ -75,7 +75,7 @@ def load_testcase(path) -> Optional[Testcase]: proto_input_paths.append(pack_path) else: print(f"Invalid pack type {pack_type} found in {test_info_path}") - return + return None # Sanity check that all the input directories were accounted for for possible_input_path in os.listdir(inputs_path): @@ -85,24 +85,24 @@ def load_testcase(path) -> Optional[Testcase]: # Typecheck the expected stdout, stderr, and returncode values if "expected_stdout" not in data: print(f"Expected 'expected_stdout' field in {test_info_path}") - return + return None elif not isinstance(data["expected_stdout"], str): print(f"Invalid Test, expecting string value for 'expected_stdout' in {path}") - return + return None if "expected_stderr" not in data: print(f"Expected 'expected_stderr' field in {test_info_path}") - return + return None elif not isinstance(data["expected_stderr"], str): print(f"Invalid Test, expecting string value for 'expected_stderr' in {path}") - return + return None if "expected_returncode" not in data: print(f"Expected 'expected_returncode' field in {test_info_path}") - return + return None elif not isinstance(data["expected_returncode"], int): print(f"Invalid Test, expecting string value for 'expected_returncode' in {path}") - return + return None return Testcase( name=os.path.basename(path), diff --git a/xml_converter/presubmit.sh b/xml_converter/presubmit.sh index 37589602..53c3235d 100755 --- a/xml_converter/presubmit.sh +++ b/xml_converter/presubmit.sh @@ -69,6 +69,13 @@ if (( $? > 0 )); then fi popd +# Run the python presubmit for the "integration_tests" subdirectory. +pushd intigration_tests +./presubmit.sh +if (( $? > 0 )); then + error_count=`expr $error_count + 1` +fi +popd exit $error_count