forked from AmberLee2427/microlens-submit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dossier_fresh.sh
More file actions
executable file
·166 lines (132 loc) · 4.72 KB
/
test_dossier_fresh.sh
File metadata and controls
executable file
·166 lines (132 loc) · 4.72 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# Test script for microlens-submit dossier generation with fresh environment
# This script creates a temporary virtual environment, installs the current version,
# runs the dossier generation test, and cleans up afterward.
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
VENV_NAME="microlens_test_env"
LOG_FILE="test_dossier_output.log"
TEST_SCRIPT="tests/test_dossier_generation.py"
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to cleanup on exit
cleanup() {
print_status "Cleaning up..."
# Deactivate virtual environment if active
if [[ "$VIRTUAL_ENV" != "" ]]; then
print_status "Deactivating virtual environment..."
deactivate
fi
# Remove virtual environment
if [[ -d "$VENV_NAME" ]]; then
print_status "Removing virtual environment: $VENV_NAME"
rm -rf "$VENV_NAME"
fi
# Remove test artifacts
if [[ -d "test_submission_project" ]]; then
print_status "Removing test submission project..."
rm -rf "test_submission_project"
fi
if [[ -d "test_dossier_output" ]]; then
print_status "Removing test dossier output..."
rm -rf "test_dossier_output"
fi
print_success "Cleanup completed"
}
# Set up trap to cleanup on script exit
trap cleanup EXIT
# Start logging
print_status "Starting fresh test of microlens-submit dossier generation"
print_status "Log file: $LOG_FILE"
exec > >(tee -a "$LOG_FILE") 2>&1
echo "=========================================="
echo "Test started at: $(date)"
echo "=========================================="
# Check if we're in the right directory
if [[ ! -f "pyproject.toml" ]]; then
print_error "pyproject.toml not found. Please run this script from the project root directory."
exit 1
fi
if [[ ! -f "$TEST_SCRIPT" ]]; then
print_error "Test script not found: $TEST_SCRIPT"
exit 1
fi
print_status "Current directory: $(pwd)"
print_status "Python version: $(python3 --version)"
# Create virtual environment
print_status "Creating virtual environment: $VENV_NAME"
python3 -m venv "$VENV_NAME"
# Activate virtual environment
print_status "Activating virtual environment..."
source "$VENV_NAME/bin/activate"
print_status "Virtual environment activated: $VIRTUAL_ENV"
print_status "Python version in venv: $(python --version)"
# Upgrade pip
print_status "Upgrading pip..."
pip install --upgrade pip
# Install the package in editable mode
print_status "Installing microlens-submit in editable mode..."
pip install markdown
pip install -e ".[dev]"
# Verify installation
print_status "Verifying installation..."
microlens_submit_version=$(python -c "import microlens_submit; print(microlens_submit.__version__)")
print_success "Installed microlens-submit version: $microlens_submit_version"
# Test that the CLI works
print_status "Testing CLI availability..."
if command -v microlens-submit &> /dev/null; then
print_success "CLI command available"
microlens-submit version
else
print_warning "CLI command not found in PATH, but package is installed"
fi
# Run the test script
print_status "Running dossier generation test..."
echo "=========================================="
echo "Test output:"
echo "=========================================="
if python "$TEST_SCRIPT"; then
print_success "Test completed successfully!"
else
print_error "Test failed!"
exit 1
fi
echo "=========================================="
echo "Test completed at: $(date)"
echo "=========================================="
print_success "All tests passed! Check the generated dossier in test_dossier_output/index.html"
print_status "Log file saved to: $LOG_FILE"
# Offer to serve the dossier with a local HTTP server
read -p $'\nWould you like to serve the dossier with a local HTTP server for browser testing? (y/n): ' serve_choice
if [[ "$serve_choice" =~ ^[Yy]$ ]]; then
if command -v python3 &> /dev/null; then
print_status "Starting local HTTP server in test_submission_project/dossier..."
(cd test_submission_project/dossier && python3 -m http.server 8000)
print_status "Server stopped."
else
print_warning "python3 not found. Cannot start HTTP server."
fi
else
print_status "Skipping HTTP server."
fi
# Always prompt before cleanup, after the server (or skip)
read -p $'\nPress enter to clean up and remove the test environment and output files...'
# Don't cleanup here - let the trap handle it
print_status "Script completed successfully"