def mock_hacr_connection(table, start, stop):
<EOL>cursor = mock.MagicMock()<EOL>def execute(qstr):<EOL><INDENT>cursor._query = sqlparse.parse(qstr)[<NUM_LIT:0>]<EOL>return len(table)<EOL><DEDENT>cursor.execute = execute<EOL>def fetchall():<EOL><INDENT>if cursor._query.get_real_name() == '<STR_LIT>':<EOL><INDENT>return [(<NUM_LIT:1>, start, stop)]<EOL><DEDENT>if cursor._query.get_real_name() == '<STR_LIT>':<EOL><INDENT>columns = list(map(<EOL>str, list(cursor._query.get_sublists())[<NUM_LIT:0>].get_identifiers()))<EOL>selections = list(map(<EOL>str, list(cursor._query.get_sublists())[<NUM_LIT:2>].get_sublists()))<EOL>return filter_table(table, selections[<NUM_LIT:3>:])[columns]<EOL><DEDENT><DEDENT>cursor.fetchall = fetchall<EOL>conn = mock.MagicMock()<EOL>conn.cursor.return_value = cursor<EOL>return conn<EOL>
Mock a pymysql connection object to test HACR fetching