Skip to content

Instantly share code, notes, and snippets.

@afonasev
Last active March 15, 2021 09:07
Show Gist options
  • Save afonasev/fa9cd4ca69e5abd9d8f9 to your computer and use it in GitHub Desktop.
Save afonasev/fa9cd4ca69e5abd9d8f9 to your computer and use it in GitHub Desktop.
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