コード例 #1
0
ファイル: test_check_funcs.py プロジェクト: optionalg/sqlwhat
def prepare_state(solution_code, student_code, dialect='postgresql'):
    dispatcher = Dispatcher.from_module(PARSER_MODULES[dialect])
    return State(
        student_code=student_code,
        solution_code=solution_code,
        reporter=Reporter(),
        # args below should be ignored
        pre_exercise_code="NA",
        student_result=[],
        solution_result=[],
        student_conn=None,
        solution_conn=None,
        ast_dispatcher=dispatcher)
コード例 #2
0
ファイル: test_line_info.py プロジェクト: fossabot/sqlwhat
def test_line_info(sql_cmd, start, pos):
    state = State(sql_cmd,
                  "",
                  "",
                  None,
                  None, {}, {},
                  Reporter(),
                  ast_dispatcher=Dispatcher.from_module(
                      PARSER_MODULES['mssql']))
    try:
        state.do_test("failure message")
    except TF as tf:
        for ii, k in enumerate(pos_names):
            assert tf.payload[k] == pos[ii]
コード例 #3
0
ファイル: State.py プロジェクト: optionalg/sqlwhat
    def get_dispatcher(self):
        # MCE doesn't always have connection - fallback on postgresql
        dialect = self.student_conn.dialect.name if self.student_conn else 'postgresql'
        ast_dispatcher = Dispatcher.from_module(PARSER_MODULES[dialect])

        # TODO: the code below monkney patches the mssql ast to use only lowercase
        #       representations. This is because msft server has a setting to be
        #       case sensitive. However, this is often not the case, and probably
        #       detremental to DataCamp courses. Need to move to more sane configuration.
        #        if dialect_name == 'mssql':
        if dialect == 'mssql':
            AstNode = ast_dispatcher.ast.AstNode
            AstNode.__repr__ = lower_case(AstNode.__repr__)

        return ast_dispatcher
コード例 #4
0
    def get_dispatcher(self):
        if not self.student_conn:
            return DummyDispatcher()

        dialect = self.student_conn.dialect.name
        ast_dispatcher = Dispatcher.from_module(PARSER_MODULES[dialect])

        # TODO: the code below monkney patches the mssql ast to use only lowercase
        #       representations. This is because msft server has a setting to be
        #       case sensitive. However, this is often not the case, and probably
        #       detremental to DataCamp courses. Need to move to more sane configuration.
        if dialect == "mssql":
            AstNode = ast_dispatcher.ast_mod.AstNode
            AstNode.__repr__ = lower_case(AstNode.__repr__)

        return ast_dispatcher
コード例 #5
0
def test_state_line_info():
    state = State("\nSELECT x FROM y",
                  "SELECT x FROM y",
                  "",
                  None,
                  None, {}, {},
                  Reporter(),
                  ast_dispatcher=Dispatcher.from_module(
                      PARSER_MODULES['mssql']))

    with pytest.raises(TF):
        state.do_test("failure message")

    payload = state.reporter.build_payload()

    pos = [2, 1, 2, 15]
    pos_names = ['line_start', 'column_start', 'line_end', 'column_end']
    for ii, k in enumerate(pos_names):
        assert payload[k] == pos[ii]
コード例 #6
0
ファイル: test_selectors.py プロジェクト: codecamp/sqlwhat
def dispatcher():
    return Dispatcher.from_module(ast())
コード例 #7
0
ファイル: State.py プロジェクト: codecamp/shellwhat
 def get_dispatcher(self):
     return Dispatcher.from_module(DEFAULT_PARSER)