mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
subprocess to unittest
This commit is contained in:
parent
1f4e08d20c
commit
ec4dc74de4
1 changed files with 23 additions and 13 deletions
|
@ -1,14 +1,13 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import unittest
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -356,24 +355,35 @@ def run_test(
|
||||||
|
|
||||||
|
|
||||||
def run_unit_tests(testdir, history_fname):
|
def run_unit_tests(testdir, history_fname):
|
||||||
suite = unittest.defaultTestLoader.discover(
|
command = [
|
||||||
|
"python",
|
||||||
|
"-m",
|
||||||
|
"unittest",
|
||||||
|
"discover",
|
||||||
|
"-s",
|
||||||
str(testdir),
|
str(testdir),
|
||||||
pattern="*_test.py",
|
"-t",
|
||||||
top_level_dir=str(testdir),
|
str(testdir),
|
||||||
|
"-p",
|
||||||
|
"*_test.py",
|
||||||
|
]
|
||||||
|
print(" ".join(command))
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
command,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
text=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
stream = io.StringIO()
|
res = result.stdout
|
||||||
runner = unittest.TextTestRunner(stream=stream)
|
res = cleanup_test_output(res)
|
||||||
result = runner.run(suite)
|
|
||||||
|
|
||||||
res = stream.getvalue()
|
|
||||||
print(res)
|
|
||||||
|
|
||||||
with history_fname.open("a") as fh:
|
with history_fname.open("a") as fh:
|
||||||
fh.write(f"```\n{res}\n```")
|
fh.write(f"```\n{res}\n```")
|
||||||
|
|
||||||
if not result.wasSuccessful():
|
if result.returncode != 0:
|
||||||
print(f"Tests in {testdir} failed")
|
print(f"Tests failed: {testdir}")
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue