~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/teststatus.py

  • Committer: Martin Pool
  • Date: 2005-07-22 22:36:54 UTC
  • Revision ID: mbp@sourcefrog.net-20050722223654-93bf9d8cc0f0c128
todo

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""
22
22
 
23
23
 
24
 
from bzrlib.selftest import TestCaseInTempDir
25
 
from bzrlib.revisionspec import RevisionSpec
26
 
from bzrlib.merge import merge
27
 
from cStringIO import StringIO
28
 
from bzrlib.status import show_status
29
 
from bzrlib.branch import Branch
30
 
from os import mkdir
31
 
from bzrlib.clone import copy_branch
 
24
from bzrlib.selftest import InTempDir
32
25
 
33
 
class BranchStatus(TestCaseInTempDir):
34
 
    
35
 
    def test_branch_status(self): 
36
 
        """Test basic branch status"""
 
26
class BranchStatus(InTempDir):
 
27
    def runTest(self): 
 
28
        """Basic 'bzr mkdir' operation"""
37
29
        from cStringIO import StringIO
38
30
        from bzrlib.status import show_status
39
31
        from bzrlib.branch import Branch
40
32
        
41
 
        b = Branch.initialize('.')
 
33
        b = Branch('.', init=True)
42
34
 
43
35
        # status with nothing
44
36
        tof = StringIO()
47
39
 
48
40
        tof = StringIO()
49
41
        self.build_tree(['hello.c', 'bye.c'])
50
 
        b.add_pending_merge('pending@pending-0-0')
51
42
        show_status(b, to_file=tof)
52
43
        tof.seek(0)
53
44
        self.assertEquals(tof.readlines(),
54
45
                          ['unknown:\n',
55
46
                           '  bye.c\n',
56
47
                           '  hello.c\n',
57
 
                           'pending merges:\n',
58
 
                           '  pending@pending-0-0\n'
59
 
                           ])
60
 
 
61
 
    def test_branch_status_revisions(self):
62
 
        """Tests branch status with revisions"""
63
 
        
64
 
        b = Branch.initialize('.')
65
 
 
66
 
        tof = StringIO()
67
 
        self.build_tree(['hello.c', 'bye.c'])
68
 
        b.add('hello.c')
69
 
        b.add('bye.c')
70
 
        b.commit('Test message')
71
 
 
72
 
        tof = StringIO()
73
 
        revs =[]
74
 
        revs.append(RevisionSpec(0))
75
 
        
76
 
        show_status(b, to_file=tof, revision=revs)
77
 
        
78
 
        tof.seek(0)
79
 
        self.assertEquals(tof.readlines(),
80
 
                          ['added:\n',
81
 
                           '  bye.c\n',
82
 
                           '  hello.c\n'])
83
 
 
84
 
        self.build_tree(['more.c'])
85
 
        b.add('more.c')
86
 
        b.commit('Another test message')
87
 
        
88
 
        tof = StringIO()
89
 
        revs.append(RevisionSpec(1))
90
 
        
91
 
        show_status(b, to_file=tof, revision=revs)
92
 
        
93
 
        tof.seek(0)
94
 
        self.assertEquals(tof.readlines(),
95
 
                          ['added:\n',
96
 
                           '  bye.c\n',
97
 
                           '  hello.c\n'])
98
 
 
99
 
    def status_string(self, branch):
100
 
        tof = StringIO()
101
 
        show_status(branch, to_file=tof)
102
 
        tof.seek(0)
103
 
        return tof.getvalue()
104
 
 
105
 
    def test_pending(self):
106
 
        """Pending merges display works"""
107
 
        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 
123
 
 
124
 
    def test_branch_status_specific_files(self): 
125
 
        """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('.')
131
 
 
132
 
        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')
136
 
        
137
 
        tof = StringIO()
138
 
        show_status(b, to_file=tof)
139
 
        tof.seek(0)
140
 
        self.assertEquals(tof.readlines(),
141
 
                          ['unknown:\n',
142
 
                           '  bye.c\n',
143
 
                           '  dir2\n',
144
 
                           '  directory/hello.c\n'
145
 
                           ])
146
 
 
147
 
        tof = StringIO()
148
 
        show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
149
 
        tof.seek(0)
150
 
        self.assertEquals(tof.readlines(),
151
 
                          ['unknown:\n',
152
 
                           '  bye.c\n'
153
 
                           ])
154
 
        
155
 
        tof = StringIO()
156
 
        show_status(b, specific_files=['directory'], to_file=tof)
157
 
        tof.seek(0)
158
 
        self.assertEquals(tof.readlines(),
159
 
                          ['unknown:\n',
160
 
                           '  directory/hello.c\n'
161
 
                           ])
162
 
        tof = StringIO()
163
 
        show_status(b, specific_files=['dir2'], to_file=tof)
164
 
        tof.seek(0)
165
 
        self.assertEquals(tof.readlines(),
166
 
                          ['unknown:\n',
167
 
                           '  dir2\n'
168
 
                           ])
 
48
                           ])
 
49