run ruff
This commit is contained in:
@@ -6,21 +6,18 @@ Runs all test suites and generates a comprehensive test report
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class ColoredTextTestResult(unittest.TextTestResult):
|
||||
"""Custom test result class with colored output"""
|
||||
|
||||
# ANSI color codes
|
||||
GREEN = '\033[92m'
|
||||
RED = '\033[91m'
|
||||
YELLOW = '\033[93m'
|
||||
BLUE = '\033[94m'
|
||||
RESET = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
GREEN = "\033[92m"
|
||||
RED = "\033[91m"
|
||||
YELLOW = "\033[93m"
|
||||
BLUE = "\033[94m"
|
||||
RESET = "\033[0m"
|
||||
BOLD = "\033[1m"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -28,7 +25,7 @@ class ColoredTextTestResult(unittest.TextTestResult):
|
||||
|
||||
def addSuccess(self, test):
|
||||
super().addSuccess(test)
|
||||
self.test_results.append(('PASS', test))
|
||||
self.test_results.append(("PASS", test))
|
||||
if self.showAll:
|
||||
self.stream.write(f"{self.GREEN}✓ PASS{self.RESET}\n")
|
||||
elif self.dots:
|
||||
@@ -37,7 +34,7 @@ class ColoredTextTestResult(unittest.TextTestResult):
|
||||
|
||||
def addError(self, test, err):
|
||||
super().addError(test, err)
|
||||
self.test_results.append(('ERROR', test))
|
||||
self.test_results.append(("ERROR", test))
|
||||
if self.showAll:
|
||||
self.stream.write(f"{self.RED}✗ ERROR{self.RESET}\n")
|
||||
elif self.dots:
|
||||
@@ -46,7 +43,7 @@ class ColoredTextTestResult(unittest.TextTestResult):
|
||||
|
||||
def addFailure(self, test, err):
|
||||
super().addFailure(test, err)
|
||||
self.test_results.append(('FAIL', test))
|
||||
self.test_results.append(("FAIL", test))
|
||||
if self.showAll:
|
||||
self.stream.write(f"{self.RED}✗ FAIL{self.RESET}\n")
|
||||
elif self.dots:
|
||||
@@ -55,7 +52,7 @@ class ColoredTextTestResult(unittest.TextTestResult):
|
||||
|
||||
def addSkip(self, test, reason):
|
||||
super().addSkip(test, reason)
|
||||
self.test_results.append(('SKIP', test))
|
||||
self.test_results.append(("SKIP", test))
|
||||
if self.showAll:
|
||||
self.stream.write(f"{self.YELLOW}⊘ SKIP{self.RESET}\n")
|
||||
elif self.dots:
|
||||
@@ -65,14 +62,15 @@ class ColoredTextTestResult(unittest.TextTestResult):
|
||||
|
||||
class ColoredTextTestRunner(unittest.TextTestRunner):
|
||||
"""Custom test runner with colored output"""
|
||||
|
||||
resultclass = ColoredTextTestResult
|
||||
|
||||
|
||||
def discover_tests(test_dir='tests'):
|
||||
def discover_tests(test_dir="tests"):
|
||||
"""Discover all test files in the tests directory"""
|
||||
loader = unittest.TestLoader()
|
||||
start_dir = test_dir
|
||||
pattern = 'test_*.py'
|
||||
pattern = "test_*.py"
|
||||
|
||||
suite = loader.discover(start_dir, pattern=pattern)
|
||||
return suite
|
||||
@@ -83,9 +81,9 @@ def run_specific_suite(suite_name):
|
||||
loader = unittest.TestLoader()
|
||||
|
||||
suite_map = {
|
||||
'config': 'tests.test_config_validation',
|
||||
'features': 'tests.test_scraper_features',
|
||||
'integration': 'tests.test_integration'
|
||||
"config": "tests.test_config_validation",
|
||||
"features": "tests.test_scraper_features",
|
||||
"integration": "tests.test_integration",
|
||||
}
|
||||
|
||||
if suite_name not in suite_map:
|
||||
@@ -110,9 +108,9 @@ def print_summary(result):
|
||||
errors = len(result.errors)
|
||||
skipped = len(result.skipped)
|
||||
|
||||
print("\n" + "="*70)
|
||||
print("\n" + "=" * 70)
|
||||
print("TEST SUMMARY")
|
||||
print("="*70)
|
||||
print("=" * 70)
|
||||
|
||||
# Overall stats
|
||||
print(f"\n{ColoredTextTestResult.BOLD}Total Tests:{ColoredTextTestResult.RESET} {total}")
|
||||
@@ -127,31 +125,35 @@ def print_summary(result):
|
||||
# Success rate
|
||||
if total > 0:
|
||||
success_rate = (passed / total) * 100
|
||||
color = ColoredTextTestResult.GREEN if success_rate == 100 else \
|
||||
ColoredTextTestResult.YELLOW if success_rate >= 80 else \
|
||||
ColoredTextTestResult.RED
|
||||
color = (
|
||||
ColoredTextTestResult.GREEN
|
||||
if success_rate == 100
|
||||
else ColoredTextTestResult.YELLOW
|
||||
if success_rate >= 80
|
||||
else ColoredTextTestResult.RED
|
||||
)
|
||||
print(f"\n{color}Success Rate: {success_rate:.1f}%{ColoredTextTestResult.RESET}")
|
||||
|
||||
# Category breakdown
|
||||
if hasattr(result, 'test_results'):
|
||||
if hasattr(result, "test_results"):
|
||||
print(f"\n{ColoredTextTestResult.BOLD}Test Breakdown by Category:{ColoredTextTestResult.RESET}")
|
||||
|
||||
categories = {}
|
||||
for status, test in result.test_results:
|
||||
test_name = str(test)
|
||||
# Extract test class name
|
||||
if '.' in test_name:
|
||||
class_name = test_name.split('.')[0].split()[-1]
|
||||
if "." in test_name:
|
||||
class_name = test_name.split(".")[0].split()[-1]
|
||||
if class_name not in categories:
|
||||
categories[class_name] = {'PASS': 0, 'FAIL': 0, 'ERROR': 0, 'SKIP': 0}
|
||||
categories[class_name] = {"PASS": 0, "FAIL": 0, "ERROR": 0, "SKIP": 0}
|
||||
categories[class_name][status] += 1
|
||||
|
||||
for category, stats in sorted(categories.items()):
|
||||
total_cat = sum(stats.values())
|
||||
passed_cat = stats['PASS']
|
||||
passed_cat = stats["PASS"]
|
||||
print(f" {category}: {passed_cat}/{total_cat} passed")
|
||||
|
||||
print("\n" + "="*70)
|
||||
print("\n" + "=" * 70)
|
||||
|
||||
# Return status
|
||||
return failed == 0 and errors == 0
|
||||
@@ -162,20 +164,14 @@ def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Run tests for Skill Seeker',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
description="Run tests for Skill Seeker", formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
|
||||
parser.add_argument('--suite', '-s', type=str,
|
||||
help='Run specific test suite (config, features, integration)')
|
||||
parser.add_argument('--verbose', '-v', action='store_true',
|
||||
help='Verbose output (show each test)')
|
||||
parser.add_argument('--quiet', '-q', action='store_true',
|
||||
help='Quiet output (minimal output)')
|
||||
parser.add_argument('--failfast', '-f', action='store_true',
|
||||
help='Stop on first failure')
|
||||
parser.add_argument('--list', '-l', action='store_true',
|
||||
help='List all available tests')
|
||||
parser.add_argument("--suite", "-s", type=str, help="Run specific test suite (config, features, integration)")
|
||||
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output (show each test)")
|
||||
parser.add_argument("--quiet", "-q", action="store_true", help="Quiet output (minimal output)")
|
||||
parser.add_argument("--failfast", "-f", action="store_true", help="Stop on first failure")
|
||||
parser.add_argument("--list", "-l", action="store_true", help="List all available tests")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -186,9 +182,9 @@ def main():
|
||||
elif args.quiet:
|
||||
verbosity = 0
|
||||
|
||||
print(f"\n{ColoredTextTestResult.BOLD}{'='*70}{ColoredTextTestResult.RESET}")
|
||||
print(f"\n{ColoredTextTestResult.BOLD}{'=' * 70}{ColoredTextTestResult.RESET}")
|
||||
print(f"{ColoredTextTestResult.BOLD}SKILL SEEKER TEST SUITE{ColoredTextTestResult.RESET}")
|
||||
print(f"{ColoredTextTestResult.BOLD}{'='*70}{ColoredTextTestResult.RESET}\n")
|
||||
print(f"{ColoredTextTestResult.BOLD}{'=' * 70}{ColoredTextTestResult.RESET}\n")
|
||||
|
||||
# Discover or load specific suite
|
||||
if args.suite:
|
||||
@@ -210,10 +206,7 @@ def main():
|
||||
return 0
|
||||
|
||||
# Run tests
|
||||
runner = ColoredTextTestRunner(
|
||||
verbosity=verbosity,
|
||||
failfast=args.failfast
|
||||
)
|
||||
runner = ColoredTextTestRunner(verbosity=verbosity, failfast=args.failfast)
|
||||
|
||||
result = runner.run(suite)
|
||||
|
||||
@@ -224,5 +217,5 @@ def main():
|
||||
return 0 if success else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user