summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/grader.py4
-rw-r--r--yaksh/tests/test_code_server.py34
2 files changed, 37 insertions, 1 deletions
diff --git a/yaksh/grader.py b/yaksh/grader.py
index 38cce8d..c9dc8a2 100644
--- a/yaksh/grader.py
+++ b/yaksh/grader.py
@@ -131,7 +131,9 @@ class Grader(object):
# Add a new signal handler for the execution of this code.
prev_handler = create_signal_handler()
success = False
- test_case_success_status = [False] * len(test_case_instances)
+ test_case_success_status = [False]
+ if len(test_case_instances) != 0:
+ test_case_success_status = [False] * len(test_case_instances)
error = []
weight = 0.0
diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py
index 1309624..e2781df 100644
--- a/yaksh/tests/test_code_server.py
+++ b/yaksh/tests/test_code_server.py
@@ -106,6 +106,40 @@ class TestCodeServer(unittest.TestCase):
self.assertFalse(data['success'])
self.assertTrue('AssertionError' in data['error'][0]['exception'])
+ def test_question_with_no_testcases(self):
+ # Given
+ testdata = {
+ 'metadata': {
+ 'user_answer': 'def f(): return 1',
+ 'language': 'python',
+ 'partial_grading': False
+ },
+ 'test_case_data': []
+ }
+
+ # When
+ submit(self.url, '0', json.dumps(testdata), '')
+ result = get_result(self.url, '0', block=True)
+
+ # Then
+ data = json.loads(result.get('result'))
+ self.assertFalse(data['success'])
+
+ # With correct answer and test case
+ testdata["metadata"]["user_answer"] = 'def f(): return 2'
+ testdata["test_case_data"] = [{'test_case': 'assert f() == 2',
+ 'test_case_type': 'standardtestcase',
+ 'weight': 0.0
+ }
+ ]
+ # When
+ submit(self.url, '0', json.dumps(testdata), '')
+ result = get_result(self.url, '0', block=True)
+
+ # Then
+ data = json.loads(result.get('result'))
+ self.assertTrue(data['success'])
+
def test_multiple_simultaneous_hits(self):
# Given
results = Queue()