~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_status.py

Status tests include unicode character.

Make it work by going to an encoded temporary file, not a StringIO.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""
22
22
 
23
23
 
 
24
from cStringIO import StringIO
 
25
from os import mkdir
 
26
from tempfile import TemporaryFile
 
27
import codecs
 
28
 
24
29
from bzrlib.tests import TestCaseInTempDir
25
30
from bzrlib.revisionspec import RevisionSpec
26
31
from bzrlib.merge import merge
27
 
from cStringIO import StringIO
28
32
from bzrlib.status import show_status
29
33
from bzrlib.branch import Branch
30
 
from os import mkdir
31
34
from bzrlib.clone import copy_branch
32
35
 
33
36
class BranchStatus(TestCaseInTempDir):
97
100
                           '  hello.c\n'])
98
101
 
99
102
    def status_string(self, branch):
100
 
        tof = StringIO()
 
103
        # use a real file rather than StringIO because it doesn't handle
 
104
        # Unicode very well.
 
105
        tof = codecs.getwriter('utf-8')(TemporaryFile())
101
106
        show_status(branch, to_file=tof)
102
107
        tof.seek(0)
103
 
        return tof.getvalue()
 
108
        return tof.read().decode('utf-8')
104
109
 
105
110
    def test_pending(self):
106
 
        """Pending merges display works"""
 
111
        """Pending merges display works, including Unicode"""
107
112
        mkdir("./branch")
108
113
        b = Branch.initialize('./branch')
109
114
        b.working_tree().commit("Empty commit 1")
110
115
        b_2 = copy_branch(b, './copy')
111
 
        b.working_tree().commit("Empty commit 2")
 
116
        b.working_tree().commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
112
117
        merge(["./branch", -1], [None, None], this_dir = './copy')
113
118
        message = self.status_string(b_2)
114
119
        self.assert_(message.startswith("pending merges:\n"))
115
120
        self.assert_(message.endswith("Empty commit 2\n")) 
116
121
        b_2.working_tree().commit("merged")
117
122
        # must be long to make sure we see elipsis at the end
118
 
        b.working_tree().commit("Empty commit 3 blah blah blah blah blah blah blah blah blah"
119
 
                 " blah blah blah blah blah blah bleh")
 
123
        b.working_tree().commit("Empty commit 3 " + 
 
124
                                "blah blah blah blah " * 10)
120
125
        merge(["./branch", -1], [None, None], this_dir = './copy')
121
126
        message = self.status_string(b_2)
122
127
        self.assert_(message.startswith("pending merges:\n"))