format with black
This commit is contained in:
parent
a8adcab0a1
commit
f247fb6019
22
testr/cli.py
22
testr/cli.py
@ -18,13 +18,16 @@ async def run_cli():
|
||||
test_data_group = parser.add_mutually_exclusive_group(required=True)
|
||||
|
||||
test_data_group.add_argument("--testdir", help="Directory for test cases")
|
||||
test_runner_group.add_argument("--exec", help="Executable to run test cases against")
|
||||
test_runner_group.add_argument(
|
||||
"--exec", help="Executable to run test cases against"
|
||||
)
|
||||
|
||||
parser.add_argument("--timelim", help="Time limit in seconds", type=float, default=5.0)
|
||||
parser.add_argument(
|
||||
"--timelim", help="Time limit in seconds", type=float, default=5.0
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
code_styles = {
|
||||
StatusCode.AC: Fore.GREEN,
|
||||
StatusCode.WA: Fore.RED,
|
||||
@ -39,10 +42,7 @@ async def run_cli():
|
||||
test_case_count = 0
|
||||
|
||||
async for test_case in test_runner.run_test_suite(
|
||||
test_suite,
|
||||
TestOptions(
|
||||
time_limit=args.timelim
|
||||
)
|
||||
test_suite, TestOptions(time_limit=args.timelim)
|
||||
):
|
||||
test_case_count += 1
|
||||
status_counts[test_case.code] += 1
|
||||
@ -52,12 +52,7 @@ async def run_cli():
|
||||
)
|
||||
|
||||
if test_case.code == StatusCode.IR:
|
||||
print(
|
||||
"---\n" +
|
||||
Style.BRIGHT +
|
||||
"Program stderr:"
|
||||
+ Style.RESET_ALL
|
||||
)
|
||||
print("---\n" + Style.BRIGHT + "Program stderr:" + Style.RESET_ALL)
|
||||
print("\n".join([f" {line}" for line in test_case.stderr.split("\n")]))
|
||||
|
||||
if test_case_count > 15:
|
||||
@ -76,5 +71,6 @@ async def run_cli():
|
||||
def main():
|
||||
asyncio.run(run_cli())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -1,5 +1,12 @@
|
||||
import asyncio
|
||||
from testr.runner import TestData, TestOptions, TestRunner, TestStatus, TestSuite, StatusCode
|
||||
from testr.runner import (
|
||||
TestData,
|
||||
TestOptions,
|
||||
TestRunner,
|
||||
TestStatus,
|
||||
TestSuite,
|
||||
StatusCode,
|
||||
)
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@ -43,7 +50,8 @@ class ExecutableRunner(TestRunner):
|
||||
|
||||
try:
|
||||
out_stream, err_stream = await asyncio.wait_for(
|
||||
proc.communicate(input=input_data.encode()), timeout=opts.time_limit)
|
||||
proc.communicate(input=input_data.encode()), timeout=opts.time_limit
|
||||
)
|
||||
except TimeoutError:
|
||||
proc.kill()
|
||||
return TestStatus(code=StatusCode.TLE, stderr="", stdout="", test_data=data)
|
||||
@ -52,7 +60,9 @@ class ExecutableRunner(TestRunner):
|
||||
stderr: str = err_stream.decode()
|
||||
|
||||
if proc.returncode != 0:
|
||||
return TestStatus(code=StatusCode.IR, stdout=stdout, stderr=stderr, test_data=data)
|
||||
return TestStatus(
|
||||
code=StatusCode.IR, stdout=stdout, stderr=stderr, test_data=data
|
||||
)
|
||||
|
||||
correct: bool = await data.validate_output(stdout)
|
||||
ret_code = StatusCode.AC if correct else StatusCode.WA
|
||||
@ -73,8 +83,9 @@ class DirectorySuite(TestSuite):
|
||||
outp_file = inp_file.with_suffix(".out")
|
||||
if not outp_file.is_file():
|
||||
raise ValueError(f"output file '{outp_file}' is not a valid file")
|
||||
self.test_cases.append(FileData(inp_file, outp_file, name=inp_file.with_suffix("").name))
|
||||
|
||||
self.test_cases.append(
|
||||
FileData(inp_file, outp_file, name=inp_file.with_suffix("").name)
|
||||
)
|
||||
|
||||
def __iter__(self):
|
||||
return self.test_cases.__iter__()
|
||||
|
@ -31,14 +31,16 @@ class TestInput(ABC):
|
||||
"""Input provider for single test case."""
|
||||
|
||||
@abstractmethod
|
||||
async def get_input(self) -> str: pass
|
||||
async def get_input(self) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class TestValidator(ABC):
|
||||
"""Output validator for single test case."""
|
||||
|
||||
@abstractmethod
|
||||
async def validate_output(self, output: str) -> bool: pass
|
||||
async def validate_output(self, output: str) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -71,7 +73,8 @@ class TestSuite(ABC):
|
||||
"""Loader for multiple test cases."""
|
||||
|
||||
@abstractmethod
|
||||
def __iter__(self) -> Iterator[TestData]: pass
|
||||
def __iter__(self) -> Iterator[TestData]:
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -92,8 +95,11 @@ class TestRunner(ABC):
|
||||
"""Runner for test cases."""
|
||||
|
||||
@abstractmethod
|
||||
async def run_test(self, data: TestData, opts: TestOptions) -> TestStatus: pass
|
||||
async def run_test(self, data: TestData, opts: TestOptions) -> TestStatus:
|
||||
pass
|
||||
|
||||
async def run_test_suite(self, data: TestSuite, opts: TestOptions) -> AsyncIterator[TestStatus]:
|
||||
async def run_test_suite(
|
||||
self, data: TestSuite, opts: TestOptions
|
||||
) -> AsyncIterator[TestStatus]:
|
||||
for test_case in data:
|
||||
yield await self.run_test(test_case, opts)
|
||||
|
Loading…
Reference in New Issue
Block a user