def test_detect_robot_context_settings(): assert detect_robot_context("""\ *** Settings *** """, -1) == '__settings__' assert detect_robot_context("""\ *** Settings *** *** Tasks *** """, len('*** Settings ***')) == '__settings__'
def test_detect_robot_context_root(): assert detect_robot_context('', -1) == '__root__' assert detect_robot_context("""\ *** Variables *** """, -1) == '__root__' assert detect_robot_context("""\ *** Settings *** *** Variables *** """, -1) == '__root__'
def test_detect_robot_context_settings(): assert ( detect_robot_context( """\ *** Settings *** """, -1, ) == "__settings__" ) assert ( detect_robot_context( """\ *** Settings *** *** Tasks *** """, len("*** Settings ***"), ) == "__settings__" )
def test_detect_robot_context_root(): assert detect_robot_context("", -1) == "__root__" assert ( detect_robot_context( """\ *** Variables *** """, -1, ) == "__root__" ) assert ( detect_robot_context( """\ *** Settings *** *** Variables *** """, -1, ) == "__root__" )
def test_detect_robot_context_tasks(): assert ( detect_robot_context( """\ *** Test Cases *** This is a test case With a keyword and param """, -1, ) == "__tasks__" ) assert ( detect_robot_context( """\ *** Settings *** *** Test Cases *** This is a test case With a keyword and param """, -1, ) == "__tasks__" ) assert ( detect_robot_context( """\ *** Settings *** *** Tasks *** This is a task With a keyword and param """, -1, ) == "__tasks__" )
def do_complete(self, code, cursor_pos): cursor_pos = cursor_pos is None and len(code) or cursor_pos line, offset = line_at_cursor(code, cursor_pos) line_cursor = cursor_pos - offset needle = re.split(r"\s{2,}|\t| \| ", line[:line_cursor])[-1].lstrip() if needle and needle[0] in "$@&%": # is variable completion matches = [ m["ref"] for m in scored_results( needle, [ dict(ref=v) for v in (self.robot_variables + VARIABLE_REGEXP.findall(code)) ], ) if needle.lower() in m["ref"].lower() ] if len(line) > line_cursor and line[line_cursor] == "}": cursor_pos += 1 needle += "}" elif is_selector(needle): matches = [] for driver in yield_current_connection(self.robot_connections, ["selenium", "appium"]): matches = get_selector_completions(needle.rstrip(), driver) elif is_autoit_selector(needle): matches = get_autoit_selector_completions(needle) elif is_white_selector(needle): matches = get_white_selector_completions(needle) else: # Clear selector completion highlights for driver in yield_current_connection(self.robot_connections, ["selenium"]): clear_selector_highlights(driver) context = detect_robot_context(code, cursor_pos) matches = get_lunr_completions( needle, self.robot_catalog["index"], self.robot_catalog["keywords"], context, ) return { "matches": matches, "cursor_end": cursor_pos, "cursor_start": cursor_pos - len(needle), "metadata": {}, "status": "ok", }
def do_complete(self, code, cursor_pos): cursor_pos = cursor_pos is None and len(code) or cursor_pos line, offset = line_at_cursor(code, cursor_pos) line_cursor = cursor_pos - offset needle = re.split(r'\s{2,}|\t| \| ', line[:line_cursor])[-1].lstrip() if needle and needle[0] in '$@&%': # is variable completion matches = [ m['ref'] for m in scored_results( needle, [ dict(ref=v) for v in (self.robot_variables + VARIABLE_REGEXP.findall(code)) ], ) if needle.lower() in m['ref'].lower() ] if len(line) > line_cursor and line[line_cursor] == '}': cursor_pos += 1 needle += '}' elif is_selector(needle): matches = [] for driver in yield_current_connection(self.robot_connections, ['selenium', 'appium']): matches = get_selector_completions(needle.rstrip(), driver) elif is_autoit_selector(needle): matches = get_autoit_selector_completions(needle) elif is_white_selector(needle): matches = get_white_selector_completions(needle) else: # Clear selector completion highlights for driver in yield_current_connection(self.robot_connections, ['selenium']): clear_selector_highlights(driver) context = detect_robot_context(code, cursor_pos) matches = get_lunr_completions( needle, self.robot_catalog['index'], self.robot_catalog['keywords'], context, ) return { 'matches': matches, 'cursor_end': cursor_pos, 'cursor_start': cursor_pos - len(needle), 'metadata': {}, 'status': 'ok', }