Skip to content

Commit

Permalink
Added python virtual environment
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-ni committed Jan 17, 2024
1 parent 6624d5c commit 96d9b91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}" "./src" "./third_party/grpc" "

add_custom_target(Detect_Compatibility_Breaks
COMMAND ${CMAKE_COMMAND} -E echo "Detecting backward compatibility breakage ..."
COMMAND python -m pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeTests/requirements.txt
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeTests/run_test.py
RESULT_VARIABLE shell_command_result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeTests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exported_function_list.json
exported_function_list.json
venv
1 change: 0 additions & 1 deletion tests/CMakeTests/requirements.txt

This file was deleted.

37 changes: 29 additions & 8 deletions tests/CMakeTests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,53 @@
import os
from pathlib import Path

# Setting global variables
if os.name == 'nt': # windows
venv_command = "python -m venv venv"
activate_script = "venv\\Scripts\\activate"
activate_command = f"call {activate_script}"
else:
venv_command = "python -m venv venv"
activate_script = "venv/bin/activate"
activate_command = f"source {activate_script}"

def create_virtual_environment():
if os.name == 'nt': # windows
venv_command = "python -m venv venv"
else:
venv_command = "python -m venv venv"
venv_folder_path = Path(__file__).parent / "venv"
if not venv_folder_path.exists():
subprocess.run(venv_command, shell=True)

def install_dependencies():
subprocess.run(f"{activate_command} && pip install pytest", shell=True)

def run_tests():
message_structures_test_path = Path(__file__).parent / "tests" / "message_structure_test.py"
exported_functions_test_path = Path(__file__).parent / "tests" / "exported_functions_test.py"
exported_functions_addition_test_path = Path(__file__).parent / "tests" / "exported_functions_addition_test.py"

# Check the exit code
result_message_structure = subprocess.run(["python", "-m", "pytest", str(message_structures_test_path), "-vv"])
result_message_structure = subprocess.run(f"{activate_command} && python -m pytest {str(message_structures_test_path)} -vv", shell=True)
if result_message_structure.returncode != 0:
result_message_structure = subprocess.run(["python", "-m", "pytest", str(message_structures_test_path), "-vv"])
if result_message_structure.returncode != 0:
print(f"Message structural tests failed with exit code {result_message_structure.returncode}. Exiting.")
sys.exit(result_message_structure.returncode)
result_exported_functions = subprocess.run(["python", "-m", "pytest", str(exported_functions_test_path), "-vv"])

result_exported_functions = subprocess.run(f"{activate_command} && python -m pytest {str(exported_functions_test_path)} -vv", shell=True)
if result_exported_functions.returncode != 0:
result_exported_functions = subprocess.run(["python", "-m", "pytest", str(exported_functions_test_path), "-vv"])
if result_exported_functions.returncode != 0:
print(f"Function structural tests failed with exit code {result_exported_functions.returncode}. Exiting.")
sys.exit(result_exported_functions.returncode)
result_exported_functions_addition = subprocess.run(["python", str(exported_functions_addition_test_path)])

result_exported_functions_addition = subprocess.run(f"{activate_command} && python {str(exported_functions_addition_test_path)}", shell=True)
if result_exported_functions_addition.returncode != 0:
result_exported_functions_addition = subprocess.run(["python", str(exported_functions_addition_test_path)])
if result_exported_functions_addition.returncode != 0:
print(f"Function structural tests failed with exit code {result_exported_functions_addition.returncode}. Exiting.")
sys.exit(result_exported_functions_addition.returncode)

print("All structural tests passed.")

if __name__ == "__main__":
create_virtual_environment()
install_dependencies()
run_tests()

0 comments on commit 96d9b91

Please sign in to comment.