diff options
author | maheshgudi | 2016-09-16 19:30:33 +0530 |
---|---|---|
committer | maheshgudi | 2016-09-16 19:30:45 +0530 |
commit | e6bff444d1217b9f657d5696f2cdaae575124ece (patch) | |
tree | 72039f3bcf2ae3ca891a5c4d3fd6058ebf1b23c0 /yaksh/evaluator_tests | |
parent | e615c7b5cc922db1b92891b327e25258d778bd07 (diff) | |
download | online_test-e6bff444d1217b9f657d5696f2cdaae575124ece.tar.gz online_test-e6bff444d1217b9f657d5696f2cdaae575124ece.tar.bz2 online_test-e6bff444d1217b9f657d5696f2cdaae575124ece.zip |
test cases for python assertion bug fixes
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 3c07907..2fd63ad 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -52,7 +52,7 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get('success')) self.assertEqual(result.get('error'), self.timeout_msg) - + def test_syntax_error(self): user_answer = dedent(""" def add(a, b); return a + b @@ -207,6 +207,57 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): self.assertEqual(result.get('error'), "Correct answer") self.assertTrue(result.get('success')) + def test_single_testcase_error(self): + user_answer = "def palindrome(a):\n\treturn a == a[::-1]" + test_case_data = [{"test_case": 's="abbb"\nasert palindrome(s)==False'} + ] + syntax_error_msg = ["Traceback", + "call", + "File", + "line", + "<string>", + "SyntaxError", + "invalid syntax" + ] + get_class = PythonAssertionEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': test_case_data, + 'file_paths': self.file_paths + } + result = get_class.evaluate(**kwargs) + err = result.get("error").splitlines() + self.assertFalse(result.get("success")) + self.assertEqual(5, len(err)) + for msg in syntax_error_msg: + self.assertIn(msg, result.get("error")) + + + def test_multiple_testcase_error(self): + user_answer = "def palindrome(a):\n\treturn a == a[::-1]" + test_case_data = [{"test_case": 'assert(palindrome("abba")==True)'}, + {"test_case": 's="abbb"\nassert palindrome(S)==False'} + ] + name_error_msg = ["Traceback", + "call", + "File", + "line", + "<string>", + "NameError", + "name 'S' is not defined" + ] + get_class = PythonAssertionEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': test_case_data, + 'file_paths': self.file_paths + } + result = get_class.evaluate(**kwargs) + err = result.get("error").splitlines() + self.assertFalse(result.get("success")) + self.assertEqual(3, len(err)) + for msg in name_error_msg: + self.assertIn(msg, result.get("error")) + + class PythonStdoutEvaluationTestCases(unittest.TestCase): def setUp(self): self.test_case_data = [{"expected_input": None, @@ -246,7 +297,11 @@ class PythonStdoutEvaluationTestCases(unittest.TestCase): kwargs = {'user_answer': user_answer, 'test_case_data': self.test_case_data } - + result = get_class.evaluate(**kwargs) + self.assertEqual(result.get('error'), self.timeout_msg) + self.assertFalse(result.get('success')) + + class PythonStdIOEvaluator(unittest.TestCase): def setUp(self): |