From 99f0c944fafec51b9327fe5dea01096842788e03 Mon Sep 17 00:00:00 2001
From: maheshgudi
Date: Wed, 4 Jul 2018 16:34:56 +0530
Subject: Raise appropriate exceptions for C and Java language to the Grader

- Raise AssertionError,CompilationError and TestCaseError for assertion, user answer compilation
  and testcase compilation errors respectively.
- Add test case for C/C++ and Java
---
 yaksh/evaluator_tests/test_c_cpp_evaluation.py | 29 +++++++++++++++-----------
 yaksh/evaluator_tests/test_java_evaluation.py  | 23 ++++++++++----------
 2 files changed, 29 insertions(+), 23 deletions(-)

(limited to 'yaksh/evaluator_tests')

diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
index 5b49671..17f7c82 100644
--- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py
+++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
@@ -100,12 +100,12 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
-
+        errors = result.get('error')
         # Then
-        lines_of_error = len(result.get('error')[0].splitlines())
         self.assertFalse(result.get('success'))
-        self.assert_correct_output("Incorrect:", result.get('error'))
-        self.assertTrue(lines_of_error > 1)
+        for error in errors:
+            self.assertEqual(error['exception'], 'AssertionError')
+
 
     def test_compilation_error(self):
         # Given
@@ -122,10 +122,12 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
         self.assertFalse(result.get("success"))
-        self.assert_correct_output("Compilation Error", result.get("error"))
+        for error in errors:
+            self.assertEqual(error['exception'], 'CompilationError')
 
     def test_infinite_loop(self):
         # Given
@@ -272,14 +274,12 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get("error")
 
         # Then
-        err = result.get('error')[0]
-        lines_of_error = len(err.splitlines())
         self.assertFalse(result.get('success'))
-        self.assertTrue(lines_of_error > 1)
-        self.assertIn("Test case Error", err)
-
+        for error in errors:
+            self.assertEqual(error['exception'], 'TestCaseError')
 
 class CppStdIOEvaluationTestCases(EvaluatorBaseTest):
     def setUp(self):
@@ -432,10 +432,13 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
         self.assertFalse(result.get("success"))
-        self.assert_correct_output("Compilation Error", result.get("error"))
+        for error in errors:
+            self.assertEqual(error['exception'], 'CompilationError')
+
 
     def test_infinite_loop(self):
         # Given
@@ -636,10 +639,12 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
         self.assertFalse(result.get("success"))
-        self.assert_correct_output("Compilation Error", result.get("error"))
+        for error in errors:
+            self.assertEqual(error['exception'], 'CompilationError')
 
     def test_cpp_infinite_loop(self):
         # Given
diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py
index ab86dec..eb09f2f 100644
--- a/yaksh/evaluator_tests/test_java_evaluation.py
+++ b/yaksh/evaluator_tests/test_java_evaluation.py
@@ -113,13 +113,12 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
         self.assertFalse(result.get('success'))
-        lines_of_error = len(result.get('error')[0].splitlines())
-        self.assertFalse(result.get('success'))
-        self.assert_correct_output("Incorrect", result.get('error'))
-        self.assertTrue(lines_of_error > 1)
+        for error in errors:
+            self.assertEqual(error.get('exception'), 'AssertionError')
 
     def test_error(self):
         # Given
@@ -136,10 +135,11 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
-
+        errors = result.get('error')
         # Then
         self.assertFalse(result.get("success"))
-        self.assert_correct_output("Error", result.get("error"))
+        for error in errors:
+            self.assertEqual(error.get('exception'), 'CompilationError')
 
     def test_infinite_loop(self):
         # Given
@@ -290,13 +290,12 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
-        err = result.get('error')[0]
-        lines_of_error = len(err.splitlines())
         self.assertFalse(result.get('success'))
-        self.assertTrue(lines_of_error > 1)
-        self.assertIn("Test case Error", err)
+        for error in errors:
+            self.assertEqual(error.get('exception'), 'TestCaseError')
 
 
 class JavaStdIOEvaluationTestCases(EvaluatorBaseTest):
@@ -432,10 +431,12 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest):
         # When
         grader = Grader(self.in_dir)
         result = grader.evaluate(kwargs)
+        errors = result.get('error')
 
         # Then
         self.assertFalse(result.get("success"))
-        self.assertTrue("Compilation Error" in '\n'.join(result.get("error")))
+        for error in errors:
+            self.assertEqual(error.get('exception'), 'CompilationError')
 
     def test_infinite_loop(self):
         # Given
-- 
cgit