init
This commit is contained in:
77
run_tests.py
Normal file
77
run_tests.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Run unit tests for the trading bot.
|
||||
|
||||
This script runs the unit tests defined in tests.py and displays the results.
|
||||
It can run a single test or all tests.
|
||||
|
||||
Usage:
|
||||
python run_tests.py [test_name]
|
||||
|
||||
If test_name is provided, only that test will be run.
|
||||
Otherwise, all tests will be run.
|
||||
|
||||
Example:
|
||||
python run_tests.py TestPeriodicUpdates
|
||||
python run_tests.py TestBacktesting
|
||||
python run_tests.py TestBacktestingLastSevenDays
|
||||
python run_tests.py TestSingleDayBacktesting
|
||||
python run_tests.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
import logging
|
||||
from tests import (
|
||||
TestPeriodicUpdates,
|
||||
TestBacktesting,
|
||||
TestBacktestingLastSevenDays,
|
||||
TestSingleDayBacktesting
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
handlers=[logging.StreamHandler()])
|
||||
|
||||
# Get the test name from the command line
|
||||
test_name = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
|
||||
# Run the specified test or all tests
|
||||
if test_name:
|
||||
logging.info(f"Running test: {test_name}")
|
||||
if test_name == "TestPeriodicUpdates":
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestPeriodicUpdates)
|
||||
elif test_name == "TestBacktesting":
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestBacktesting)
|
||||
elif test_name == "TestBacktestingLastSevenDays":
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestBacktestingLastSevenDays)
|
||||
elif test_name == "TestSingleDayBacktesting":
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestSingleDayBacktesting)
|
||||
else:
|
||||
logging.error(f"Unknown test: {test_name}")
|
||||
logging.info("Available tests: TestPeriodicUpdates, TestBacktesting, TestBacktestingLastSevenDays, TestSingleDayBacktesting")
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Run all tests
|
||||
logging.info("Running all tests")
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestPeriodicUpdates))
|
||||
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestBacktesting))
|
||||
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestBacktestingLastSevenDays))
|
||||
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSingleDayBacktesting))
|
||||
|
||||
# Run the tests
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
result = runner.run(suite)
|
||||
|
||||
# Print summary
|
||||
print("\nTest Summary:")
|
||||
print(f" Ran {result.testsRun} tests")
|
||||
print(f" Errors: {len(result.errors)}")
|
||||
print(f" Failures: {len(result.failures)}")
|
||||
print(f" Skipped: {len(result.skipped)}")
|
||||
|
||||
# Exit with non-zero status if any tests failed
|
||||
sys.exit(len(result.errors) + len(result.failures))
|
Reference in New Issue
Block a user