diff options
author | mahesh | 2017-03-21 16:38:31 +0530 |
---|---|---|
committer | mahesh | 2017-03-21 16:38:31 +0530 |
commit | 72061d5f4ceae8e848a1fb12ab245be93db75435 (patch) | |
tree | 0cee9facaa3cd8d7701eff36de044ceac960acfe /yaksh/evaluator_tests | |
parent | 977399542df00349cc87917191af343226c44596 (diff) | |
parent | 49a4cbac480f8a9e3fafcd50e6ce2fa41a5d8699 (diff) | |
download | online_test-72061d5f4ceae8e848a1fb12ab245be93db75435.tar.gz online_test-72061d5f4ceae8e848a1fb12ab245be93db75435.tar.bz2 online_test-72061d5f4ceae8e848a1fb12ab245be93db75435.zip |
rebase changes for simple question types
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 56 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_simple_question_types.py | 30 |
2 files changed, 70 insertions, 16 deletions
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 51f9bea..a751c40 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -19,7 +19,8 @@ class EvaluatorBaseTest(unittest.TestCase): class PythonAssertionEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.tmp_file = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.tmp_file, 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() self.in_dir = tmp_in_dir_path @@ -33,7 +34,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest): self.file_paths = None def tearDown(self): - os.remove('/tmp/test.txt') + os.remove(self.tmp_file) shutil.rmtree(self.in_dir) def test_correct_answer(self): @@ -343,7 +344,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest): def test_file_based_assert(self): # Given self.test_case_data = [{"test_case_type": "standardtestcase", "test_case": "assert(ans()=='2')", "weight": 0.0}] - self.file_paths = [('/tmp/test.txt', False)] + self.file_paths = [(self.tmp_file, False)] user_answer = dedent(""" def ans(): with open("test.txt") as f: @@ -479,12 +480,17 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest): class PythonStdIOEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.tmp_file = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.tmp_file, 'wb') as f: f.write('2'.encode('ascii')) self.file_paths = None tmp_in_dir_path = tempfile.mkdtemp() self.in_dir = tmp_in_dir_path + def teardown(self): + os.remove(self.tmp_file) + shutil.rmtree(self.in_dir) + def test_correct_answer_integer(self): # Given self.test_case_data = [{"test_case_type": "stdiobasedtestcase", @@ -618,7 +624,7 @@ class PythonStdIOEvaluationTestCases(EvaluatorBaseTest): "expected_output": "2", "weight": 0.0 }] - self.file_paths = [('/tmp/test.txt', False)] + self.file_paths = [(self.tmp_file, False)] user_answer = dedent(""" with open("test.txt") as f: @@ -702,7 +708,8 @@ class PythonStdIOEvaluationTestCases(EvaluatorBaseTest): class PythonHookEvaluationTestCases(EvaluatorBaseTest): def setUp(self): - with open('/tmp/test.txt', 'wb') as f: + self.tmp_file = os.path.join(tempfile.gettempdir(), "test.txt") + with open(self.tmp_file, 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() self.in_dir = tmp_in_dir_path @@ -712,7 +719,7 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest): self.file_paths = None def tearDown(self): - os.remove('/tmp/test.txt') + os.remove(self.tmp_file) shutil.rmtree(self.in_dir) def test_correct_answer(self): @@ -910,6 +917,41 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest): self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) + def test_assignment_upload(self): + # Given + user_answer = "Assignment Upload" + hook_code = dedent("""\ + def check_answer(user_answer): + success = False + err = "Incorrect Answer" + mark_fraction = 0.0 + with open("test.txt") as f: + data = f.read() + if data == '2': + success, err, mark_fraction = True, "", 1.0 + return success, err, mark_fraction + """ + ) + test_case_data = [{"test_case_type": "hooktestcase", + "hook_code": hook_code,"weight": 1.0 + }] + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'assign_files': [(self.tmp_file, False)], + 'partial_grading': False, + 'language': 'python' + }, + 'test_case_data': test_case_data, + } + + # When + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) + + # Then + self.assertTrue(result.get('success')) if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py index 1d0a1e2..fb1c220 100644 --- a/yaksh/evaluator_tests/test_simple_question_types.py +++ b/yaksh/evaluator_tests/test_simple_question_types.py @@ -15,10 +15,6 @@ def setUpModule(): Profile.objects.create(user=user, roll_number=1, institute='IIT', department='Aerospace', position='Student') - # create 2 questions - for i in range(101, 103): - Question.objects.create(summary='Q%d' % (i), points=1, - type='code', user=user) # create a course course = Course.objects.create(name="Python Course 100", @@ -48,7 +44,6 @@ def setUpModule(): def tearDownModule(): User.objects.get(username="demo_user_100").delete() - class IntegerQuestionTestCases(unittest.TestCase): @classmethod def setUpClass(self): @@ -61,7 +56,8 @@ class IntegerQuestionTestCases(unittest.TestCase): self.user = User.objects.get(username='demo_user_100') #Creating Question - self.question1 = Question.objects.get(summary='Q101') + self.question1 = Question.objects.create(summary='int1', points=1, + type='code', user=self.user) self.question1.language = 'python' self.question1.type = "integer" self.question1.test_case_type = 'integertestcase' @@ -80,6 +76,10 @@ class IntegerQuestionTestCases(unittest.TestCase): ) self.integer_based_testcase.save() + @classmethod + def tearDownClass(self): + self.question1.delete() + def test_integer_correct_answer(self): # Given integer_answer = 25 @@ -127,14 +127,16 @@ class StringQuestionTestCases(unittest.TestCase): #Creating User self.user = User.objects.get(username='demo_user_100') #Creating Question - self.question1 = Question.objects.get(summary='Q101') + self.question1 = Question.objects.create(summary='str1', points=1, + type='code', user=self.user) self.question1.language = 'python' self.question1.type = "string" self.question1.test_case_type = 'stringtestcase' self.question1.description = 'Write Hello, EARTH!' self.question1.save() - self.question2 = Question.objects.get(summary='Q102') + self.question2 = Question.objects.create(summary='str2', points=1, + type='code', user=self.user) self.question2.language = 'python' self.question2.type = "string" self.question2.test_case_type = 'stringtestcase' @@ -162,6 +164,11 @@ class StringQuestionTestCases(unittest.TestCase): ) self.exact_string_testcase.save() + @classmethod + def tearDownClass(self): + self.question1.delete() + self.question2.delete() + def test_case_insensitive_string_correct_answer(self): # Given string_answer = "hello, earth!" @@ -236,7 +243,8 @@ class FloatQuestionTestCases(unittest.TestCase): #Creating User self.user = User.objects.get(username='demo_user_100') #Creating Question - self.question1 = Question.objects.get(summary='Q101') + self.question1 = Question.objects.create(summary='flt1', points=1, + type='code', user=self.user) self.question1.language = 'python' self.question1.type = "float" self.question1.test_case_type = 'floattestcase' @@ -255,6 +263,10 @@ class FloatQuestionTestCases(unittest.TestCase): ) self.float_based_testcase.save() + @classmethod + def tearDownClass(self): + self.question1.delete() + def test_float_correct_answer(self): # Given float_answer = 99.9 |