/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-15 11:19:02 UTC
  • mfrom: (7027.6.1 python3-bashcompletion)
  • Revision ID: breezy.the.bot@gmail.com-20180715111902-m0osz3vr0zaq7yy7
Fix bash completion plugin tests on Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/python3-bashcompletion/+merge/349621

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
58
        if b'' != err:
58
59
            raise AssertionError('Unexpected error message:\n%s' % err)
59
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):