~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
31
 
from bzrlib import bzrdir, errors, ignores
 
31
from bzrlib import bzrdir, errors
32
32
import bzrlib.branch
33
33
from bzrlib.builtins import merge
34
34
from bzrlib.osutils import pathjoin
40
40
 
41
41
class BranchStatus(TestCaseWithTransport):
42
42
    
 
43
    def assertStatus(self, output_lines, working_tree,
 
44
        revision=None):
 
45
        """Run status in working_tree and look for output.
 
46
        
 
47
        :param output_lines: The lines to look for.
 
48
        :param working_tree: The tree to run status in.
 
49
        """
 
50
        output_string = self.status_string(working_tree, revision)
 
51
        self.assertEqual(output_lines, output_string.splitlines(True))
 
52
    
 
53
    def status_string(self, wt, revision=None):
 
54
        # use a real file rather than StringIO because it doesn't handle
 
55
        # Unicode very well.
 
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
 
57
        show_tree_status(wt, to_file=tof, revision=revision)
 
58
        tof.seek(0)
 
59
        return tof.read().decode('utf-8')
 
60
 
43
61
    def test_branch_status(self):
44
62
        """Test basic branch status"""
45
63
        wt = self.make_branch_and_tree('.')
46
 
        b = wt.branch
47
 
 
48
 
        ignores._set_user_ignores(['./.bazaar'])
49
 
 
50
 
        # status with nothing
51
 
        tof = StringIO()
52
 
        show_tree_status(wt, to_file=tof)
53
 
        self.assertEquals(tof.getvalue(), "")
54
 
 
55
 
        tof = StringIO()
 
64
 
 
65
        # status with no commits or files - it must
 
66
        # work and show no output. We do this with no
 
67
        # commits to be sure that it's not going to fail
 
68
        # as a corner case.
 
69
        self.assertStatus([], wt)
 
70
 
56
71
        self.build_tree(['hello.c', 'bye.c'])
57
 
        wt.add_pending_merge('pending@pending-0-0')
58
 
        show_tree_status(wt, to_file=tof)
59
 
        tof.seek(0)
60
 
        self.assertEquals(tof.readlines(),
61
 
                          ['unknown:\n',
62
 
                           '  bye.c\n',
63
 
                           '  hello.c\n',
64
 
                           'pending merges:\n',
65
 
                           '  pending@pending-0-0\n'
66
 
                           ])
 
72
        self.assertStatus([
 
73
                'unknown:\n',
 
74
                '  bye.c\n',
 
75
                '  hello.c\n',
 
76
            ],
 
77
            wt)
 
78
 
 
79
        # add a commit to allow showing pending merges.
 
80
        wt.commit('create a parent to allow testing merge output')
 
81
 
 
82
        wt.add_parent_tree_id('pending@pending-0-0')
 
83
        self.assertStatus([
 
84
                'unknown:\n',
 
85
                '  bye.c\n',
 
86
                '  hello.c\n',
 
87
                'pending merges:\n',
 
88
                '  pending@pending-0-0\n',
 
89
            ],
 
90
            wt)
67
91
 
68
92
    def test_branch_status_revisions(self):
69
93
        """Tests branch status with revisions"""
70
94
        wt = self.make_branch_and_tree('.')
71
 
        b = wt.branch
72
 
 
73
 
        ignores._set_user_ignores(['./.bazaar'])
74
 
 
75
 
        tof = StringIO()
 
95
 
76
96
        self.build_tree(['hello.c', 'bye.c'])
77
97
        wt.add('hello.c')
78
98
        wt.add('bye.c')
79
99
        wt.commit('Test message')
80
100
 
81
 
        tof = StringIO()
82
 
        revs =[]
83
 
        revs.append(RevisionSpec(0))
84
 
        
85
 
        show_tree_status(wt, to_file=tof, revision=revs)
86
 
        
87
 
        tof.seek(0)
88
 
        self.assertEquals(tof.readlines(),
89
 
                          ['added:\n',
90
 
                           '  bye.c\n',
91
 
                           '  hello.c\n'])
 
101
        revs = [RevisionSpec.from_string('0')]
 
102
        self.assertStatus([
 
103
                'added:\n',
 
104
                '  bye.c\n',
 
105
                '  hello.c\n'
 
106
            ],
 
107
            wt,
 
108
            revision=revs)
92
109
 
93
110
        self.build_tree(['more.c'])
94
111
        wt.add('more.c')
95
112
        wt.commit('Another test message')
96
113
        
97
 
        tof = StringIO()
98
 
        revs.append(RevisionSpec(1))
99
 
        
100
 
        show_tree_status(wt, to_file=tof, revision=revs)
101
 
        
102
 
        tof.seek(0)
103
 
        self.assertEquals(tof.readlines(),
104
 
                          ['added:\n',
105
 
                           '  bye.c\n',
106
 
                           '  hello.c\n'])
107
 
 
108
 
    def status_string(self, wt):
109
 
        # use a real file rather than StringIO because it doesn't handle
110
 
        # Unicode very well.
111
 
        tof = codecs.getwriter('utf-8')(TemporaryFile())
112
 
        show_tree_status(wt, to_file=tof)
113
 
        tof.seek(0)
114
 
        return tof.read().decode('utf-8')
 
114
        revs.append(RevisionSpec.from_string('1'))
 
115
        self.assertStatus([
 
116
                'added:\n',
 
117
                '  bye.c\n',
 
118
                '  hello.c\n',
 
119
            ],
 
120
            wt,
 
121
            revision=revs)
115
122
 
116
123
    def test_pending(self):
117
124
        """Pending merges display works, including Unicode"""
142
149
        wt = self.make_branch_and_tree('.')
143
150
        b = wt.branch
144
151
 
145
 
        ignores._set_user_ignores(['./.bazaar'])
146
 
 
147
152
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
148
153
        wt.add('directory')
149
154
        wt.add('test.c')
186
191
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
187
192
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
188
193
 
 
194
    def test_status_out_of_date(self):
 
195
        """Simulate status of out-of-date tree after remote push"""
 
196
        tree = self.make_branch_and_tree('.')
 
197
        self.build_tree_contents([('a', 'foo\n')])
 
198
        tree.lock_write()
 
199
        try:
 
200
            tree.add(['a'])
 
201
            tree.commit('add test file')
 
202
            # simulate what happens after a remote push
 
203
            tree.set_last_revision("0")
 
204
            out, err = self.run_bzr('status')
 
205
            self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
206
                             err)
 
207
        finally:
 
208
            tree.unlock()
 
209
 
189
210
 
190
211
class CheckoutStatus(BranchStatus):
191
212
 
204
225
class TestStatus(TestCaseWithTransport):
205
226
 
206
227
    def test_status(self):
207
 
        ignores._set_user_ignores(['./.bazaar'])
208
 
 
209
228
        self.run_bzr("init")
210
229
        self.build_tree(['hello.txt'])
211
230
        result = self.run_bzr("status")[0]