-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.py
29 lines (25 loc) · 982 Bytes
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# helpers.py
# Daniel Kogan
# 03.02.2023
import unittest
import sys
import os
import subprocess
GREEN = '\033[92m'
RED = '\033[91m'
UNDERLINE = '\033[4m'
CLEAR_FORMAT = '\033[0m'
class Runner():
def run_file(testcase_class, file, expected_return_code=0):
cmd_str = f"python src/decaf_checker.py {file}"
process = subprocess.Popen(
cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
err_message = f"{RED}{file}{CLEAR_FORMAT} {UNDERLINE}exited with return code {process.returncode}, not {expected_return_code}{CLEAR_FORMAT}\n {GREEN}Output:{CLEAR_FORMAT} {stdout}\n\n {RED}Error:{CLEAR_FORMAT} {stderr}"
# print(f"{GREEN}{file}{CLEAR_FORMAT}: {stdout}")
testcase_class.assertEqual(
expected_return_code, process.returncode, err_message)
return stdout, stderr
def syntax_err_msg(line_col):
line, column = line_col
return f"Syntax error at line {line}, column {column}"