Last active
March 15, 2021 09:07
-
-
Save afonasev/fa9cd4ca69e5abd9d8f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from pathlib import Path | |
import typer | |
def main(task_name: str): | |
task_dir = Path(task_name) | |
code_path = task_dir / 'code.py' | |
input_path = task_dir / 'input.txt' | |
output_path = task_dir / 'output.txt' | |
with open(input_path, 'rb') as input_file: | |
input_values = input_file.read() | |
result = ( | |
subprocess | |
.run( | |
['python', code_path], | |
input=input_values, | |
check=True, | |
capture_output=True, | |
) | |
.stdout | |
.decode() | |
.strip() | |
) | |
with open(output_path) as output_file: | |
expected_output = output_file.read().strip() | |
if expected_output != result: | |
typer.echo(f'[-] {expected_output} != {result}', color='red') | |
else: | |
typer.echo(f'[+] {expected_output} == {result}') | |
if __name__ == "__main__": | |
typer.run(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment