Esempio n. 1
0
 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, '')])
Esempio n. 2
0
 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, '')])
Esempio n. 3
0
    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)
Esempio n. 4
0
 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')
Esempio n. 5
0
 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 ")
Esempio n. 6
0
 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 ')
Esempio n. 7
0
 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\\ ")
Esempio n. 8
0
 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')
Esempio n. 9
0
 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?
Esempio n. 10
0
 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.")
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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 ')
Esempio n. 14
0
 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 ")
Esempio n. 15
0
 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")
Esempio n. 16
0
 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)
Esempio n. 17
0
 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)
Esempio n. 18
0
    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')
Esempio n. 19
0
 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)
Esempio n. 20
0
    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 ')
Esempio n. 21
0
    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.")
Esempio n. 22
0
 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"
Esempio n. 23
0
    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?
Esempio n. 24
0
    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 ")
Esempio n. 25
0
    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\\ ")
Esempio n. 26
0
 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 ")
Esempio n. 27
0
 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")
Esempio n. 28
0
 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)
Esempio n. 29
0
 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")
Esempio n. 30
0
    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 ')
Esempio n. 31
0
    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')
Esempio n. 32
0
 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_ ")
Esempio n. 33
0
 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 "))
Esempio n. 34
0
 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' ")
Esempio n. 35
0
 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 ")
Esempio n. 36
0
 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' ")
Esempio n. 37
0
 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.")
Esempio n. 38
0
 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, '')
Esempio n. 39
0
    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)
Esempio n. 40
0
    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)
Esempio n. 41
0
    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)
Esempio n. 42
0
    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")
Esempio n. 43
0
    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)
Esempio n. 44
0
 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.")
Esempio n. 45
0
    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' ")
Esempio n. 46
0
 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 ")
Esempio n. 47
0
    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 ")
Esempio n. 48
0
    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, '')
Esempio n. 49
0
    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.")
Esempio n. 50
0
    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' ")
Esempio n. 51
0
    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 "))
Esempio n. 52
0
 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")
Esempio n. 53
0
    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"
Esempio n. 54
0
    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.")
Esempio n. 55
0
    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.")
Esempio n. 56
0
    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' ")
Esempio n. 57
0
    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")
Esempio n. 58
0
    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)
Esempio n. 59
0
    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?
Esempio n. 60
0
 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)