-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_conformance_tests_python.sh
More file actions
executable file
·91 lines (69 loc) · 2.54 KB
/
run_conformance_tests_python.sh
File metadata and controls
executable file
·91 lines (69 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
UNRECOVERABLE_ERROR_EXIT_CODE=69
# Check if build folder name is provided
if [ -z "$1" ]; then
printf "Error: No build folder name provided.\n"
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
# Check if conformance tests folder name is provided
if [ -z "$2" ]; then
printf "Error: No conformance tests folder name provided.\n"
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
current_dir=$(pwd)
echo "Current directory: $current_dir"
echo "Build folder name: $1"
echo "Conformance tests folder name: $2"
echo "--------------------------------"
PYTHON_BUILD_SUBFOLDER=python_$1
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
printf "Preparing Python build subfolder: $PYTHON_BUILD_SUBFOLDER\n"
fi
# Check if the Python build subfolder exists
if [ -d "$PYTHON_BUILD_SUBFOLDER" ]; then
# Find and delete all files and folders
find "$PYTHON_BUILD_SUBFOLDER" -mindepth 1 -exec rm -rf {} +
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
printf "Cleanup completed.\n"
fi
else
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
printf "Subfolder does not exist. Creating it...\n"
fi
mkdir -p $PYTHON_BUILD_SUBFOLDER
fi
cp -R $1/* $PYTHON_BUILD_SUBFOLDER
# Move to the subfolder
cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null
if [ $? -ne 0 ]; then
printf "Error: Python build folder '$PYTHON_BUILD_SUBFOLDER' does not exist.\n"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
printf "Creating and activating virtual environment...\n"
# Time the virtual environment creation and activation
start_time=$(date +%s.%N)
# Install requirements if requirements.txt exists
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
else
echo "Warning: requirements.txt not found. Cannot proceed with setting up requirements. The requirements may also already be installed"
fi
end_time=$(date +%s.%N)
# Calculate and display the time taken
duration=$(echo "$end_time - $start_time" | bc)
printf "Requirements setup completed in %.2f seconds\n\n" "$duration"
# Execute all Python conformance tests in the build folder
printf "Running Python conformance tests in the conformance tests folder...\n\n"
output=$(python -m unittest discover -b -s "$current_dir/$2" 2>&1)
exit_code=$?
# Echo the original output
echo "$output"
# Check if no tests were discovered
if echo "$output" | grep -q "Ran 0 tests in"; then
printf "\nError: No unittests discovered.\n"
exit 1
fi
# Echo the original exit code of the unittest command
exit $exit_code