feat: Add test scripts and runner for TheChart application
- Created demo_failing_test.py to demonstrate pre-commit blocking with a failing test. - Added run_tests.py for executing all tests with coverage reporting. - Introduced test.py as a quick test runner for the application, providing coverage reports and user-friendly output.
This commit is contained in:
19
scripts/demo_failing_test.py
Normal file
19
scripts/demo_failing_test.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""
|
||||
Demonstration script to show pre-commit test blocking.
|
||||
This creates a temporary failing test to demonstrate the pre-commit behavior.
|
||||
"""
|
||||
|
||||
# Create a simple test file that will fail
|
||||
test_content = '''
|
||||
def test_that_will_fail():
|
||||
"""This test is designed to fail to demonstrate pre-commit blocking."""
|
||||
assert False, "This test intentionally fails"
|
||||
'''
|
||||
|
||||
with open("tests/test_demo_fail.py", "w") as f:
|
||||
f.write(test_content)
|
||||
|
||||
print("Created temporary failing test: tests/test_demo_fail.py")
|
||||
print("Now try: git add . && git commit -m 'test commit'")
|
||||
print("The commit should be blocked by the failing test.")
|
||||
print("Remove the file with: rm tests/test_demo_fail.py")
|
||||
45
scripts/run_tests.py
Normal file
45
scripts/run_tests.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test runner script for TheChart application.
|
||||
Run this script to execute all tests with coverage reporting.
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def run_tests():
|
||||
"""Run all tests with coverage reporting."""
|
||||
|
||||
# Change to project root directory
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
os.chdir(project_root)
|
||||
|
||||
print("Running TheChart tests with coverage...")
|
||||
print(f"Project root: {project_root}")
|
||||
|
||||
# Run pytest with coverage
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pytest",
|
||||
"tests/",
|
||||
"--verbose",
|
||||
"--cov=src",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-report=html:htmlcov",
|
||||
"--cov-report=xml",
|
||||
]
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, check=False)
|
||||
return result.returncode
|
||||
except Exception as e:
|
||||
print(f"Error running tests: {e}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = run_tests()
|
||||
sys.exit(exit_code)
|
||||
51
scripts/test.py
Executable file
51
scripts/test.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick test runner for TheChart application.
|
||||
This script provides a simple way to run the test suite.
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the test suite."""
|
||||
print("🧪 Running TheChart Test Suite")
|
||||
print("=" * 50)
|
||||
|
||||
# Change to project directory
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Run tests with coverage
|
||||
cmd = [
|
||||
"uv",
|
||||
"run",
|
||||
"pytest",
|
||||
"tests/",
|
||||
"--cov=src",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-report=html:htmlcov",
|
||||
"-v",
|
||||
]
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, check=False)
|
||||
if result.returncode == 0:
|
||||
print("\n✅ All tests passed!")
|
||||
else:
|
||||
print(f"\n❌ Some tests failed (exit code: {result.returncode})")
|
||||
|
||||
print("\n📊 Coverage report generated in htmlcov/index.html")
|
||||
return result.returncode
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n⚠️ Tests interrupted by user")
|
||||
return 1
|
||||
except Exception as e:
|
||||
print(f"\n💥 Error running tests: {e}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user