Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for TutorX UI/UX enhancements | |
| This script validates the UI improvements and provides a quick way to test the interface. | |
| """ | |
| import sys | |
| import os | |
| import subprocess | |
| import time | |
| from pathlib import Path | |
| def check_dependencies(): | |
| """Check if required dependencies are installed""" | |
| required_packages = [ | |
| 'gradio', | |
| 'matplotlib', | |
| 'networkx', | |
| 'requests' | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package) | |
| print(f"β {package} is installed") | |
| except ImportError: | |
| missing_packages.append(package) | |
| print(f"β {package} is missing") | |
| if missing_packages: | |
| print(f"\nβ οΈ Missing packages: {', '.join(missing_packages)}") | |
| print("Install them with: pip install " + " ".join(missing_packages)) | |
| return False | |
| return True | |
| def validate_ui_components(): | |
| """Validate that UI enhancement components are properly implemented""" | |
| print("\nπ Validating UI components...") | |
| try: | |
| # Import the app module to check for syntax errors | |
| sys.path.insert(0, os.getcwd()) | |
| import app | |
| # Check if helper functions exist | |
| helper_functions = [ | |
| 'create_info_card', | |
| 'create_status_display', | |
| 'create_feature_section' | |
| ] | |
| for func_name in helper_functions: | |
| if hasattr(app, func_name): | |
| print(f"β {func_name} function is available") | |
| else: | |
| print(f"β {func_name} function is missing") | |
| return False | |
| # Check if the main interface function exists | |
| if hasattr(app, 'create_gradio_interface'): | |
| print("β create_gradio_interface function is available") | |
| else: | |
| print("β create_gradio_interface function is missing") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"β Error importing app module: {str(e)}") | |
| return False | |
| def test_interface_creation(): | |
| """Test if the Gradio interface can be created without errors""" | |
| print("\nπ§ͺ Testing interface creation...") | |
| try: | |
| sys.path.insert(0, os.getcwd()) | |
| import app | |
| # Try to create the interface | |
| demo = app.create_gradio_interface() | |
| print("β Gradio interface created successfully") | |
| # Check if demo has the expected properties | |
| if hasattr(demo, 'queue'): | |
| print("β Interface has queue method") | |
| else: | |
| print("β Interface missing queue method") | |
| return True | |
| except Exception as e: | |
| print(f"β Error creating interface: {str(e)}") | |
| return False | |
| def run_ui_test(): | |
| """Run a quick UI test by launching the interface briefly""" | |
| print("\nπ Running UI test...") | |
| try: | |
| # Launch the app in a subprocess for a brief test | |
| process = subprocess.Popen( | |
| [sys.executable, "app.py"], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True | |
| ) | |
| # Wait a few seconds to see if it starts successfully | |
| time.sleep(3) | |
| if process.poll() is None: | |
| print("β UI launched successfully") | |
| process.terminate() | |
| process.wait() | |
| return True | |
| else: | |
| stdout, stderr = process.communicate() | |
| print(f"β UI failed to launch") | |
| if stderr: | |
| print(f"Error: {stderr}") | |
| return False | |
| except Exception as e: | |
| print(f"β Error running UI test: {str(e)}") | |
| return False | |
| def check_documentation(): | |
| """Check if UI/UX documentation exists""" | |
| print("\nπ Checking documentation...") | |
| doc_file = Path("docs/UI_UX_ENHANCEMENTS.md") | |
| if doc_file.exists(): | |
| print("β UI/UX enhancement documentation exists") | |
| # Check file size to ensure it has content | |
| if doc_file.stat().st_size > 1000: | |
| print("β Documentation has substantial content") | |
| else: | |
| print("β οΈ Documentation file is quite small") | |
| return True | |
| else: | |
| print("β UI/UX enhancement documentation is missing") | |
| return False | |
| def main(): | |
| """Main test function""" | |
| print("π§ TutorX UI/UX Enhancement Test Suite") | |
| print("=" * 50) | |
| tests = [ | |
| ("Dependencies Check", check_dependencies), | |
| ("UI Components Validation", validate_ui_components), | |
| ("Interface Creation Test", test_interface_creation), | |
| ("Documentation Check", check_documentation), | |
| ("UI Launch Test", run_ui_test) | |
| ] | |
| results = [] | |
| for test_name, test_func in tests: | |
| print(f"\nπ Running: {test_name}") | |
| try: | |
| result = test_func() | |
| results.append((test_name, result)) | |
| except Exception as e: | |
| print(f"β Test failed with exception: {str(e)}") | |
| results.append((test_name, False)) | |
| # Summary | |
| print("\n" + "=" * 50) | |
| print("π Test Results Summary:") | |
| print("=" * 50) | |
| passed = 0 | |
| total = len(results) | |
| for test_name, result in results: | |
| status = "β PASSED" if result else "β FAILED" | |
| print(f"{test_name}: {status}") | |
| if result: | |
| passed += 1 | |
| print(f"\nOverall: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("π All tests passed! UI enhancements are working correctly.") | |
| print("\nπ You can now run the app with: python app.py") | |
| else: | |
| print("β οΈ Some tests failed. Please check the issues above.") | |
| return passed == total | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) | |