<s> """<STR_LIT>""" <EOL> import functools <EOL> import pytest <EOL> from pyqode . qt import QtCore , QtGui <EOL> from pyqode . qt . QtTest import QTest <EOL> from pyqode . core . api import TextHelper <EOL> from pyqode . core import modes <EOL> from pyqode . core . modes . code_completion import SubsequenceCompleter <EOL> from . . helpers import server_path , wait_for_connected <EOL> from . . helpers import ensure_visible , ensure_connected <EOL> def get_mode ( editor ) : <EOL> return editor . modes . get ( modes . CodeCompletionMode ) <EOL> code = '''<STR_LIT>''' <EOL> def ensure_empty ( func ) : <EOL> @ functools . wraps ( func ) <EOL> def wrapper ( editor , * args , ** kwds ) : <EOL> editor . file . _path = None <EOL> editor . setPlainText ( code , '<STR_LIT>' , '<STR_LIT:utf-8>' ) <EOL> return func ( editor , * args , ** kwds ) <EOL> return wrapper <EOL> @ ensure_empty <EOL> @ ensure_visible <EOL> @ ensure_connected <EOL> def test_enabled ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> assert mode . enabled <EOL> mode . enabled = False <EOL> mode . enabled = True <EOL> @ ensure_empty <EOL> @ ensure_visible <EOL> @ ensure_connected <EOL> def test_properties ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> mode . trigger_key = '<STR_LIT:A>' <EOL> assert mode . trigger_key == '<STR_LIT:A>' <EOL> mode . trigger_length = <NUM_LIT:3> <EOL> assert mode . trigger_length == <NUM_LIT:3> <EOL> mode . trigger_symbols = [ '<STR_LIT:.>' , '<STR_LIT>' ] <EOL> assert len ( mode . trigger_symbols ) == <NUM_LIT:2> <EOL> assert '<STR_LIT:.>' in mode . trigger_symbols <EOL> assert '<STR_LIT>' in mode . trigger_symbols <EOL> mode . show_tooltips = False <EOL> assert mode . show_tooltips is False <EOL> mode . case_sensitive = True <EOL> assert mode . case_sensitive is True <EOL> mode . trigger_key = <NUM_LIT:1> <EOL> @ ensure_empty <EOL> @ ensure_visible <EOL> @ ensure_connected <EOL> def test_request_completion ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> if editor . backend . running : <EOL> editor . backend . stop ( ) <EOL> TextHelper ( editor ) . goto_line ( <NUM_LIT:0> ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> mode . request_completion ( ) <EOL> editor . backend . start ( server_path ( ) ) <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> assert editor . backend . running is True <EOL> TextHelper ( editor ) . goto_line ( <NUM_LIT:3> ) <EOL> QTest . qWait ( <NUM_LIT:100> ) <EOL> assert mode . request_completion ( ) is True <EOL> QTest . qWait ( <NUM_LIT:100> ) <EOL> @ ensure_empty <EOL> @ ensure_visible <EOL> @ ensure_connected <EOL> def test_successive_requests ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> TextHelper ( editor ) . goto_line ( <NUM_LIT:3> ) <EOL> assert editor . backend . running <EOL> ret1 = mode . request_completion ( ) <EOL> ret2 = mode . request_completion ( ) <EOL> assert ret1 is True <EOL> assert ret2 is True <EOL> @ ensure_visible <EOL> @ ensure_empty <EOL> @ ensure_connected <EOL> def test_events ( editor ) : <EOL> assert editor . backend . running <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> TextHelper ( editor ) . goto_line ( <NUM_LIT:3> ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Space , QtCore . Qt . ControlModifier ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Escape ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:m>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:o>' ) <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Escape ) <EOL> QTest . keyPress ( editor , '<STR_LIT:U+0020>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:m>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:o>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:d>' ) <EOL> QTest . qWait ( <NUM_LIT:10> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:U+0020>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:e>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:n>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:a>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:b>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:l>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:e>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:d>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:U+0020>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:t>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:.>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , '<STR_LIT>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:t>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Space , QtCore . Qt . ControlModifier ) <EOL> @ ensure_empty <EOL> @ ensure_visible <EOL> @ ensure_connected <EOL> def test_insert_completions ( editor ) : <EOL> assert editor . backend . running <EOL> TextHelper ( editor ) . goto_line ( <NUM_LIT:3> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:m>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:o>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Return ) <EOL> QTest . keyPress ( editor , QtCore . Qt . Key_Return ) <EOL> QTest . keyPress ( editor , '<STR_LIT>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:T>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:e>' ) <EOL> QTest . keyPress ( editor , '<STR_LIT:s>' ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> QTest . keyPress ( editor , '<STR_LIT:t>' ) <EOL> QTest . qWait ( <NUM_LIT:100> ) <EOL> @ ensure_empty <EOL> @ ensure_connected <EOL> def test_show_completion_with_tooltip ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> mode . show_tooltips = True <EOL> mode . _show_completions ( [ { '<STR_LIT:name>' : '<STR_LIT:test>' , '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> mode . _display_completion_tooltip ( '<STR_LIT:test>' ) <EOL> mode . _display_completion_tooltip ( '<STR_LIT>' ) <EOL> mode . show_tooltips = False <EOL> mode . _display_completion_tooltip ( '<STR_LIT:test>' ) <EOL> @ ensure_empty <EOL> @ ensure_connected <EOL> def test_show_completion_with_icon ( editor ) : <EOL> mode = get_mode ( editor ) <EOL> mode . _show_completions ( [ { '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> QtCore . Qt . CaseSensitive , QtCore . Qt . CaseInsensitive ] ) <EOL> def test_subsequence_completer ( case ) : <EOL> completer = SubsequenceCompleter ( ) <EOL> words = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> model = QtGui . QStandardItemModel ( ) <EOL> for word in words : <EOL> item = QtGui . QStandardItem ( ) <EOL> item . setData ( word , QtCore . Qt . DisplayRole ) <EOL> model . appendRow ( item ) <EOL> completer . setCaseSensitivity ( case ) <EOL> completer . setModel ( model ) <EOL> if case == QtCore . Qt . CaseInsensitive : <EOL> completer . setCompletionPrefix ( '<STR_LIT>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:3> <EOL> completer . setCompletionPrefix ( '<STR_LIT>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:2> <EOL> completer . update_model ( ) <EOL> completer . setCompletionPrefix ( '<STR_LIT:action>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:3> <EOL> else : <EOL> completer . setCompletionPrefix ( '<STR_LIT>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:1> <EOL> completer . setCompletionPrefix ( '<STR_LIT>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:3> <EOL> completer . setCompletionPrefix ( '<STR_LIT>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:1> <EOL> completer . setCompletionPrefix ( '<STR_LIT:action>' ) <EOL> completer . update_model ( ) <EOL> assert completer . completionCount ( ) == <NUM_LIT:2> </s>
