Last active
May 1, 2016 03:49
-
-
Save firesofmay/707cc51e6841de4821a266055ca7a960 to your computer and use it in GitHub Desktop.
Python script to execute coursera tests for ds-algo course
This file contains hidden or 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
# python3 | |
import subprocess | |
from glob import glob | |
import os,re, argparse | |
p = argparse.ArgumentParser(description="code_tests.py") | |
p.add_argument("-p", "--codepath", dest="script_path", type=str, help="Path to your script to execute") | |
p.add_argument("-t", "--testdir", dest="test_dir", type=str, help="Test directoy, default tests") | |
args = p.parse_args() | |
for file_name in os.listdir(args.test_dir): | |
if re.match(r"\d+\d$", file_name): | |
act_op_cmd = "python3 {} < {}/{}".format(args.script_path, args.test_dir, file_name) | |
act_op = subprocess.check_output(act_op_cmd, shell=True).strip() | |
ip_file = '{}/{}'.format(args.test_dir, file_name) | |
with open(ip_file, 'rb') as f: | |
ip = f.read().strip() | |
exp_op_file = '{}/{}.a'.format(args.test_dir, file_name) | |
with open(exp_op_file, 'rb') as f: | |
exp_op = f.read().strip() | |
if (act_op != exp_op): | |
print ("Input -> ", ip) | |
print ("Expected Input => ", exp_op) | |
print ("Actual Input => ", act_op) | |
print ("\n-------") |
This file contains hidden or 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
# For help | |
$ python3 --help | |
usage: code_test.py [-h] [-p SCRIPT_PATH] [-t TEST_DIR] | |
code_tests.py | |
optional arguments: | |
-h, --help show this help message and exit | |
-p SCRIPT_PATH, --codepath SCRIPT_PATH | |
Path to your script to execute | |
-t TEST_DIR, --testdir TEST_DIR | |
Test directoy, default tests | |
## How to execute, if no output means tests passed else it'll print failing tests | |
$ python3 code_test.py -p week01/hw/check_brackets_in_code/check_brackets.py -t week01/hw/check_brackets_in_code/tests/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment