#!/usr/bin/env python3 """ Comprehensive Build and Test Runner for Project Unknown """ import os import sys import subprocess import unittest from datetime import datetime def print_header(title): """Print a formatted header.""" print(f"\n{'='*50}") print(f" {title}") print(f"{'='*50}\n") def print_section(title): """Print a formatted section header.""" print(f"\n--- {title} ---") def check_environment(): """Check the environment and available tools.""" print_header("ENVIRONMENT CHECK") print(f"Python Version: {sys.version}") print(f"Current Directory: {os.getcwd()}") print(f"Timestamp: {datetime.now()}") # Check if we're in a git repo if os.path.exists('.git'): print("✓ Git repository detected") try: result = subprocess.run(['git', 'branch'], capture_output=True, text=True) if 'main' in result.stdout: print("✓ Currently on main branch") else: print("Current branches:", result.stdout.strip()) except: print("✗ Git command failed") else: print("✗ No git repository detected") def list_project_files(): """List all project files.""" print_section("PROJECT FILES") try: files = os.listdir('.') for file in sorted(files): if os.path.isfile(file): size = os.path.getsize(file) print(f" {file} ({size} bytes)") except Exception as e: print(f"Error listing files: {e}") def run_python_tests(): """Run Python unit tests.""" print_section("RUNNING PYTHON TESTS") try: # Import and run tests directly sys.path.insert(0, os.getcwd()) from test_project_unknown import TestProjectUnknown # Create test suite suite = unittest.TestLoader().loadTestsFromTestCase(TestProjectUnknown) # Run tests runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) # Print summary print(f"\nTests run: {result.testsRun}") print(f"Failures: {len(result.failures)}") print(f"Errors: {len(result.errors)}") if result.failures: print("\nFailures:") for test, traceback in result.failures: print(f" - {test}: {traceback}") if result.errors: print("\nErrors:") for test, traceback in result.errors: print(f" - {test}: {traceback}") return result.wasSuccessful() except Exception as e: print(f"Error running tests: {e}") return False def run_main_module(): """Test the main module.""" print_section("TESTING MAIN MODULE") try: sys.path.insert(0, os.getcwd()) from project_unknown import main print("Executing main() function...") main() print("✓ Main module executed successfully") return True except Exception as e: print(f"✗ Main module execution failed: {e}") return False def check_code_quality(): """Basic code quality checks.""" print_section("CODE QUALITY CHECKS") # Check if main module has proper structure try: with open('project_unknown.py', 'r') as f: content = f.read() checks = [ ("docstring in module", '"""' in content), ("function definitions", 'def ' in content), ("main guard", 'if __name__' in content), ] for check_name, result in checks: status = "✓" if result else "✗" print(f" {status} {check_name}") except Exception as e: print(f"Error in code quality checks: {e}") def main(): """Main build and test runner.""" print_header("PROJECT UNKNOWN - BUILD AND TEST") print("Branch: main") print("Latest commit: No commits yet") # Check environment check_environment() # List files list_project_files() # Run tests tests_passed = run_python_tests() # Run main module main_works = run_main_module() # Code quality check_code_quality() # Final summary print_header("BUILD AND TEST SUMMARY") if tests_passed and main_works: print("🎉 SUCCESS: All tests passed and main module works!") print("✓ Unit tests: PASSED") print("✓ Main module: WORKING") print("✓ Code quality: GOOD") return 0 else: print("❌ FAILURE: Some tests or functionality failed") if not tests_passed: print("✗ Unit tests: FAILED") if not main_works: print("✗ Main module: BROKEN") return 1 if __name__ == "__main__": exit_code = main() sys.exit(exit_code)