Skip to content

Commit

Permalink
Adding a presubmit for integration tests and fixing the generators one
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Dec 30, 2023
1 parent 41e6da1 commit 4486a36
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions xml_converter/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ web_docs
__pycache__/
build/
export_packs/
.cache/clangd
2 changes: 1 addition & 1 deletion xml_converter/generators/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions xml_converter/intigration_tests/presubmit.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 6 additions & 9 deletions xml_converter/intigration_tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import argparse
import difflib
import json
import subprocess
import re
import os
Expand Down Expand Up @@ -70,8 +69,6 @@ def len_diff(lines: List[str]) -> int:
return diffcount




################################################################################
# remove_ansii_color_escapecodes
#
Expand All @@ -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]


################################################################################
Expand All @@ -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
Expand All @@ -115,6 +112,7 @@ def rebuild_xml_converter_binary():
else:
print(f"Directory '{cmake_build_directory}' does not exist.")


################################################################################
# remove_ignored_lines
#
Expand Down Expand Up @@ -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)

Expand All @@ -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}")
Expand All @@ -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:
Expand All @@ -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}")
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions xml_converter/intigration_tests/src/proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import difflib


def compare_protos(
outputs_directory: str,
expected_outputs_directory: str,
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions xml_converter/intigration_tests/src/testcase_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -61,21 +61,21 @@ 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)
elif pack_type == "proto":
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):
Expand All @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions xml_converter/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4486a36

Please sign in to comment.