-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_installation.py
More file actions
161 lines (130 loc) Β· 5.75 KB
/
test_installation.py
File metadata and controls
161 lines (130 loc) Β· 5.75 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
#!/usr/bin/env python3
"""Test script to verify RegexGenerator installation works correctly."""
import sys
import subprocess
import os
from pathlib import Path
def test_virtual_env_installation():
"""Test virtual environment installation process."""
print("π§ͺ Testing virtual environment installation...")
# Check if we're in the right directory
if not Path("pyproject.toml").exists():
print("β Run this script from the regexgenerator root directory")
return False
# Test virtual environment creation and activation
try:
print("1. Testing virtual environment creation...")
result = subprocess.run([sys.executable, "-m", "venv", "test_venv"],
capture_output=True, text=True)
if result.returncode != 0:
print(f"β Virtual environment creation failed: {result.stderr}")
return False
print("β Virtual environment created successfully")
# Determine activation script path
if os.name == 'nt': # Windows
pip_path = Path("test_venv/Scripts/pip")
python_path = Path("test_venv/Scripts/python")
else: # Unix/Linux/macOS
pip_path = Path("test_venv/bin/pip")
python_path = Path("test_venv/bin/python")
# Test dependency installation
print("2. Testing dependency installation...")
result = subprocess.run([str(pip_path), "install", "-r", "requirements.txt"],
capture_output=True, text=True)
if result.returncode != 0:
print(f"β Dependency installation failed: {result.stderr}")
return False
print("β Dependencies installed successfully")
# Test package installation
print("3. Testing package installation...")
result = subprocess.run([str(pip_path), "install", "-e", "."],
capture_output=True, text=True)
if result.returncode != 0:
print(f"β Package installation failed: {result.stderr}")
return False
print("β Package installed successfully")
# Test CLI functionality
print("4. Testing CLI functionality...")
if os.name == 'nt':
regexgen_path = Path("test_venv/Scripts/regexgen")
else:
regexgen_path = Path("test_venv/bin/regexgen")
result = subprocess.run([str(regexgen_path), "--help"],
capture_output=True, text=True, timeout=10)
if result.returncode != 0:
print(f"β CLI test failed: {result.stderr}")
return False
if "RegexGenerator" not in result.stdout:
print(f"β CLI output doesn't contain expected text: {result.stdout}")
return False
print("β CLI working correctly")
return True
except Exception as e:
print(f"β Installation test failed with exception: {e}")
return False
finally:
# Cleanup
if Path("test_venv").exists():
import shutil
shutil.rmtree("test_venv")
print("π§Ή Cleaned up test environment")
def test_direct_execution():
"""Test direct execution without installation."""
print("\nπ§ͺ Testing direct execution...")
try:
# Test module execution
result = subprocess.run([sys.executable, "-m", "regexgen", "--help"],
cwd="src", capture_output=True, text=True, timeout=10)
if result.returncode != 0:
print(f"β Direct execution failed: {result.stderr}")
return False
if "RegexGenerator" not in result.stdout:
print(f"β Direct execution output doesn't contain expected text")
return False
print("β Direct execution working correctly")
return True
except Exception as e:
print(f"β Direct execution test failed: {e}")
return False
def test_basic_functionality():
"""Test basic pattern generation functionality."""
print("\nπ§ͺ Testing basic functionality...")
try:
# Test basic pattern generation
result = subprocess.run([
sys.executable, "-m", "regexgen",
"--max-iterations", "10", # Quick test
"--seed", "42", # Reproducible
"test", "best", "rest"
], cwd="src", capture_output=True, text=True, timeout=30)
if result.returncode != 0:
print(f"β Basic functionality test failed: {result.stderr}")
return False
# Check that some pattern was generated
if not result.stdout.strip() or "Error" in result.stdout:
print(f"β No valid pattern generated: {result.stdout}")
return False
print("β Basic functionality working")
print(f" Generated pattern: {result.stdout.strip().split()[-1]}")
return True
except Exception as e:
print(f"β Basic functionality test failed: {e}")
return False
if __name__ == "__main__":
print("π RegexGenerator Installation Test Suite")
print("=" * 50)
success = True
# Test 1: Virtual environment installation
success &= test_virtual_env_installation()
# Test 2: Direct execution
success &= test_direct_execution()
# Test 3: Basic functionality
success &= test_basic_functionality()
print("\n" + "=" * 50)
if success:
print("π All installation tests passed!")
print("RegexGenerator is ready for use!")
else:
print("β Some installation tests failed.")
print("Check the error messages above for details.")
sys.exit(1)