/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/bash_completion/tests/test_bashcomp.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 01:18:08 UTC
  • mfrom: (7143 work)
  • mto: This revision was merged to the branch mainline in revision 7151.
  • Revision ID: jelmer@jelmer.uk-20181106011808-y870f4vq0ork3ahu
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import sys
18
18
 
19
19
import breezy
20
 
from breezy import commands, tests
 
20
from breezy import commands, osutils, tests
21
21
from breezy.tests import features
22
22
from breezy.plugins.bash_completion.bashcomp import *
23
23
 
45
45
                                stderr=subprocess.PIPE)
46
46
        if cword < 0:
47
47
            cword = len(words) + cword
48
 
        input = '%s\n' % self.script
49
 
        input += ('COMP_WORDS=( %s )\n' %
50
 
                  ' '.join(["'"+w.replace("'", "'\\''")+"'" for w in words]))
51
 
        input += 'COMP_CWORD=%d\n' % cword
52
 
        input += '%s\n' % getattr(self, 'script_name', '_brz')
53
 
        input += 'echo ${#COMPREPLY[*]}\n'
54
 
        input += "IFS=$'\\n'\n"
55
 
        input += 'echo "${COMPREPLY[*]}"\n'
 
48
        encoding = osutils.get_user_encoding()
 
49
        input = b'%s\n' % self.script.encode(encoding)
 
50
        input += (b'COMP_WORDS=( %s )\n' %
 
51
                  b' '.join([b"'"+w.replace("'", "'\\''").encode(encoding)+b"'" for w in words]))
 
52
        input += b'COMP_CWORD=%d\n' % cword
 
53
        input += b'%s\n' % getattr(self, 'script_name', '_brz').encode(encoding)
 
54
        input += b'echo ${#COMPREPLY[*]}\n'
 
55
        input += b"IFS=$'\\n'\n"
 
56
        input += b'echo "${COMPREPLY[*]}"\n'
56
57
        (out, err) = proc.communicate(input)
57
 
        if '' != err:
 
58
        if b'' != err:
58
59
            raise AssertionError('Unexpected error message:\n%s' % err)
59
 
        self.assertEqual('', err, 'No messages to standard error')
 
60
        self.assertEqual(b'', err, 'No messages to standard error')
60
61
        #import sys
61
62
        #print >>sys.stdout, '---\n%s\n---\n%s\n---\n' % (input, out)
62
 
        lines = out.split('\n')
 
63
        lines = out.split(b'\n')
63
64
        nlines = int(lines[0])
64
65
        del lines[0]
65
 
        self.assertEqual('', lines[-1], 'Newline at end')
 
66
        self.assertEqual(b'', lines[-1], 'Newline at end')
66
67
        del lines[-1]
67
 
        if nlines == 0 and len(lines) == 1 and lines[0] == '':
 
68
        if nlines == 0 and len(lines) == 1 and lines[0] == b'':
68
69
            del lines[0]
69
70
        self.assertEqual(nlines, len(lines), 'No newlines in generated words')
70
 
        self.completion_result = set(lines)
 
71
        self.completion_result = {l.decode(encoding) for l in lines}
71
72
        return self.completion_result
72
73
 
73
74
    def assertCompletionEquals(self, *words):
166
167
    def test_revspec_tag_all(self):
167
168
        self.requireFeature(features.sed_feature)
168
169
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
169
 
        wt.branch.tags.set_tag('tag1', 'null:')
170
 
        wt.branch.tags.set_tag('tag2', 'null:')
171
 
        wt.branch.tags.set_tag('3tag', 'null:')
 
170
        wt.branch.tags.set_tag('tag1', b'null:')
 
171
        wt.branch.tags.set_tag('tag2', b'null:')
 
172
        wt.branch.tags.set_tag('3tag', b'null:')
172
173
        self.complete(['brz', 'log', '-r', 'tag', ':'])
173
174
        self.assertCompletionEquals('tag1', 'tag2', '3tag')
174
175
 
175
176
    def test_revspec_tag_prefix(self):
176
177
        self.requireFeature(features.sed_feature)
177
178
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
178
 
        wt.branch.tags.set_tag('tag1', 'null:')
179
 
        wt.branch.tags.set_tag('tag2', 'null:')
180
 
        wt.branch.tags.set_tag('3tag', 'null:')
 
179
        wt.branch.tags.set_tag('tag1', b'null:')
 
180
        wt.branch.tags.set_tag('tag2', b'null:')
 
181
        wt.branch.tags.set_tag('3tag', b'null:')
181
182
        self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
182
183
        self.assertCompletionEquals('tag1', 'tag2')
183
184
 
184
185
    def test_revspec_tag_spaces(self):
185
186
        self.requireFeature(features.sed_feature)
186
187
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
187
 
        wt.branch.tags.set_tag('tag with spaces', 'null:')
 
188
        wt.branch.tags.set_tag('tag with spaces', b'null:')
188
189
        self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
189
190
        self.assertCompletionEquals(r'tag\ with\ spaces')
190
191
        self.complete(['brz', 'log', '-r', '"tag:t'])
195
196
    def test_revspec_tag_endrange(self):
196
197
        self.requireFeature(features.sed_feature)
197
198
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
198
 
        wt.branch.tags.set_tag('tag1', 'null:')
199
 
        wt.branch.tags.set_tag('tag2', 'null:')
 
199
        wt.branch.tags.set_tag('tag1', b'null:')
 
200
        wt.branch.tags.set_tag('tag2', b'null:')
200
201
        self.complete(['brz', 'log', '-r', '3..tag', ':', 't'])
201
202
        self.assertCompletionEquals('tag1', 'tag2')
202
203
        self.complete(['brz', 'log', '-r', '"3..tag:t'])