def test_filename_quoting_function(self): completer.completer = filecomplete completer.filename_quoting_function = hook completer.filename_quote_characters = ' \t\n"\'' self.mkfile('fred flintstone.txt') readline.complete_internal(TAB) self.assertEqual(called, [('fred flintstone.txt', True, '')])
def test_char_is_quoted_multi_utf8(self): def func(text, index): called.append((text, index)) return is_quoted(text, index) completer.char_is_quoted_function = func completer.quote_characters = '"' completer.word_break_characters = ' ' completion.line_buffer = 'Ää\\ ÖöÜü\\ abc' readline.complete_internal(TAB) if sys.version_info[0] >= 3: self.assertEqual(called, [('Ää\\ ÖöÜü\\ abc', 9), ('Ää\\ ÖöÜü\\ abc', 3), ('Ää\\ ÖöÜü\\ abc', 0)]) self.assertEqual(completion.begidx, 0) self.assertEqual(completion.endidx, 13) else: self.assertEqual( called, [('\xc3\x84\xc3\xa4\\ \xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc\\ abc', 15), ('\xc3\x84\xc3\xa4\\ \xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc\\ abc', 5), ('\xc3\x84\xc3\xa4\\ \xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc\\ abc', 0)]) self.assertEqual(completion.begidx, 0) self.assertEqual(completion.endidx, 19)
def test_bad_completer(self): @generator def func(text): raise RuntimeError() completer.completer = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, 'fr')
def test_bad_hook(self): def func(text, single_match, quote_char): return 23 self.mkfile('fr ed.txt') completer.filename_quoting_function = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "fr ed.txt ")
def test_complete(self): @generator def func(text): return ['fred'] completer.completer = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, 'fred ')
def test_none_hook(self): def func(text, quote_char): return None self.mkfile('fr ed.txt') completer.filename_dequoting_function = func completion.line_buffer = 'fr\\ ' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "fr\\ ")
def test_none_matches(self): @generator def func(text): return [None] completer.completer = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, 'fr')
def test_empty_string(self): @generator def func(text): return [''] completer.completer = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, 'fr ') # XXX Single match?
def test_bad_hook(self): def func(substitution, matches): return 23 self.mkfile('fred.txt') self.mkfile('fred.gif') completer.ignore_some_completions_function = func readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "fred.")
def test_word_break_hook_indexes(self): completer.word_break_hook = hook completer.word_break_characters = ' ' completion.line_buffer = 'fr ed' readline.complete_internal(TAB) self.assertEqual(called, [(3, 5)]) self.assertEqual(completion.begidx, 3) self.assertEqual(completion.endidx, 5)
def test_complete_utf8(self): @generator def func(text): return ['Mädchen'] completer.completer = func completion.line_buffer = 'Mä' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, 'Mädchen ')
def test_bad_hook(self): def func(filename): return 23 self.mkfile('fred.txt') completer.filename_rewrite_hook = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "fred.txt ")
def test_bad_hook(self): def func(dirname): return 23 self.mkdir('flint stone') self.mkfile('flint stone/fred.txt') completer.directory_completion_hook = func completion.line_buffer = 'flint\\ stone/fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "flint\\ stone/fr")
def test_char_is_not_quoted(self): def func(text, index): return False completer.char_is_quoted_function = func completer.quote_characters = '"' completion.line_buffer = 'fr\\ ed' readline.complete_internal(TAB) self.assertEqual(completion.begidx, 4) self.assertEqual(completion.endidx, 6)
def test_bad_hook(self): def func(text, index): raise RuntimeError() completer.char_is_quoted_function = func completer.quote_characters = '"' completion.line_buffer = 'fr\\ ed' readline.complete_internal(TAB) self.assertEqual(completion.begidx, 4) self.assertEqual(completion.endidx, 6)
def test_replaces_word_break_characters(self): def func(begidx, endidx): return '!' completer.word_break_hook = func completer.word_break_characters = ' ' completion.line_buffer = 'f!r ed' readline.complete_internal(TAB) self.assertEqual(completion.begidx, 2) self.assertEqual(completion.endidx, 6)
def test_display_matches_hook_utf8(self): @generator def func(text): return ['Mädchen.gif', 'Mädchen.txt'] completer.completer = func completer.display_matches_hook = hook readline.complete_internal('?') self.assertEqual(called, [('Mädchen.', ['Mädchen.gif', 'Mädchen.txt'], 11)]) # "maximum printed length"
def test_none_hook(self): def func(filename): return None self.mkdir('flintstone') self.mkfile('flintstone/fred.txt') completer.filename_stat_hook = func completion.line_buffer = 'flintstone/fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "flintstone/fred.txt ")
def test_empty_string(self): def func(dirname): return '' self.mkdir('flint stone') self.mkfile('flint stone/fred.txt') completer.directory_rewrite_hook = func completion.line_buffer = 'flint\\ stone/fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "flint\\ stone/fr")
def test_empty_string(self): def func(begidx, endidx): return '' completer.word_break_hook = func completer.word_break_characters = ' ' completion.line_buffer = 'fr ed' readline.complete_internal(TAB) self.assertEqual(completion.begidx, 0) self.assertEqual(completion.endidx, 5)
def test_empty_string(self): def func(filename): called.append(filename) return '' self.mkfile('fred.txt') completer.filename_rewrite_hook = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "fr")
def test_filename_rewrite_hook(self): def func(filename): called.append(filename) return filename + '_' self.mkfile('fred.txt') completer.filename_rewrite_hook = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(sorted(called), ['.', '..', 'fred.txt']) self.assertEqual(completion.line_buffer, "fred.txt_ ")
def test_filename_quoting_function(self): def func(text, single_match, quote_char): called.append((text, single_match, quote_char)) return text.replace(' ', '\\ ') self.mkfile('Mä dchen.txt') completer.filename_quoting_function = func completion.line_buffer = decompose('Mä') readline.complete_internal(TAB) self.assertEqual(called, [(decompose('Mä dchen.txt'), True, '')]) self.assertEqual(completion.line_buffer, decompose("Mä\\ dchen.txt "))
def test_filename_dequoting_function(self): def func(text, quote_char): called.append((text, quote_char)) return text.replace('\\', '') self.mkfile('fr ed.txt') completer.filename_dequoting_function = func completion.line_buffer = 'fr\\ ' readline.complete_internal(TAB) self.assertEqual(called, [('.', ''), ('fr\\ ', '')]) self.assertEqual(completion.line_buffer, "'fr ed.txt' ")
def test_no_quoting(self): def func(text, single_match, quote_char): called.append((text, single_match, quote_char)) return text self.mkfile('fr ed.txt') completer.filename_quoting_function = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(called, [('fr ed.txt', True, '')]) self.assertEqual(completion.line_buffer, "fr ed.txt ")
def test_quote_char(self): def func(text, quote_char): called.append((text, quote_char)) return text self.mkfile('fr ed.txt') completer.filename_dequoting_function = func completion.line_buffer = "'fr " readline.complete_internal(TAB) self.assertEqual(called, [('.', "'"), ('fr ', "'")]) self.assertEqual(completion.line_buffer, "'fr ed.txt' ")
def test_no_ignore(self): def func(substitution, matches): called.append((substitution, matches)) return matches self.mkfile('fred.txt') self.mkfile('fred.gif') completer.ignore_some_completions_function = func readline.complete_internal(TAB) self.assertEqual(called, [('fred.', ['fred.gif', 'fred.txt'])]) self.assertEqual(completion.line_buffer, "fred.")
def test_empty_string(self): def func(text, single_match, quote_char): called.append((text, single_match, quote_char)) return '' self.mkfile('fr ed.txt') self.mkfile('fr ed.gif') completer.filename_quoting_function = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, '')
def test_empty_string(self): def func(dirname): return '' self.mkdir('flint stone') self.mkfile('flint stone/fred.txt') completer.directory_completion_hook = func completion.line_buffer = 'flint\\ stone/fr' readline.complete_internal(TAB) self.assertEqual(completion.line_buffer, "flint\\ stone/fr")
def test_quote_char(self): def func(text, single_match, quote_char): called.append((text, single_match, quote_char)) return quote_char + text self.mkfile('fr ed.txt') self.mkfile('fr ed.gif') completer.filename_quoting_function = func completion.line_buffer = "'fr" readline.complete_internal(TAB) self.assertEqual(called, [('fr ed.', False, "'")]) self.assertEqual(completion.line_buffer, "'fr ed.")
def test_empty_string(self): def func(filename): called.append(filename) return '' self.mkdir('flintstone') self.mkfile('flintstone/fred.txt') completer.filename_stat_hook = func completion.line_buffer = 'flintstone/fr' readline.complete_internal(TAB) self.assertEqual(called, ['flintstone/fred.txt']) self.assertEqual(completion.line_buffer, "flintstone/fred.txt ")
def test_no_dequoting(self): def func(dirname): called.append(dirname) return dirname self.mkdir('flint stone') self.mkfile('flint stone/fred.txt') completer.directory_rewrite_hook = func completion.line_buffer = 'flint\\ stone/fr' readline.complete_internal(TAB) self.assertEqual(called, ['flint\\ stone/']) self.assertEqual(completion.line_buffer, "flint\\ stone/fr")
def test_display_matches_hook_utf8(self): @generator def func(text): return ['Mädchen.gif', 'Mädchen.txt'] completer.completer = func completer.display_matches_hook = hook readline.complete_internal('?') self.assertEqual(called, [ ('Mädchen.', ['Mädchen.gif', 'Mädchen.txt'], 11) ]) # "maximum printed length"
def test_multi_match(self): def func(text, single_match, quote_char): called.append((text, single_match, quote_char)) return text.replace(' ', '\\ ') self.mkfile('fr ed.txt') self.mkfile('fr ed.gif') completer.filename_quoting_function = func completion.line_buffer = 'fr' readline.complete_internal(TAB) self.assertEqual(called, [('fr ed.', False, '')]) self.assertEqual(completion.line_buffer, "fr\\ ed.")
def test_directory_completion_hook(self): def func(dirname): called.append(dirname) return dirname.replace('\\', '') self.mkdir('Mä dchen') self.mkfile('Mä dchen/fred.txt') completer.directory_completion_hook = func completion.line_buffer = 'Mä\\ dchen/fr' readline.complete_internal(TAB) self.assertEqual(called, ['Mä\\ dchen/']) self.assertEqual(completion.line_buffer, "'Mä dchen/fred.txt' ")
def test_no_dequoting(self): def func(dirname): called.append(dirname) return dirname self.mkdir('flint stone') self.mkfile('flint stone/fred.txt') completer.directory_completion_hook = func completion.line_buffer = 'flint\\ stone/fr' readline.complete_internal(TAB) self.assertEqual(called, ['flint\\ stone/']) self.assertEqual(completion.line_buffer, "flint\\ stone/fr")
def test_char_is_quoted_indexes(self): def func(text, index): called.append((text, index)) return is_quoted(text, index) completer.char_is_quoted_function = func completer.quote_characters = '"' completer.word_break_characters = ' ' completion.line_buffer = 'fr\\ ed' readline.complete_internal(TAB) self.assertEqual(called, [('fr\\ ed', 3), ('fr\\ ed', 0)]) self.assertEqual(completion.begidx, 0) self.assertEqual(completion.endidx, 6)
def test_empty_string(self): def func(text, quote_char): return '' self.mkfile('fr ed.txt') self.mkfile('fr ed.gif') completer.filename_dequoting_function = func completion.line_buffer = 'fr\\ ' readline.complete_internal(TAB) if readline.readline_version() >= 0x0602: self.assertEqual(completion.line_buffer, "fr\\ ") else: self.assertEqual(completion.line_buffer, "'fr ed.") # XXX Match?
def test_word_break_hook_utf8(self): completer.word_break_hook = hook completer.word_break_characters = ' ' completion.line_buffer = 'Mä dchen' readline.complete_internal(TAB) if sys.version_info[0] >= 3: self.assertEqual(called, [(3, 8)]) self.assertEqual(completion.begidx, 3) self.assertEqual(completion.endidx, 8) else: self.assertEqual(called, [(4, 9)]) self.assertEqual(completion.begidx, 4) self.assertEqual(completion.endidx, 9)