-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_unittest_script.sh
More file actions
executable file
·61 lines (47 loc) · 1.46 KB
/
run_unittest_script.sh
File metadata and controls
executable file
·61 lines (47 loc) · 1.46 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
#!/bin/bash
UNRECOVERABLE_ERROR_EXIT_CODE=69
# Check if project folder name is provided
if [ -z "$1" ]; then
echo "Error: No project folder name provided."
echo "Usage: $0 <project_folder_name>"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
PROJECT_FOLDER=$1
PYTHON_BUILD_SUBFOLDER=".tmp/$1"
echo "Preparing Python environment in: $PYTHON_BUILD_SUBFOLDER"
# Clean up or create the build subfolder
if [ -d "$PYTHON_BUILD_SUBFOLDER" ]; then
find "$PYTHON_BUILD_SUBFOLDER" -mindepth 1 -exec rm -rf {} +
else
mkdir -p "$PYTHON_BUILD_SUBFOLDER"
fi
# Copy project files
cp -R "$PROJECT_FOLDER"/* "$PYTHON_BUILD_SUBFOLDER"
# Move to the subfolder
cd "$PYTHON_BUILD_SUBFOLDER" || exit $UNRECOVERABLE_ERROR_EXIT_CODE
# Setup Virtual Environment
echo "Creating and activating virtual environment..."
python3 -m venv venv
source venv/bin/activate
# Install requirements
if [ -f "requirements.txt" ]; then
pip install --upgrade pip
pip install -r requirements.txt
else
echo "Warning: requirements.txt not found. Installing default dependencies..."
pip install slack_sdk python-dotenv
fi
# Execute Python unittests
echo "Running Python unittests..."
# Using -b to buffer stdout/stderr and -v for verbosity
output=$(timeout 120s python3 -m unittest discover -b -v 2>&1)
exit_code=$?
# Check for timeout
if [ $exit_code -eq 124 ]; then
echo "Error: Unittests timed out after 120 seconds."
exit $exit_code
fi
echo "$output"
# Deactivate venv
deactivate
exit $exit_code