You've already forked FrameTour-RenderWorker
q
This commit is contained in:
161
run_tests.py
161
run_tests.py
@@ -16,11 +16,7 @@ def run_command(cmd, cwd=None):
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
cwd=cwd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False
|
||||
cmd, cwd=cwd, capture_output=True, text=True, check=False
|
||||
)
|
||||
if result.stdout:
|
||||
print(result.stdout)
|
||||
@@ -39,7 +35,9 @@ def check_dependencies():
|
||||
# 检查pytest
|
||||
if not run_command([sys.executable, "-c", "import pytest"]):
|
||||
print("pytest not found. Installing test dependencies...")
|
||||
if not run_command([sys.executable, "-m", "pip", "install", "-r", "requirements-test.txt"]):
|
||||
if not run_command(
|
||||
[sys.executable, "-m", "pip", "install", "-r", "requirements-test.txt"]
|
||||
):
|
||||
print("Failed to install test dependencies", file=sys.stderr)
|
||||
return False
|
||||
|
||||
@@ -56,22 +54,27 @@ def run_unit_tests(args):
|
||||
print("\n=== Running Unit Tests ===")
|
||||
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pytest",
|
||||
"tests/test_effects/",
|
||||
"tests/test_ffmpeg_builder/",
|
||||
"-v",
|
||||
"-m", "not integration"
|
||||
"-m",
|
||||
"not integration",
|
||||
]
|
||||
|
||||
if args.coverage:
|
||||
cmd.extend([
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:coverage.xml",
|
||||
"--cov-report=html:htmlcov",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-branch"
|
||||
])
|
||||
cmd.extend(
|
||||
[
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:coverage.xml",
|
||||
"--cov-report=html:htmlcov",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-branch",
|
||||
]
|
||||
)
|
||||
|
||||
if args.xml_report:
|
||||
cmd.extend(["--junitxml=unit-tests.xml"])
|
||||
@@ -92,21 +95,26 @@ def run_integration_tests(args):
|
||||
return True
|
||||
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pytest",
|
||||
"tests/test_integration/",
|
||||
"-v",
|
||||
"-m", "integration",
|
||||
"--timeout=300"
|
||||
"-m",
|
||||
"integration",
|
||||
"--timeout=300",
|
||||
]
|
||||
|
||||
if args.coverage:
|
||||
cmd.extend([
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:integration-coverage.xml",
|
||||
"--cov-report=html:integration-htmlcov",
|
||||
"--cov-branch"
|
||||
])
|
||||
cmd.extend(
|
||||
[
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:integration-coverage.xml",
|
||||
"--cov-report=html:integration-htmlcov",
|
||||
"--cov-branch",
|
||||
]
|
||||
)
|
||||
|
||||
if args.xml_report:
|
||||
cmd.extend(["--junitxml=integration-tests.xml"])
|
||||
@@ -121,21 +129,19 @@ def run_all_tests(args):
|
||||
"""运行所有测试"""
|
||||
print("\n=== Running All Tests ===")
|
||||
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
"tests/",
|
||||
"-v"
|
||||
]
|
||||
cmd = [sys.executable, "-m", "pytest", "tests/", "-v"]
|
||||
|
||||
if args.coverage:
|
||||
cmd.extend([
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:coverage.xml",
|
||||
"--cov-report=html:htmlcov",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-branch"
|
||||
])
|
||||
cmd.extend(
|
||||
[
|
||||
"--cov=entity",
|
||||
"--cov=services",
|
||||
"--cov-report=xml:coverage.xml",
|
||||
"--cov-report=html:htmlcov",
|
||||
"--cov-report=term-missing",
|
||||
"--cov-branch",
|
||||
]
|
||||
)
|
||||
|
||||
if args.fail_under:
|
||||
cmd.extend([f"--cov-fail-under={args.fail_under}"])
|
||||
@@ -154,17 +160,15 @@ def run_effect_tests(effect_name=None):
|
||||
if effect_name:
|
||||
print(f"\n=== Running {effect_name} Effect Tests ===")
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pytest",
|
||||
f"tests/test_effects/test_{effect_name}_effect.py",
|
||||
"-v"
|
||||
"-v",
|
||||
]
|
||||
else:
|
||||
print("\n=== Running All Effect Tests ===")
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
"tests/test_effects/",
|
||||
"-v"
|
||||
]
|
||||
cmd = [sys.executable, "-m", "pytest", "tests/test_effects/", "-v"]
|
||||
|
||||
return run_command(cmd)
|
||||
|
||||
@@ -174,14 +178,17 @@ def run_stress_tests():
|
||||
print("\n=== Running Stress Tests ===")
|
||||
|
||||
env = os.environ.copy()
|
||||
env['RUN_STRESS_TESTS'] = '1'
|
||||
env["RUN_STRESS_TESTS"] = "1"
|
||||
|
||||
cmd = [
|
||||
sys.executable, "-m", "pytest",
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pytest",
|
||||
"tests/test_integration/",
|
||||
"-v",
|
||||
"-m", "stress",
|
||||
"--timeout=600"
|
||||
"-m",
|
||||
"stress",
|
||||
"--timeout=600",
|
||||
]
|
||||
|
||||
return subprocess.run(cmd, env=env).returncode == 0
|
||||
@@ -201,13 +208,19 @@ def create_test_video():
|
||||
# 创建短视频文件
|
||||
video_path = test_data_dir / "sample.mp4"
|
||||
cmd = [
|
||||
"ffmpeg", "-y",
|
||||
"-f", "lavfi",
|
||||
"-i", "testsrc=duration=5:size=640x480:rate=25",
|
||||
"-c:v", "libx264",
|
||||
"-preset", "ultrafast",
|
||||
"-crf", "23",
|
||||
str(video_path)
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-f",
|
||||
"lavfi",
|
||||
"-i",
|
||||
"testsrc=duration=5:size=640x480:rate=25",
|
||||
"-c:v",
|
||||
"libx264",
|
||||
"-preset",
|
||||
"ultrafast",
|
||||
"-crf",
|
||||
"23",
|
||||
str(video_path),
|
||||
]
|
||||
|
||||
if run_command(cmd):
|
||||
@@ -220,16 +233,30 @@ def create_test_video():
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="RenderWorker Test Runner")
|
||||
parser.add_argument("test_type", choices=[
|
||||
"unit", "integration", "all", "effects", "stress", "setup"
|
||||
], help="Type of tests to run")
|
||||
parser.add_argument(
|
||||
"test_type",
|
||||
choices=["unit", "integration", "all", "effects", "stress", "setup"],
|
||||
help="Type of tests to run",
|
||||
)
|
||||
|
||||
parser.add_argument("--effect", help="Specific effect to test (for effects command)")
|
||||
parser.add_argument("--coverage", action="store_true", help="Generate coverage report")
|
||||
parser.add_argument("--xml-report", action="store_true", help="Generate XML test report")
|
||||
parser.add_argument("--html-report", action="store_true", help="Generate HTML test report")
|
||||
parser.add_argument("--fail-under", type=int, default=70, help="Minimum coverage percentage")
|
||||
parser.add_argument("--no-deps-check", action="store_true", help="Skip dependency check")
|
||||
parser.add_argument(
|
||||
"--effect", help="Specific effect to test (for effects command)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--coverage", action="store_true", help="Generate coverage report"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--xml-report", action="store_true", help="Generate XML test report"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--html-report", action="store_true", help="Generate HTML test report"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--fail-under", type=int, default=70, help="Minimum coverage percentage"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-deps-check", action="store_true", help="Skip dependency check"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -264,4 +291,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user