/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Black-box tests for brz revert."""
 
17
"""Black-box tests for bzr revert."""
18
18
 
19
19
import os
20
20
 
21
 
import breezy.osutils
22
 
from breezy.tests import TestCaseWithTransport
23
 
from breezy.trace import mutter
24
 
from breezy.workingtree import WorkingTree
 
21
import brzlib.osutils
 
22
from brzlib.tests import TestCaseWithTransport
 
23
from brzlib.trace import mutter
 
24
from brzlib.workingtree import WorkingTree
25
25
 
26
26
 
27
27
class TestRevert(TestCaseWithTransport):
30
30
        self.run_bzr('init')
31
31
        self.run_bzr('mkdir dir')
32
32
 
33
 
        with open('dir/file', 'wb') as f:
34
 
            f.write(b'spam')
 
33
        f = file('dir/file', 'wb')
 
34
        f.write('spam')
 
35
        f.close()
35
36
        self.run_bzr('add dir/file')
36
37
 
37
38
        self.run_bzr('commit -m1')
38
39
 
39
40
        # modify file
40
 
        with open('dir/file', 'wb') as f:
41
 
            f.write(b'eggs')
 
41
        f = file('dir/file', 'wb')
 
42
        f.write('eggs')
 
43
        f.close()
42
44
 
43
45
        # check status
44
46
        self.assertEqual('modified:\n  dir/file\n', self.run_bzr('status')[0])
66
68
 
67
69
        self.assertEqual('1\n', self.run_bzr('revno')[0])
68
70
        self.run_bzr('revert %s file' % param)
69
 
        with open('file', 'rb') as f:
70
 
            self.assertEqual(b'spam', f.read())
 
71
        self.assertEqual('spam', open('file', 'rb').read())
71
72
 
72
73
    def test_revert_in_subdir(self):
73
74
        self.helper()
119
120
    def test_revert(self):
120
121
        self.run_bzr('init')
121
122
 
122
 
        with open('hello', 'wt') as f:
123
 
            f.write('foo')
 
123
        with file('hello', 'wt') as f: f.write('foo')
124
124
        self.run_bzr('add hello')
125
125
        self.run_bzr('commit -m setup hello')
126
126
 
127
 
        with open('goodbye', 'wt') as f:
128
 
            f.write('baz')
 
127
        with file('goodbye', 'wt') as f: f.write('baz')
129
128
        self.run_bzr('add goodbye')
130
129
        self.run_bzr('commit -m setup goodbye')
131
130
 
132
 
        with open('hello', 'wt') as f:
133
 
            f.write('bar')
134
 
        with open('goodbye', 'wt') as f:
135
 
            f.write('qux')
 
131
        with file('hello', 'wt') as f: f.write('bar')
 
132
        with file('goodbye', 'wt') as f: f.write('qux')
136
133
        self.run_bzr('revert hello')
137
 
        self.check_file_contents('hello', b'foo')
138
 
        self.check_file_contents('goodbye', b'qux')
 
134
        self.check_file_contents('hello', 'foo')
 
135
        self.check_file_contents('goodbye', 'qux')
139
136
        self.run_bzr('revert')
140
 
        self.check_file_contents('goodbye', b'baz')
 
137
        self.check_file_contents('goodbye', 'baz')
141
138
 
142
139
        os.mkdir('revertdir')
143
140
        self.run_bzr('add revertdir')
145
142
        os.rmdir('revertdir')
146
143
        self.run_bzr('revert')
147
144
 
148
 
        if breezy.osutils.has_symlinks():
 
145
        if brzlib.osutils.has_symlinks():
149
146
            os.symlink('/unlikely/to/exist', 'symlink')
150
147
            self.run_bzr('add symlink')
151
148
            self.run_bzr('commit -m f')
160
157
        else:
161
158
            self.log("skipping revert symlink tests")
162
159
 
163
 
        with open('hello', 'wt') as f:
164
 
            f.write('xyz')
 
160
        with file('hello', 'wt') as f: f.write('xyz')
165
161
        self.run_bzr('commit -m xyz hello')
166
162
        self.run_bzr('revert -r 1 hello')
167
 
        self.check_file_contents('hello', b'foo')
 
163
        self.check_file_contents('hello', 'foo')
168
164
        self.run_bzr('revert hello')
169
 
        self.check_file_contents('hello', b'xyz')
 
165
        self.check_file_contents('hello', 'xyz')
170
166
        os.chdir('revertdir')
171
167
        self.run_bzr('revert')
172
168
        os.chdir('..')
201
197
        self.run_bzr(['revert', '--forget-merges'])
202
198
        self.build_tree(['file'])
203
199
        first_rev_id = tree.commit('initial commit')
204
 
        self.build_tree_contents([('file', b'new content')])
 
200
        self.build_tree_contents([('file', 'new content')])
205
201
        existing_parents = tree.get_parent_ids()
206
202
        self.assertEqual([first_rev_id], existing_parents)
207
 
        merged_parents = existing_parents + [b'merged-in-rev']
 
203
        merged_parents = existing_parents + ['merged-in-rev']
208
204
        tree.set_parent_ids(merged_parents)
209
205
        self.assertEqual(merged_parents, tree.get_parent_ids())
210
206
        self.run_bzr(['revert', '--forget-merges'])
211
207
        self.assertEqual([first_rev_id], tree.get_parent_ids())
212
208
        # changed files are not reverted
213
 
        self.assertFileEqual(b'new content', 'file')
 
209
        self.assertFileEqual('new content', 'file')
214
210
        # you can give it the path of a tree
215
211
        self.run_bzr(['revert', '--forget-merges', tree.abspath('.')])