~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 2010, 2011, 2016 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Black-box tests for bzr revert."""
18
18
 
19
19
import os
20
20
 
21
21
import bzrlib.osutils
22
 
from bzrlib.tests.blackbox import ExternalBase
 
22
from bzrlib.tests import TestCaseWithTransport
23
23
from bzrlib.trace import mutter
24
24
from bzrlib.workingtree import WorkingTree
25
25
 
26
26
 
27
 
class TestRevert(ExternalBase):
 
27
class TestRevert(TestCaseWithTransport):
28
28
 
29
29
    def _prepare_tree(self):
30
30
        self.run_bzr('init')
43
43
        f.close()
44
44
 
45
45
        # check status
46
 
        self.assertEquals('modified:\n  dir/file\n', self.run_bzr('status')[0])
 
46
        self.assertEqual('modified:\n  dir/file\n', self.run_bzr('status')[0])
47
47
 
48
48
    def _prepare_rename_mod_tree(self):
49
 
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g', 
 
49
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d/', 'a/d/e', 'f/', 'f/g',
50
50
                         'f/h', 'f/i'])
51
51
        self.run_bzr('init')
52
52
        self.run_bzr('add')
66
66
        os.chdir('dir')
67
67
        mutter('cd dir\n')
68
68
 
69
 
        self.assertEquals('1\n', self.run_bzr('revno')[0])
 
69
        self.assertEqual('1\n', self.run_bzr('revno')[0])
70
70
        self.run_bzr('revert %s file' % param)
71
 
        self.assertEquals('spam', open('file', 'rb').read())
 
71
        self.assertEqual('spam', open('file', 'rb').read())
72
72
 
73
73
    def test_revert_in_subdir(self):
74
74
        self.helper()
93
93
        """Test that revert DIRECTORY does what's expected"""
94
94
        self._prepare_rename_mod_tree()
95
95
        self.run_bzr('revert a')
96
 
        self.failUnlessExists('a/b')
97
 
        self.failUnlessExists('a/d')
98
 
        self.failIfExists('a/g')
99
 
        self.failUnlessExists('j')
100
 
        self.failUnlessExists('h')
 
96
        self.assertPathExists('a/b')
 
97
        self.assertPathExists('a/d')
 
98
        self.assertPathDoesNotExist('a/g')
 
99
        self.expectFailure(
 
100
            "j is in the delta revert applies because j was renamed too",
 
101
            self.assertPathExists, 'j')
 
102
        self.assertPathExists('h')
101
103
        self.run_bzr('revert f')
102
 
        self.failIfExists('j')
103
 
        self.failIfExists('h')
104
 
        self.failUnlessExists('a/d/e')
 
104
        self.assertPathDoesNotExist('j')
 
105
        self.assertPathDoesNotExist('h')
 
106
        self.assertPathExists('a/d/e')
105
107
 
106
108
    def test_revert_chatter(self):
107
109
        self._prepare_rename_mod_tree()
118
120
    def test_revert(self):
119
121
        self.run_bzr('init')
120
122
 
121
 
        file('hello', 'wt').write('foo')
 
123
        with file('hello', 'wt') as f: f.write('foo')
122
124
        self.run_bzr('add hello')
123
125
        self.run_bzr('commit -m setup hello')
124
126
 
125
 
        file('goodbye', 'wt').write('baz')
 
127
        with file('goodbye', 'wt') as f: f.write('baz')
126
128
        self.run_bzr('add goodbye')
127
129
        self.run_bzr('commit -m setup goodbye')
128
130
 
129
 
        file('hello', 'wt').write('bar')
130
 
        file('goodbye', 'wt').write('qux')
 
131
        with file('hello', 'wt') as f: f.write('bar')
 
132
        with file('goodbye', 'wt') as f: f.write('qux')
131
133
        self.run_bzr('revert hello')
132
134
        self.check_file_contents('hello', 'foo')
133
135
        self.check_file_contents('goodbye', 'qux')
146
148
            self.run_bzr('commit -m f')
147
149
            os.unlink('symlink')
148
150
            self.run_bzr('revert')
149
 
            self.failUnlessExists('symlink')
 
151
            self.assertPathExists('symlink')
150
152
            os.unlink('symlink')
151
153
            os.symlink('a-different-path', 'symlink')
152
154
            self.run_bzr('revert')
154
156
                             os.readlink('symlink'))
155
157
        else:
156
158
            self.log("skipping revert symlink tests")
157
 
        
158
 
        file('hello', 'wt').write('xyz')
 
159
 
 
160
        with file('hello', 'wt') as f: f.write('xyz')
159
161
        self.run_bzr('commit -m xyz hello')
160
162
        self.run_bzr('revert -r 1 hello')
161
163
        self.check_file_contents('hello', 'foo')
197
199
        first_rev_id = tree.commit('initial commit')
198
200
        self.build_tree_contents([('file', 'new content')])
199
201
        existing_parents = tree.get_parent_ids()
200
 
        self.assertEquals([first_rev_id], existing_parents)
 
202
        self.assertEqual([first_rev_id], existing_parents)
201
203
        merged_parents = existing_parents + ['merged-in-rev']
202
204
        tree.set_parent_ids(merged_parents)
203
 
        self.assertEquals(merged_parents, tree.get_parent_ids())
 
205
        self.assertEqual(merged_parents, tree.get_parent_ids())
204
206
        self.run_bzr(['revert', '--forget-merges'])
205
 
        self.assertEquals([first_rev_id], tree.get_parent_ids())
 
207
        self.assertEqual([first_rev_id], tree.get_parent_ids())
206
208
        # changed files are not reverted
207
209
        self.assertFileEqual('new content', 'file')
208
210
        # you can give it the path of a tree