def check_result(state): """High level function which wraps other SCTs for checking results. ``check_result()`` * uses ``lowercase()``, then * runs ``check_all_columns()`` on the state produced by ``lowercase()``, then * runs ``has_equal_value`` on the state produced by ``check_all_columns()``. """ state1 = link_to_state(lowercase)(state) state2 = link_to_state(check_all_columns)(state1) has_equal_value(state2) return state2
from protowhat.Reporter import Reporter from protowhat.sct_syntax import link_to_state from sqlwhat.State import State from sqlwhat.checks import (check_row, check_column, check_all_columns, check_result, lowercase, has_equal_value, has_no_error, has_result, has_nrows, has_ncols) check_row = link_to_state(check_row) check_column = link_to_state(check_column) check_all_columns = link_to_state(check_all_columns) check_result = link_to_state(check_result) lowercase = link_to_state(lowercase) has_equal_value = link_to_state(has_equal_value) def get_sct_payload(output): output = [out for out in output if out["type"] == "sct"] if len(output) > 0: return output[0]["payload"] else: print(output) return None def run(data): from sqlbackend.Exercise import Exercise exercise = Exercise(data) output = exercise.runInit() if "backend-error" in str(output):
from functools import partial from protowhat.sct_syntax import link_to_state from pythonwhat.checks.check_function import check_function from protowhat.failure import TestFail, InstructorError from pythonwhat.checks.check_funcs import check_args from pythonwhat.checks.has_funcs import has_equal_value, has_equal_ast, has_printout # this is done by the chain for v2 # it's only needed when a new state is created and (possibly) used elsewhere check_function = link_to_state(check_function) def arg_test(state, name, do_eval, missing_msg, incorrect_msg): arg_state = check_args(state, name=name, missing_msg=missing_msg) append = incorrect_msg is None if isinstance(do_eval, bool): if do_eval: has_equal_value(arg_state, incorrect_msg=incorrect_msg, append=append, copy=False) else: has_equal_ast(arg_state, incorrect_msg=incorrect_msg, append=append) def test_function(state,
with_context, ) from pythonwhat.test_funcs.utils import fix_format, stringify, call from pythonwhat.checks.check_logic import multi from pythonwhat.checks.has_funcs import ( has_equal_part_len, has_equal_part, has_equal_value, has_equal_output, ) from pythonwhat.checks.check_has_context import has_context from functools import partial # this is done by the chain for v2 # it's only needed when a new state is created and (possibly) used elsewhere check_node = link_to_state(check_node) check_part = link_to_state(check_part) check_part_index = link_to_state(check_part_index) def test_if_else(state, index=1, test=None, body=None, orelse=None): """Test parts of the if statement. This test function will allow you to extract parts of a specific if statement and perform a set of tests specifically on these parts. A for loop consists of three potential parts: the condition test, :code:`test`, which specifies the condition of the if statement, the :code:`body`, which is what's executed if the condition is True and a else part, :code:`orelse`, which will be executed if the condition is not True.:: if 5 == 3: print("success") else:
import pytest from protowhat.sct_syntax import link_to_state from protowhat.checks.check_funcs import ( check_node, check_edge, has_equal_ast, has_code, has_parsed_ast, ) from protowhat.selectors import Dispatcher from sqlwhat.State import State, PARSER_MODULES from protowhat.Reporter import Reporter from protowhat.Test import TestFail as TF check_node = link_to_state(check_node) check_edge = link_to_state(check_edge) has_equal_ast = link_to_state(has_equal_ast) def print_message(exc): print(exc.value.payload["message"]) def prepare_state(sol_code, stu_code, dialect="postgresql"): dispatcher = Dispatcher.from_module(PARSER_MODULES[dialect]) return State( student_code=stu_code, solution_code=sol_code, reporter=Reporter(), # args below should be ignored
from protowhat.sct_syntax import link_to_state from pythonwhat.tasks import getColumnsInProcess from pythonwhat.checks.check_object import check_object, check_df, check_keys from pythonwhat.checks.has_funcs import has_equal_value # this is done by the chain for v2 # it's only needed when a new state is created and (possibly) used elsewhere check_object = link_to_state(check_object) check_df = link_to_state(check_df) check_keys = link_to_state(check_keys) def test_object( state, name, eq_condition="equal", eq_fun=None, do_eval=True, undefined_msg=None, incorrect_msg=None, ): expand_msg = "" if undefined_msg or incorrect_msg else None child = check_object(state, name, undefined_msg, expand_msg=expand_msg) if do_eval: has_equal_value(child, incorrect_msg) def test_data_frame( state,