~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_status.py

Basic BzrDir support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests of status command.
19
19
 
20
20
Most of these depend on the particular formatting used.
 
21
As such they really are blackbox tests even though some of the 
 
22
tests are not using self.capture. If we add tests for the programmatic
 
23
interface later, they will be non blackbox tests.
21
24
"""
22
25
 
23
26
 
24
 
from bzrlib.selftest import TestCaseInTempDir
25
 
from bzrlib.revisionspec import RevisionSpec
26
 
from bzrlib.merge import merge
27
27
from cStringIO import StringIO
28
 
from bzrlib.status import show_status
29
 
from bzrlib.branch import Branch
30
28
from os import mkdir
 
29
from tempfile import TemporaryFile
 
30
import codecs
 
31
 
31
32
from bzrlib.clone import copy_branch
 
33
from bzrlib.branch import Branch
 
34
from bzrlib.builtins import merge
 
35
from bzrlib.revisionspec import RevisionSpec
 
36
from bzrlib.status import show_status
 
37
from bzrlib.tests import TestCaseInTempDir
 
38
from bzrlib.workingtree import WorkingTree
 
39
 
32
40
 
33
41
class BranchStatus(TestCaseInTempDir):
34
42
    
35
43
    def test_branch_status(self): 
36
44
        """Test basic branch status"""
37
 
        from cStringIO import StringIO
38
 
        from bzrlib.status import show_status
39
 
        from bzrlib.branch import Branch
40
 
        
41
 
        b = Branch.initialize('.')
 
45
        wt = WorkingTree.create_standalone('.')
 
46
        b = wt.branch
42
47
 
43
48
        # status with nothing
44
49
        tof = StringIO()
47
52
 
48
53
        tof = StringIO()
49
54
        self.build_tree(['hello.c', 'bye.c'])
50
 
        b.add_pending_merge('pending@pending-0-0')
 
55
        wt.add_pending_merge('pending@pending-0-0')
51
56
        show_status(b, to_file=tof)
52
57
        tof.seek(0)
53
58
        self.assertEquals(tof.readlines(),
60
65
 
61
66
    def test_branch_status_revisions(self):
62
67
        """Tests branch status with revisions"""
63
 
        
64
 
        b = Branch.initialize('.')
 
68
        wt = WorkingTree.create_standalone('.')
 
69
        b = wt.branch
65
70
 
66
71
        tof = StringIO()
67
72
        self.build_tree(['hello.c', 'bye.c'])
68
 
        b.add('hello.c')
69
 
        b.add('bye.c')
70
 
        b.commit('Test message')
 
73
        wt.add('hello.c')
 
74
        wt.add('bye.c')
 
75
        wt.commit('Test message')
71
76
 
72
77
        tof = StringIO()
73
78
        revs =[]
82
87
                           '  hello.c\n'])
83
88
 
84
89
        self.build_tree(['more.c'])
85
 
        b.add('more.c')
86
 
        b.commit('Another test message')
 
90
        wt.add('more.c')
 
91
        wt.commit('Another test message')
87
92
        
88
93
        tof = StringIO()
89
94
        revs.append(RevisionSpec(1))
97
102
                           '  hello.c\n'])
98
103
 
99
104
    def status_string(self, branch):
100
 
        tof = StringIO()
 
105
        # use a real file rather than StringIO because it doesn't handle
 
106
        # Unicode very well.
 
107
        tof = codecs.getwriter('utf-8')(TemporaryFile())
101
108
        show_status(branch, to_file=tof)
102
109
        tof.seek(0)
103
 
        return tof.getvalue()
 
110
        return tof.read().decode('utf-8')
104
111
 
105
112
    def test_pending(self):
106
 
        """Pending merges display works"""
 
113
        """Pending merges display works, including Unicode"""
107
114
        mkdir("./branch")
108
 
        b = Branch.initialize('./branch')
109
 
        b.commit("Empty commit 1")
110
 
        b_2 = copy_branch(b, './copy')
111
 
        b.commit("Empty commit 2")
112
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
113
 
        message = self.status_string(b_2)
114
 
        assert (message.startswith("pending merges:\n")), message
115
 
        assert (message.endswith("Empty commit 2\n")), message 
116
 
        b_2.commit("merged")
117
 
        b.commit("Empty commit 3 blah blah blah blah blah blah blah blah blah")
118
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
119
 
        message = self.status_string(b_2)
120
 
        assert (message.startswith("pending merges:\n")), message
121
 
        assert ("Empty commit 3" in message), message
122
 
        assert (message.endswith("...\n")), message 
 
115
        wt = WorkingTree.create_standalone('branch')
 
116
        b = wt.branch
 
117
        wt.commit("Empty commit 1")
 
118
        b_2 = b.clone('./copy')
 
119
        wt2 = WorkingTree('copy', b_2)
 
120
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
 
121
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
122
        message = self.status_string(b_2)
 
123
        self.assert_(message.startswith("pending merges:\n"))
 
124
        self.assert_(message.endswith("Empty commit 2\n")) 
 
125
        wt2.commit("merged")
 
126
        # must be long to make sure we see elipsis at the end
 
127
        wt.commit("Empty commit 3 " + 
 
128
                   "blah blah blah blah " * 10)
 
129
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
130
        message = self.status_string(b_2)
 
131
        self.assert_(message.startswith("pending merges:\n"))
 
132
        self.assert_("Empty commit 3" in message)
 
133
        self.assert_(message.endswith("...\n")) 
123
134
 
124
135
    def test_branch_status_specific_files(self): 
125
136
        """Tests branch status with given specific files"""
126
 
        from cStringIO import StringIO
127
 
        from bzrlib.status import show_status
128
 
        from bzrlib.branch import Branch
129
 
        
130
 
        b = Branch.initialize('.')
 
137
        wt = WorkingTree.create_standalone('.')
 
138
        b = wt.branch
131
139
 
132
140
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
133
 
        b.add('directory')
134
 
        b.add('test.c')
135
 
        b.commit('testing')
 
141
        wt.add('directory')
 
142
        wt.add('test.c')
 
143
        wt.commit('testing')
136
144
        
137
145
        tof = StringIO()
138
146
        show_status(b, to_file=tof)