diff options
author | ankitjavalkar | 2015-04-30 11:21:49 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-04-30 11:29:35 +0530 |
commit | d8847656ba79e51c96c6e3650374aaf616c375dc (patch) | |
tree | 9e4ca3c29bc082cdd7b6775208544c2da9cee374 /testapp/test_server.py | |
parent | 18df6d88a2e1a9dfe7d05ca97b2d69ff0569e088 (diff) | |
download | online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.gz online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.bz2 online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.zip |
Code Review: Code Refactoring
Diffstat (limited to 'testapp/test_server.py')
-rw-r--r-- | testapp/test_server.py | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/testapp/test_server.py b/testapp/test_server.py index 39995e1..9319d5b 100644 --- a/testapp/test_server.py +++ b/testapp/test_server.py @@ -1,12 +1,15 @@ import unittest import os -from exam import evaluate_c_code, evaluate_cpp_code, evaluate_java_code, evaluate_python_code, evaluate_scilab_code, evaluate_bash_code -from exam.language_registry import registry +# from exam import evaluate_c_code, evaluate_cpp_code, evaluate_java_code, evaluate_python_code, evaluate_scilab_code, evaluate_bash_code +from exam import c_cpp_code_evaluator, bash_code_evaluator, python_code_evaluator, scilab_code_evaluator, java_code_evaluator +from exam.language_registry import set_registry, get_registry from exam.settings import SERVER_TIMEOUT + class RegistryTestCase(unittest.TestCase): def setUp(self): - self.registry_object = registry + set_registry() + self.registry_object = get_registry() def test_set_register(self): self.registry_object.register("demo_language", "demo_object") @@ -17,6 +20,9 @@ class RegistryTestCase(unittest.TestCase): cls = self.registry_object.get_class("demo_language") self.assertEquals(cls, "demo_object") + def tearDown(self): + self.registry_object = None + ############################################################################### class PythonEvaluationTestCases(unittest.TestCase): @@ -33,8 +39,8 @@ class PythonEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "def add(a, b):\n\treturn a + b""" - get_class = evaluate_python_code.EvaluatePythonCode(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) - result = get_class.run_code() + get_class = python_code_evaluator.PythonCodeEvaluator(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") @@ -46,8 +52,8 @@ class PythonEvaluationTestCases(unittest.TestCase): "pos_args": ["3", "2"], "kw_args": {} }] - get_class = evaluate_python_code.EvaluatePythonCode(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) - result = get_class.run_code() + get_class = python_code_evaluator.PythonCodeEvaluator(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertEqual(result.get("error"), "AssertionError in: assert add(3, 2) == 5") @@ -59,8 +65,8 @@ class PythonEvaluationTestCases(unittest.TestCase): "pos_args": ["3", "2"], "kw_args": {} }] - get_class = evaluate_python_code.EvaluatePythonCode(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) - result = get_class.run_code() + get_class = python_code_evaluator.PythonCodeEvaluator(self.test_case_data, self.language, user_answer, ref_code_path=None, in_dir=None) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) @@ -78,24 +84,24 @@ class CEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "int add(int a, int b)\n{return a+b;}" - get_class = evaluate_c_code.EvaluateCCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") def test_compilation_error(self): user_answer = "int add(int a, int b)\n{return a+b}" - get_class = evaluate_c_code.EvaluateCCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in result.get("error")) def test_infinite_loop(self): user_answer = "int add(int a, int b)\n{while(1>0){}}" - get_class = evaluate_c_code.EvaluateCCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) @@ -114,24 +120,24 @@ class CppEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "int add(int a, int b)\n{return a+b;}" - get_class = evaluate_cpp_code.EvaluateCppCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") def test_compilation_error(self): user_answer = "int add(int a, int b)\n{return a+b}" - get_class = evaluate_cpp_code.EvaluateCppCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertTrue("Compilation Error" in result.get("error")) def test_infinite_loop(self): user_answer = "int add(int a, int b)\n{while(1>0){}}" - get_class = evaluate_cpp_code.EvaluateCppCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = c_cpp_code_evaluator.CCppCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) @@ -149,25 +155,25 @@ class BashEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "#!/bin/bash\n[[ $# -eq 2 ]] && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))" - get_class = evaluate_bash_code.EvaluateBashCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = bash_code_evaluator.BashCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") def test_error(self): user_answer = "#!/bin/bash\n[[ $# -eq 2 ]] && echo $(( $1 - $2 )) && exit $(( $1 - $2 ))" - get_class = evaluate_bash_code.EvaluateBashCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() - + get_class = bash_code_evaluator.BashCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() + self.assertFalse(result.get("success")) self.assertTrue("Error" in result.get("error")) def test_infinite_loop(self): user_answer = "#!/bin/bash\nwhile [ 1 ] ; do echo "" > /dev/null ; done" - get_class = evaluate_bash_code.EvaluateBashCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() - + get_class = bash_code_evaluator.BashCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() + self.assertFalse(result.get("success")) self.assertEquals(result.get("error"), self.timeout_msg) @@ -198,7 +204,7 @@ class JavaEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get("success")) self.assertTrue("Error" in result.get("error")) - def test_infinite_loop(self): + 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 = evaluate_java_code.EvaluateJavaCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) result = get_class.run_code() @@ -217,24 +223,24 @@ class ScilabEvaluationTestCases(unittest.TestCase): def test_correct_answer(self): user_answer = "funcprot(0)\nfunction[c]=add(a,b)\n\tc=a+b;\nendfunction" - get_class = evaluate_scilab_code.EvaluateScilabCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = scilab_code_evaluator.ScilabCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") def test_correct_answer_2(self): user_answer = "funcprot(0)\nfunction[c]=add(a,b)\n\tc=a-b;\nendfunction" - get_class = evaluate_scilab_code.EvaluateScilabCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = scilab_code_evaluator.ScilabCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertTrue(result.get("success")) self.assertEqual(result.get("error"), "Correct answer") def test_error(self): user_answer = "funcprot(0)\nfunction[c]=add(a,b)\n\t c=a+b;\ndis(\tendfunction" - get_class = evaluate_java_code.EvaluateJavaCode(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) - result = get_class.run_code() + get_class = scilab_code_evaluator.ScilabCodeEvaluator(self.test_case_data, self.language, user_answer, self.ref_code_path, self.in_dir) + result = get_class.code_evaluator() self.assertFalse(result.get("success")) self.assertTrue("Error" in result.get("error")) |