From f1da39aded67efa3da145851f0e9f687a3e434e5 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 11:44:55 +0530 Subject: Change all evaluator structure and make sure eval test cases pass --- yaksh/evaluator_tests/test_java_evaluation.py | 371 +++++++++++++++++++------- 1 file changed, 274 insertions(+), 97 deletions(-) (limited to 'yaksh/evaluator_tests/test_java_evaluation.py') diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index f7ecd97..a66b6d6 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -3,7 +3,8 @@ import unittest import os import shutil import tempfile -from yaksh import code_evaluator as evaluator +from yaksh import code_evaluator +from yaksh.code_evaluator import CodeEvaluator from yaksh.java_code_evaluator import JavaCodeEvaluator from yaksh.java_stdio_evaluator import JavaStdioEvaluator from yaksh.settings import SERVER_TIMEOUT @@ -17,41 +18,70 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): tmp_in_dir_path = tempfile.mkdtemp() self.test_case_data = [ {"test_case": "java_files/main_square.java", + "test_case_type": "standardtestcase", "weight": 0.0 } ] self.in_dir = tmp_in_dir_path - evaluator.SERVER_TIMEOUT = 9 + code_evaluator.SERVER_TIMEOUT = 9 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" - " your code.").format(evaluator.SERVER_TIMEOUT) + " your code.").format(code_evaluator.SERVER_TIMEOUT) self.file_paths = None def tearDown(self): + code_evaluator.SERVER_TIMEOUT = 4 os.remove('/tmp/test.txt') shutil.rmtree(self.in_dir) def test_correct_answer(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a;\n\t}\n}" - get_class = JavaCodeEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + + # get_class = JavaCodeEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) def test_incorrect_answer(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a;\n\t}\n}" - get_class = JavaCodeEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + # get_class = JavaCodeEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertFalse(result.get('success')) lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) @@ -60,25 +90,52 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): def test_error(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a" - get_class = JavaCodeEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + # get_class = JavaCodeEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertFalse(result.get("success")) self.assertTrue("Error" in result.get("error")) def test_infinite_loop(self): user_answer = "class Test {\n\tint square_num(int a) {\n\t\twhile(0==0){\n\t\t}\n\t}\n}" - get_class = JavaCodeEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + # get_class = JavaCodeEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertFalse(result.get("success")) self.assertEqual(result.get("error"), self.timeout_msg) @@ -86,6 +143,7 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): self.file_paths = [("/tmp/test.txt", False)] self.test_case_data = [ {"test_case": "java_files/read_file.java", + "test_case_type": "standardtestcase", "weight": 0.0 } ] @@ -107,34 +165,48 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): br.close(); }}} """) - get_class = JavaCodeEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + # get_class = JavaCodeEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer\n") class JavaStdioEvaluationTestCases(unittest.TestCase): - def setUp(self): with open('/tmp/test.txt', 'wb') as f: f.write('2'.encode('ascii')) tmp_in_dir_path = tempfile.mkdtemp() self.in_dir = tmp_in_dir_path self.test_case_data = [{'expected_output': '11', - 'expected_input': '5\n6', - 'weight': 0.0 - }] - evaluator.SERVER_TIMEOUT = 4 + 'expected_input': '5\n6', + 'test_case_type': 'stdiobasedtestcase', + 'weight': 0.0 + }] + code_evaluator.SERVER_TIMEOUT = 4 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" - " your code.").format(evaluator.SERVER_TIMEOUT) + " your code.").format(code_evaluator.SERVER_TIMEOUT) + self.file_paths = None def tearDown(self): - evaluator.SERVER_TIMEOUT = 4 + code_evaluator.SERVER_TIMEOUT = 4 os.remove('/tmp/test.txt') shutil.rmtree(self.in_dir) @@ -148,19 +220,32 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = s.nextInt(); System.out.print(a+b); }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) def test_array_input(self): - self.test_case_data = [{'expected_output': '561', 'expected_input': '5\n6\n1', + 'test_case_type': 'stdiobasedtestcase', 'weight': 0.0 }] user_answer = dedent(""" @@ -173,17 +258,29 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): a[i] = s.nextInt(); System.out.print(a[i]);} }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) def test_incorrect_answer(self): - user_answer = dedent(""" import java.util.Scanner; class Test @@ -193,30 +290,55 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = s.nextInt(); System.out.print(a); }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Incorrect", result.get('error')) self.assertTrue(lines_of_error > 1) def test_error(self): - user_answer = dedent(""" class Test { System.out.print("a"); }""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in result.get("error")) @@ -229,19 +351,33 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): { System.out.print("a");} }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertFalse(result.get("success")) self.assertEqual(result.get("error"), self.timeout_msg) def test_only_stdout(self): self.test_case_data = [{'expected_output': '11', - 'expected_input': '', - 'weight': 0.0 + 'expected_input': '', + 'test_case_type': 'stdiobasedtestcase', + 'weight': 0.0 }] user_answer = dedent(""" class Test @@ -250,19 +386,33 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = 6; System.out.print(a+b); }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) def test_string_input(self): self.test_case_data = [{'expected_output': 'HelloWorld', - 'expected_input': 'Hello\nWorld', - 'weight': 0.0 + 'expected_input': 'Hello\nWorld', + 'test_case_type': 'stdiobasedtestcase', + 'weight': 0.0 }] user_answer = dedent(""" import java.util.Scanner; @@ -273,20 +423,34 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): String b = s.nextLine(); System.out.print(a+b); }}""") - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, - 'test_case_data': self.test_case_data - } - result = get_class.evaluate(**kwargs) + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, + 'test_case_data': self.test_case_data, + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) def test_file_based_stdout(self): self.file_paths = [("/tmp/test.txt", False)] self.test_case_data = [{'expected_output': '2', - 'expected_input': '', - 'weight': 0.0 + 'expected_input': '', + 'test_case_type': 'stdiobasedtestcase', + 'weight': 0.0 }] user_answer = dedent(""" import java.io.BufferedReader; @@ -306,13 +470,26 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): br.close(); }}} """) - get_class = JavaStdioEvaluator(self.in_dir) - kwargs = {'user_answer': user_answer, - 'partial_grading': True, + # get_class = JavaStdioEvaluator(self.in_dir) + # kwargs = {'user_answer': user_answer, + # 'partial_grading': True, + # 'test_case_data': self.test_case_data, + # 'file_paths': self.file_paths + # } + # result = get_class.evaluate(**kwargs) + kwargs = { + 'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'java' + }, 'test_case_data': self.test_case_data, - 'file_paths': self.file_paths - } - result = get_class.evaluate(**kwargs) + } + + evaluator = CodeEvaluator(self.in_dir) + result = evaluator.evaluate(kwargs) + self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer\n") -- cgit From 4a0f94084bc26559ef3e26470619e87314f9d70e Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 19:18:35 +0530 Subject: Remove commented code --- yaksh/evaluator_tests/test_java_evaluation.py | 86 --------------------------- 1 file changed, 86 deletions(-) (limited to 'yaksh/evaluator_tests/test_java_evaluation.py') diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index a66b6d6..246a3e5 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -36,14 +36,6 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a;\n\t}\n}" - - # get_class = JavaCodeEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -62,13 +54,6 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): def test_incorrect_answer(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a;\n\t}\n}" - # get_class = JavaCodeEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -90,14 +75,6 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): def test_error(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a" - # get_class = JavaCodeEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) - kwargs = { 'metadata': { 'user_answer': user_answer, @@ -116,13 +93,6 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): def test_infinite_loop(self): user_answer = "class Test {\n\tint square_num(int a) {\n\t\twhile(0==0){\n\t\t}\n\t}\n}" - # get_class = JavaCodeEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -165,13 +135,6 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): br.close(); }}} """) - # get_class = JavaCodeEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -220,12 +183,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = s.nextInt(); System.out.print(a+b); }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -258,12 +215,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): a[i] = s.nextInt(); System.out.print(a[i]);} }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -290,12 +241,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = s.nextInt(); System.out.print(a); }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -320,12 +265,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): { System.out.print("a"); }""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -351,12 +290,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): { System.out.print("a");} }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -386,12 +319,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): int b = 6; System.out.print(a+b); }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -423,12 +350,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): String b = s.nextLine(); System.out.print(a+b); }}""") - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, @@ -470,13 +391,6 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): br.close(); }}} """) - # get_class = JavaStdioEvaluator(self.in_dir) - # kwargs = {'user_answer': user_answer, - # 'partial_grading': True, - # 'test_case_data': self.test_case_data, - # 'file_paths': self.file_paths - # } - # result = get_class.evaluate(**kwargs) kwargs = { 'metadata': { 'user_answer': user_answer, -- cgit From bf5b4e7607bae0b81ceeb99e8bf5d750433e92e8 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 20 Dec 2016 12:42:44 +0530 Subject: Fix errors and rename resources - code_evaluator module and class renamed to grader - Test cases fixed - Comments removed - weight variable renamed to mark --- yaksh/evaluator_tests/test_java_evaluation.py | 83 ++++++++++++++------------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'yaksh/evaluator_tests/test_java_evaluation.py') diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 246a3e5..36eb6a5 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -3,13 +3,14 @@ import unittest import os import shutil import tempfile -from yaksh import code_evaluator -from yaksh.code_evaluator import CodeEvaluator -from yaksh.java_code_evaluator import JavaCodeEvaluator -from yaksh.java_stdio_evaluator import JavaStdioEvaluator -from yaksh.settings import SERVER_TIMEOUT from textwrap import dedent +# Local Import +from yaksh import grader as gd +from yaksh.grader import Grader +from yaksh.java_code_evaluator import JavaCodeEvaluator +from yaksh.java_stdio_evaluator import JavaStdIOEvaluator + class JavaAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): @@ -23,14 +24,15 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): } ] self.in_dir = tmp_in_dir_path - code_evaluator.SERVER_TIMEOUT = 9 + self.file_paths = None + gd.SERVER_TIMEOUT = 9 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" - " your code.").format(code_evaluator.SERVER_TIMEOUT) - self.file_paths = None + " your code.").format(gd.SERVER_TIMEOUT) + def tearDown(self): - code_evaluator.SERVER_TIMEOUT = 4 + gd.SERVER_TIMEOUT = 4 os.remove('/tmp/test.txt') shutil.rmtree(self.in_dir) @@ -46,8 +48,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) @@ -64,8 +66,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertFalse(result.get('success')) lines_of_error = len(result.get('error').splitlines()) @@ -85,8 +87,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertFalse(result.get("success")) self.assertTrue("Error" in result.get("error")) @@ -103,8 +105,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertFalse(result.get("success")) self.assertEqual(result.get("error"), self.timeout_msg) @@ -145,13 +147,13 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer\n") -class JavaStdioEvaluationTestCases(unittest.TestCase): +class JavaStdIOEvaluationTestCases(unittest.TestCase): def setUp(self): with open('/tmp/test.txt', 'wb') as f: f.write('2'.encode('ascii')) @@ -162,14 +164,14 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_type': 'stdiobasedtestcase', 'weight': 0.0 }] - code_evaluator.SERVER_TIMEOUT = 4 + self.file_paths = None + gd.SERVER_TIMEOUT = 9 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" - " your code.").format(code_evaluator.SERVER_TIMEOUT) - self.file_paths = None + " your code.").format(gd.SERVER_TIMEOUT) def tearDown(self): - code_evaluator.SERVER_TIMEOUT = 4 + gd.SERVER_TIMEOUT = 4 os.remove('/tmp/test.txt') shutil.rmtree(self.in_dir) @@ -193,8 +195,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) @@ -225,8 +227,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) @@ -251,8 +253,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) @@ -275,14 +277,13 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in result.get("error")) def test_infinite_loop(self): - user_answer = dedent(""" class Test {public static void main(String[] args){ @@ -300,8 +301,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertFalse(result.get("success")) self.assertEqual(result.get("error"), self.timeout_msg) @@ -329,8 +330,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) @@ -360,8 +361,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertEqual(result.get('error'), "Correct answer\n") self.assertTrue(result.get('success')) @@ -401,8 +402,8 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data, } - evaluator = CodeEvaluator(self.in_dir) - result = evaluator.evaluate(kwargs) + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer\n") -- cgit