def test_in_clean_environment( student_repo, root_dir, week_number, logfile_name, timeout=5, temp_file_path="temp_results.json", test_file_path="./test_shim.py", ): """Test a single student's work in a clean environment. This calls a subprocess that opens a fresh python environment, runs the tests and then saves the results to a temp file. Back in this process, we read that temp file, and then use its values to constuct a dictionary of results (or errors). The logging is just to see real time progress as this can run for a long time and hang the machine. """ results_dict = {} log_progress(student_repo, logfile_name) start_time = time.time() try: test_args = [ sys.executable, test_file_path, "week{}.tests".format(week_number), "{}/{}".format(root_dir, student_repo), ] # print("\ntest_args", test_args, # "\nstudent_repo", student_repo, # "\nroot_dir", root_dir, # "\nweek_number", week_number, # "\nlogfile_name", logfile_name, # "\ntemp_file_path", temp_file_path, # "\ntest_file_path", test_file_path, # "\ntimeout", timeout, # "\nLOCAL", LOCAL) RunCmd(test_args, timeout).Run() # this is unessarily complicated full_path = os.path.join(LOCAL, temp_file_path) temp_results = open(full_path, "r") contents = temp_results.read() results_dict = json.loads(contents) results_dict["bigerror"] = ":)" temp_results.close() log_progress(" good for w{}\n".format(week_number), logfile_name) except Exception as e: results_dict = { "bigerror": str(e).replace(",", "~"), "name": student_repo, } # the comma messes with the csv log_progress(" bad {} w{}\n".format(e, week_number), logfile_name) elapsed_time = time.time() - start_time results_dict["time"] = elapsed_time return results_dict
def test_in_clean_environment(student_repo, root_dir, week_number, logfile_name, temp_file_path='temp_results.json', test_file_path='./test_shim.py', timeout=5): """Test a single student's work in a clean environment. This calls a subprocess that opens a fresh python environment, runs the tests and then saves the results to a temp file. Back in this process, we read that temp file, and then use its values to constuct a dictionary of results (or errors). The logging is just to see real time progress as this can run for a long time and hang the machine. """ results_dict = {} log_progress(student_repo, logfile_name) try: timeout_cap = timeout args = ['python', test_file_path, "week{}.tests".format(week_number), "{}/{}".format(root_dir, student_repo) ] RunCmd(args, timeout_cap).Run() temp_results = open(os.path.join(LOCAL, temp_file_path), 'r') contents = temp_results.read() results_dict = json.loads(contents) results_dict["bigerror"] = ":)" temp_results.close() log_progress(" good for w{}\n".format(week_number), logfile_name) except Exception as e: results_dict = {"bigerror": str(e).replace(",", "~"), "name": student_repo} # the comma messes with the csv log_progress(" bad {} w{}\n".format(e, week_number), logfile_name) return results_dict
repos = ["code1161benFork_fully_working_secret_squirel"] times = [] repos = [ "alanw410", "bvn-architecture", "alanw410", "bvn-architecture", "alanw410", "bvn-architecture", "alanw410", "bvn-architecture", "alanw410", "bvn-architecture" ] # "bvn-architecture" results = [] for name in repos: start_time = time.time() try: timeout_cap = 25 args = [ 'python', './test_shim.py', "week{}.tests".format(week_number), "../code1161StudentRepos/{}".format(name) ] print args RunCmd(args, timeout_cap).Run() temp_results = open(os.path.join(LOCAL, 'temp_results.json'), 'r') results.append(temp_results.read()) temp_results.close() except Exception as e: print e elapsed_time = time.time() - start_time print "Time to test:", elapsed_time times.append({"name": name, "time": elapsed_time}) print results print times