Skip to content

Commit

Permalink
Change in evaluator_tests, celery_task
Browse files Browse the repository at this point in the history
- Fix R and Python evaluation tests
- Add return to the celery task to store the task result in the database
  • Loading branch information
adityacp committed Apr 26, 2021
1 parent 745f02b commit e9b2116
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
39 changes: 0 additions & 39 deletions yaksh/evaluator_tests/test_python_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def assert_correct_output(self, expected_output, actual_output):

class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
def setUp(self):
self.tmp_file = os.path.join(tempfile.gettempdir(), "test.txt")
with open(self.tmp_file, '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 = [{"test_case_type": "standardtestcase",
Expand Down Expand Up @@ -927,41 +924,5 @@ def check_answer(user_answer):
result.get("error")[0]["message"]
)

def test_assignment_upload(self):
# Given
user_answer = "Assignment Upload"
hook_code = dedent("""\
def check_answer(user_answer):
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
with open("test.txt") as f:
data = f.read()
if data == '2':
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
)

test_case_data = [{"test_case_type": "hooktestcase",
"hook_code": hook_code, "weight": 1.0
}]
kwargs = {'metadata': {
'user_answer': user_answer,
'file_paths': self.file_paths,
'assign_files': [self.tmp_file],
'partial_grading': False,
'language': 'python'},
'test_case_data': test_case_data,
}

# When
grader = Grader(self.in_dir)
result = grader.evaluate(kwargs)

# Then
self.assertTrue(result.get('success'))


if __name__ == '__main__':
unittest.main()
5 changes: 2 additions & 3 deletions yaksh/evaluator_tests/test_r_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def setUp(self):
"test_case_type": "standardtestcase",
"weight": 0.0, "hidden": True
}]
self.timeout_msg = ("Code took more than {0} seconds to run. "
"You probably have an infinite loop in"
" your code.").format(SERVER_TIMEOUT)
self.timeout_msg = ("You probably have an infinite loop in"
" your code.")
self.file_paths = None

def tearDown(self):
Expand Down
6 changes: 3 additions & 3 deletions yaksh/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def send_files_to_code_server(data):
files = [file.get_filename() for file in uploads]
data = {"files": files, "action": action, "path": path}
response = requests.post(post_url, data=data)
message = response.content
if response.status_code == 200:
print("Successfully downloaded/deleted files")
else:
print("Download failed\n", response.content)
message = "Successfully downloaded/deleted files"
return message

0 comments on commit e9b2116

Please sign in to comment.