Пример #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, '')])
Пример #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, '')])
Пример #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)
Пример #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')
Пример #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 ")
Пример #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 ')
Пример #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\\ ")
Пример #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')
Пример #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?
Пример #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.")
Пример #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)
Пример #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)
Пример #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 ')
Пример #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 ")
Пример #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")
Пример #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)
Пример #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)
Пример #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')
Пример #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)
Пример #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 ')
Пример #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.")
Пример #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"
Пример #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?
Пример #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 ")
Пример #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\\ ")
Пример #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 ")
Пример #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")
Пример #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)
Пример #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")
Пример #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 ')
Пример #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')
Пример #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_ ")
Пример #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 "))
Пример #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' ")
Пример #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 ")
Пример #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' ")
Пример #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.")
Пример #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, '')
Пример #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)
Пример #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)
Пример #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)
Пример #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")
Пример #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)
Пример #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.")
Пример #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' ")
Пример #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 ")
Пример #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 ")
Пример #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, '')
Пример #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.")
Пример #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' ")
Пример #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 "))
Пример #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")
Пример #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"
Пример #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.")
Пример #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.")
Пример #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' ")
Пример #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")
Пример #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)
Пример #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?
Пример #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)