Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pythonwhat/check_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def call(args,
from pythonwhat.tasks import ReprFail, UndefinedValue
from pythonwhat import utils
def has_expr(incorrect_msg="FMT:Unexpected expression {test}: expected `{sol_eval}`, got `{stu_eval}` with values{extra_env}.",
error_msg="Running an expression in the student process caused an issue",
error_msg="Running an expression in the student process caused an issue.",
undefined_msg="FMT:Have you defined `{name}` without errors?",
extra_env=None,
context_vals=None,
Expand Down
7 changes: 5 additions & 2 deletions pythonwhat/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def getRepresentation(name, process):
try:
stream = getStreamPickle(name, process)
if not errored(stream): return pickle.loads(stream)
except PicklingError:
except:
pass

# if it failed, try to dill
Expand All @@ -268,7 +268,10 @@ def getRepresentation(name, process):
if not errored(stream): return dill.loads(stream)
return ReprFail("dilling inside process failed for %s - write manual converter" % obj_class)
except PicklingError:
return ReprFail("undilling of bytestream failed - write manual converter")
return ReprFail("undilling of bytestream failed with PicklingError - write manual converter")
except Exception as e:
return ReprFail("undilling of bytestream failed for class %s - write manual converter."
"Error: %s - %s" % (obj_class, type(e), e))

def errored(el):
return el is None or (isinstance(el, list) and 'backend-error' in str(el))
Expand Down
2 changes: 1 addition & 1 deletion pythonwhat/test_funcs/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def build_test(stud, sol, state, do_eval, eq_fun, feedback_msg, add_more, highli
if do_eval:

eval_solution, str_solution = getResultInProcess(tree = sol, process = state.solution_process)
if str_solution is None:
if isinstance(str_solution, Exception):
raise ValueError("Running an argument in the solution environment raised an error")
if isinstance(eval_solution, ReprFail):
raise ValueError("Couldn't figure out the argument: " + eval_solution.info)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,49 @@ def test_nohighlight_too_few_calls(self):
self.assertEqual(sct_payload.get('line_start'), None)


class TestFunctionComplexArgs(unittest.TestCase):
def setUp(self):
self.data = {
"DC_SOLUTION": """
def sum2(arr): return sum(arr)

def apply(f, arr): return f(arr)

apply(sum2, [1,2,3])
""",
"DC_SCT": """
test_function('apply')
"""
}
self.data["DC_CODE"] = self.data["DC_SOLUTION"]

def test_function_with_funcarg_fails(self):
# because functions are shipped across student and submission processes
# they are always "unequal".
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])

def test_pass_with_no_eval(self):
self.data["DC_SCT"] = """test_function_v2('apply', params=['f', 'arr'], do_eval=[False, True])"""
sct_payload = helper.run(self.data)
self.assertTrue(sct_payload['correct'])

def test_fail_undillable_args(self):
self.data = {
"DC_PEC": """
import pickle; from io import BytesIO

file = BytesIO(pickle.dumps('abc'))
""",
"DC_SOLUTION": "d = pickle.load(file); print(d)",
"DC_CODE": "print(file)",
"DC_SCT": """test_function("print", index=1)"""
}
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])




if __name__ == "__main__":
unittest.main()