<commit_before>import sys
from StringIO import StringIO
import unittest

#pass student code and unit test file
#def autotester(self, student_code, test_code):
def autotester():

  student_code = '''
def from1to5():
    ret = []
    for i in range(6):
        ret.append(i)

    return ret
    '''
    
  unit_test = '''
import unittest
class Tester(unittest.TestCase):
    def test_1to5(self):
        stud_output = from1to5()
        self.assertListEqual(stud_output, [0, 1, 2, 3, 4, 5])

#unittest.main()
'''
  test_code = student_code+unit_test
  #exec student_code 
  print test_code
  test_output = StringIO()
  sys.stdout = test_output
  exec test_code in globals() #THIS HACK NEEDS SERIOUS CONSIDERATION
  sys.stdout = sys.__stdout__
  print test_output.getvalue()
  
  # test_code is just the expected output
  failed = "FAILED"
  if (failed in test_output.getvalue()):
    print ("FAIL")
  else:
    print ("PASS")


if __name__ == "__main__":
	autotester()
<commit_msg>-- Isolated testing in mock module, to prevent concurrency issues -- in the main namespace; -- Separated test code into class definition and runtime code. Still tight -- coupling, unless we choose to make a convention on test class name<commit_after>import sys
# from StringIO import StringIO
from types import ModuleType
import unittest


# pass student code and unit test file
# def autotester(self, student_code, test_code):
def autotester():

    student_code = '''
def from1to5():
    ret = []
    for i in range(6):
        ret.append(i)

    return ret
'''
    
    unit_test = '''
import unittest
class Tester(unittest.TestCase):
    def test_1to5(self):
        stud_output = from1to5()
        self.assertListEqual(stud_output, [0, 1, 2, 3, 4, 5])
'''

    #Assumes the testing class to be called tester. for now
    test_code = '''
{testModule}.Tester = Tester
{testModule}.testResult=unittest.main(module={testModule}, exit=False, verbosity=3)
'''
    mockModule = 'm'
    test_code = student_code + unit_test + test_code.format(testModule=mockModule)
    # exec student_code 
    # print test_code
    # test_output = StringIO()
    # sys.stdout = test_output
    envDict = {mockModule: ModuleType(mockModule)}
    try:
        exec test_code in envDict  #HACK SOLVED FOR NOW
    except:
        print "Something wrong happened while executing the test code"

    result = envDict['m'].testResult.result
    print [len(result.errors), len(result.failures), result.testsRun]
    # sys.stdout = sys.__stdout__
    # print test_output.getvalue()
  
    # test_code is just the expected output
    # ifailed = "FAILED"
    # if (failed in test_output.getvalue()):
    #     print ("FAIL")
    # else:
    #     print ("PASS")


if __name__ == "__main__":
	autotester()

{'fraction_non_alphanumeric': 0.10663764961915125, 'fraction_numerical': 0.009793253536452665, 'mean_word_length': 3.3777777777777778, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2067403', 'n_tokens_mistral': 899, 'n_tokens_neox': 874, 'n_words': 264}