Newer
Older
class IsNuisanceFailureTest(unittest.TestCase):
# Testing is_nuisance_failure
def test_not_uncaught_error(self):
result = {"result": "not_uncaught_error"}
self.assertFalse(is_nuisance_failure(result))
def test_no_traceback(self):
result = {"result": "uncaught_error"}
self.assertFalse(is_nuisance_failure(result))
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
result = {"result": "uncaught_error",
"traceback": "unknow traceback"}
self.assertFalse(is_nuisance_failure(result))
def test_traceback_has_badstatusline(self):
result = {"result": "uncaught_error",
"traceback": "BadStatusLine: \nfoo"}
self.assertTrue(is_nuisance_failure(result))
def test_traceback_address_already_in_use(self):
result = {"result": "uncaught_error",
"traceback": "\nbind: address already in use \nfoo"}
self.assertTrue(is_nuisance_failure(result))
def test_traceback_new_connection_error(self):
result = {"result": "uncaught_error",
"traceback":
"\nrequests.packages.urllib3.exceptions."
"NewConnectionError: \nfoo"}
self.assertTrue(is_nuisance_failure(result))
def test_traceback_remote_disconnected(self):
result = {"result": "uncaught_error",
"traceback":
"\nhttp.client.RemoteDisconnected: \nfoo"}
self.assertTrue(is_nuisance_failure(result))
def test_no_route_to_host(self):
result = {"result": "uncaught_error",
"traceback":
"\n[Errno 113] No route to host: \nfoo"}
self.assertTrue(is_nuisance_failure(result))
class CodeQuestionWithHumanTextFeedbackSpecialCase(
SingleCoursePageTestMixin, SubprocessRunpyContainerMixin, TestCase):
"""
https://github.com/inducer/relate/issues/269
https://github.com/inducer/relate/commit/2af0ad7aa053b735620b2cf0bae0b45822bfb87f
client = Client()
client.force_login(cls.student_participation.user)
cls.start_flow(client, cls.flow_id)
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
self.rf = RequestFactory()
def get_grade_feedback(self, answer_data, page_value,
human_feedback_percentage, grade_data):
page_id = "py_simple_list"
course_identifier = self.course.identifier
flow_session_id = self.get_default_flow_session_id(course_identifier)
flow_session = FlowSession.objects.get(id=flow_session_id)
page_ordinal = self.get_page_ordinal_via_page_id(
page_id, course_identifier, flow_session_id)
post_data = answer_data.copy()
post_data.update({"submit": ""})
request = self.rf.post(
self.get_page_url_by_ordinal(
page_ordinal, course_identifier, flow_session_id),
post_data)
request.user = self.student_participation.user
pctx = CoursePageContext(request, course_identifier)
fpctx = FlowPageContext(
pctx.repo, pctx.course, self.flow_id, page_ordinal,
self.student_participation, flow_session, request)
page_desc = fpctx.page_desc
page_desc.value = page_value
page_desc.human_feedback_percentage = human_feedback_percentage
page = PythonCodeQuestionWithHumanTextFeedback(None, None, page_desc)
page_context = fpctx.page_context
grade_data.setdefault("grade_percent", None)
grade_data.setdefault("released", True)
grade_data.setdefault("feedback_text", "")
page_data = fpctx.page_data
feedback = page.grade(
page_context=page_context,
answer_data=answer_data,
page_data=page_data,
grade_data=grade_data)
return feedback
def test_code_with_human_feedback(self):
answer_data = {"answer": "b = [a + 0] * 50"}
grade_data = {"grade_percent": 100}
page_value = 4
human_feedback_percentage = 60
feedback = self.get_grade_feedback(
answer_data, page_value, human_feedback_percentage, grade_data)
self.assertIn("The overall grade is 100%.", feedback.feedback)
self.assertIn(
"The autograder assigned 1.60/1.60 points.", feedback.feedback)
self.assertIn(
"The human grader assigned 2.40/2.40 points.", feedback.feedback)
def test_code_with_human_feedback_full_percentage(self):
answer_data = {"answer": "b = [a + 0] * 50"}
grade_data = {"grade_percent": 100}
page_value = 0
human_feedback_percentage = 100
from course.page.base import AnswerFeedback
with mock.patch(
"course.page.code.PythonCodeQuestion.grade") as mock_py_grade:
# In this way, code_feedback.correctness is None
mock_py_grade.return_value = AnswerFeedback(correctness=None)
feedback = self.get_grade_feedback(
answer_data, page_value, human_feedback_percentage, grade_data)
self.assertIn("The overall grade is 100%.", feedback.feedback)
self.assertIn(
"No information on correctness of answer.", feedback.feedback)
self.assertIn(
"The human grader assigned 0/0 points.", feedback.feedback)
def test_code_with_human_feedback_zero_percentage(self):
answer_data = {"answer": "b = [a + 0] * 50"}
grade_data = {}
page_value = 0
human_feedback_percentage = 0
feedback = self.get_grade_feedback(
answer_data, page_value, human_feedback_percentage, grade_data)
self.assertIn("The overall grade is 100%.", feedback.feedback)
self.assertIn(
"Your answer is correct.", feedback.feedback)
self.assertIn(
"The autograder assigned 0/0 points.", feedback.feedback)