def test_dictionary(name, keys=None, undefined_msg=None, not_dictionary_msg=None, key_missing_msg=None, incorrect_value_msg=None, state=None): """Test the contents of a dictionary. """ rep = Reporter.active_reporter rep.set_tag("fun", "test_dictionary") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state, typestr="dictionary") is_instance(dict, not_dictionary_msg or MSG_NOT_INSTANCE, state=child) # test instance # set keys or check if manual keys are valid if not keys: keys = getKeysInProcess(name, state.solution_process) for key in keys: # check if key in dictionary has_equal_key(key, incorrect_value_msg or MSG_INCORRECT_VAL, key_missing_msg or MSG_KEY_MISSING, state=child)
def test_data_frame(name, columns=None, undefined_msg=None, not_data_frame_msg=None, undefined_cols_msg=None, incorrect_msg=None, state=None): """Test a pandas dataframe. """ rep = Reporter.active_reporter rep.set_tag("fun", "test_data_frame") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state, typestr="pandas DataFrame") is_instance(pd.DataFrame, not_data_frame_msg or MSG_NOT_INSTANCE, state=child) # test instance sol_cols = getColumnsInProcess(name, child.solution_process) if sol_cols is None: raise ValueError("Something went wrong in figuring out the columns for %s in the solution process" % name) # set columns or check if manual columns are valid if columns is None: columns = sol_cols for col in columns: # check if column available has_equal_key(col, incorrect_msg or MSG_INCORRECT_VAL, undefined_cols_msg or MSG_KEY_MISSING, state=child)
def check_df(name, undefined_msg=MSG_UNDEFINED, not_instance_msg=MSG_NOT_INSTANCE, state=None): # test defined child = check_object(name, undefined_msg, state=state, typestr="pandas DataFrame") is_instance(pd.DataFrame, not_instance_msg, state=child) # test instance return child
def check_dict(name, undefined_msg=MSG_UNDEFINED, not_instance_msg=MSG_NOT_INSTANCE, expand_msg="", state=None): # test defined child = check_object(name, undefined_msg, state=state, typestr="dictionary") is_instance(dict, not_instance_msg, state=child) # test instance return child
def test_object(name, eq_condition="equal", eq_fun=None, do_eval=True, undefined_msg=None, incorrect_msg=None, state=None): """Test object. The value of an object in the ending environment is compared in the student's environment and the solution environment. Args: name (str): the name of the object which value has to be checked. eq_condition (str): how objects are compared. Currently, only "equal" is supported, meaning that the object in student and solution process should have exactly the same value. do_eval (bool): if False, the object will only be checked for existence. Defaults to True. undefined_msg (str): feedback message when the object is not defined incorrect_msg (str): feedback message if the value of the object in the solution environment doesn't match the one in the student environment. :Example: Student code:: a = 1 b = 5 Solution code:: a = 1 b = 2 SCT:: test_object("a") # pass test_object("b") # fail Note that the student code below would fail both tests:: a = 1 b = 2 a = 3 # incorrect final value of a """ rep = Reporter.active_reporter rep.set_tag("fun", "test_object") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state) if do_eval: has_equal_value(incorrect_msg or MSG_INCORRECT, state=child)
def test_object(name, eq_condition="equal", eq_fun=None, do_eval=True, undefined_msg=None, incorrect_msg=None, state=None): """Test object. The value of an object in the ending environment is compared in the student's environment and the solution environment. Args: name (str): the name of the object which value has to be checked. eq_condition (str): how objects are compared. Currently, only "equal" is supported, meaning that the object in student and solution process should have exactly the same value. do_eval (bool): if False, the object will only be checked for existence. Defaults to True. undefined_msg (str): feedback message when the object is not defined incorrect_msg (str): feedback message if the value of the object in the solution environment doesn't match the one in the student environment. :Example: Student code:: a = 1 b = 5 Solution code:: a = 1 b = 2 SCT:: test_object("a") # pass test_object("b") # fail Note that the student code below would fail both tests:: a = 1 b = 2 a = 3 # incorrect final value of a """ rep = Reporter.active_reporter rep.set_tag("fun", "test_object") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg = "", state=state) if do_eval: has_equal_value(incorrect_msg or MSG_INCORRECT, state=child)
def test_object(name, eq_condition="equal", eq_fun=None, do_eval=True, undefined_msg=None, incorrect_msg=None, state=None): child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state) if do_eval: has_equal_value(incorrect_msg or MSG_INCORRECT, state=child)
def test_object(name, eq_condition="equal", eq_fun=None, do_eval=True, undefined_msg=None, incorrect_msg=None, state=None): expand_msg = "" if undefined_msg or incorrect_msg else None child = check_object(name, undefined_msg, expand_msg=expand_msg, state=state) if do_eval: has_equal_value(incorrect_msg, state=child)
def test_dictionary(name, keys=None, undefined_msg=None, not_dictionary_msg=None, key_missing_msg=None, incorrect_value_msg=None, state=None): """Test the contents of a dictionary. """ rep = Reporter.active_reporter rep.set_tag("fun", "test_dictionary") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg = "", state=state, typestr="dictionary") is_instance(dict, not_dictionary_msg or MSG_NOT_INSTANCE, state=child) # test instance # set keys or check if manual keys are valid if not keys: keys = getKeysInProcess(name, state.solution_process) for key in keys: # check if key in dictionary has_equal_key(key, incorrect_value_msg or MSG_INCORRECT_VAL, key_missing_msg or MSG_KEY_MISSING, state=child)
def test_data_frame(name, columns=None, undefined_msg=None, not_data_frame_msg=None, undefined_cols_msg=None, incorrect_msg=None, state=None): """Test a pandas dataframe. """ rep = Reporter.active_reporter rep.set_tag("fun", "test_data_frame") child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state, typestr="pandas DataFrame") is_instance(pd.DataFrame, not_data_frame_msg or MSG_NOT_INSTANCE, state=child) # test instance sol_cols = getColumnsInProcess(name, child.solution_process) if sol_cols is None: raise ValueError( "Something went wrong in figuring out the columns for %s in the solution process" % name) # set columns or check if manual columns are valid if columns is None: columns = sol_cols for col in columns: # check if column available has_equal_key(col, incorrect_msg or MSG_INCORRECT_VAL, undefined_cols_msg or MSG_KEY_MISSING, state=child)