Spaces:
Configuration error
Configuration error
mike dupont commited on
Commit Β·
07e5088
1
Parent(s): 5470877
Add test script for app.py
Browse filesTests without launching server:
- Import validation
- Syntax checking
- Function existence
- Interface creation
All 4 tests passing β
- test_app.py +71 -0
test_app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script for app.py - validates without launching server
|
| 4 |
+
"""
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
def test_imports():
|
| 8 |
+
"""Test that all imports work"""
|
| 9 |
+
try:
|
| 10 |
+
import gradio as gr
|
| 11 |
+
print("β gradio imported")
|
| 12 |
+
return True
|
| 13 |
+
except ImportError as e:
|
| 14 |
+
print(f"β Import failed: {e}")
|
| 15 |
+
return False
|
| 16 |
+
|
| 17 |
+
def test_syntax():
|
| 18 |
+
"""Test Python syntax"""
|
| 19 |
+
try:
|
| 20 |
+
with open('app.py', 'r') as f:
|
| 21 |
+
compile(f.read(), 'app.py', 'exec')
|
| 22 |
+
print("β Syntax valid")
|
| 23 |
+
return True
|
| 24 |
+
except SyntaxError as e:
|
| 25 |
+
print(f"β Syntax error: {e}")
|
| 26 |
+
return False
|
| 27 |
+
|
| 28 |
+
def test_function_exists():
|
| 29 |
+
"""Test that main function exists"""
|
| 30 |
+
try:
|
| 31 |
+
import app
|
| 32 |
+
assert hasattr(app, 'create_game_interface')
|
| 33 |
+
print("β create_game_interface() exists")
|
| 34 |
+
return True
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"β Function test failed: {e}")
|
| 37 |
+
return False
|
| 38 |
+
|
| 39 |
+
def test_interface_creation():
|
| 40 |
+
"""Test interface can be created without launching"""
|
| 41 |
+
try:
|
| 42 |
+
import app
|
| 43 |
+
demo = app.create_game_interface()
|
| 44 |
+
print("β Interface created successfully")
|
| 45 |
+
print(f" Components: {len(demo.blocks)}")
|
| 46 |
+
return True
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"β Interface creation failed: {e}")
|
| 49 |
+
return False
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
print("π§ͺ Testing app.py\n")
|
| 53 |
+
|
| 54 |
+
tests = [
|
| 55 |
+
test_imports,
|
| 56 |
+
test_syntax,
|
| 57 |
+
test_function_exists,
|
| 58 |
+
test_interface_creation,
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
results = [test() for test in tests]
|
| 62 |
+
|
| 63 |
+
print(f"\n{'='*50}")
|
| 64 |
+
print(f"Results: {sum(results)}/{len(results)} tests passed")
|
| 65 |
+
|
| 66 |
+
if all(results):
|
| 67 |
+
print("β
All tests passed!")
|
| 68 |
+
sys.exit(0)
|
| 69 |
+
else:
|
| 70 |
+
print("β Some tests failed")
|
| 71 |
+
sys.exit(1)
|