/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 bzrlib/tests/blackbox/test_revert.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-02 03:58:58 UTC
  • mto: (1711.4.39 win32-accepted)
  • mto: This revision was merged to the branch mainline in revision 1836.
  • Revision ID: john@arbash-meinel.com-20060702035858-414b2de9dec7519a
Factor out i18n bundle tests, so we don't always skip.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
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
 
16
 
 
17
"""Black-box tests for bzr revert."""
 
18
 
 
19
import os
 
20
 
 
21
import bzrlib.osutils
 
22
from bzrlib.tests.blackbox import ExternalBase
 
23
from bzrlib.trace import mutter
 
24
 
 
25
 
 
26
class TestRevert(ExternalBase):
 
27
 
 
28
    def _prepare_tree(self):
 
29
        self.runbzr('init')
 
30
        self.runbzr('mkdir dir')
 
31
 
 
32
        f = file('dir/file', 'wb')
 
33
        f.write('spam')
 
34
        f.close()
 
35
        self.runbzr('add dir/file')
 
36
 
 
37
        self.runbzr('commit -m1')
 
38
 
 
39
        # modify file
 
40
        f = file('dir/file', 'wb')
 
41
        f.write('eggs')
 
42
        f.close()
 
43
 
 
44
        # check status
 
45
        self.assertEquals('modified:\n  dir/file\n', self.capture('status'))
 
46
 
 
47
    def helper(self, param=''):
 
48
        self._prepare_tree()
 
49
        # change dir
 
50
        # revert to default revision for file in subdir does work
 
51
        os.chdir('dir')
 
52
        mutter('cd dir\n')
 
53
 
 
54
        self.assertEquals('1\n', self.capture('revno'))
 
55
        self.runbzr('revert %s file' % param)
 
56
        self.assertEquals('spam', open('file', 'rb').read())
 
57
 
 
58
    def test_revert_in_subdir(self):
 
59
        self.helper()
 
60
 
 
61
    def test_revert_to_revision_in_subdir(self):
 
62
        # test case for bug #29424:
 
63
        # revert to specific revision for file in subdir does not work
 
64
        self.helper('-r 1')
 
65
 
 
66
    def test_revert_in_checkout(self):
 
67
        os.mkdir('brach')
 
68
        os.chdir('brach')
 
69
        self._prepare_tree()
 
70
        self.runbzr('checkout --lightweight . ../sprach')
 
71
        self.runbzr('commit -m more')
 
72
        os.chdir('../sprach')
 
73
        self.assertEqual('', self.capture('status'))
 
74
        self.runbzr('revert')
 
75
        self.assertEqual('', self.capture('status'))
 
76
 
 
77
    def test_revert(self):
 
78
        self.run_bzr('init')
 
79
 
 
80
        file('hello', 'wt').write('foo')
 
81
        self.run_bzr('add', 'hello')
 
82
        self.run_bzr('commit', '-m', 'setup', 'hello')
 
83
 
 
84
        file('goodbye', 'wt').write('baz')
 
85
        self.run_bzr('add', 'goodbye')
 
86
        self.run_bzr('commit', '-m', 'setup', 'goodbye')
 
87
 
 
88
        file('hello', 'wt').write('bar')
 
89
        file('goodbye', 'wt').write('qux')
 
90
        self.run_bzr('revert', 'hello')
 
91
        self.check_file_contents('hello', 'foo')
 
92
        self.check_file_contents('goodbye', 'qux')
 
93
        self.run_bzr('revert')
 
94
        self.check_file_contents('goodbye', 'baz')
 
95
 
 
96
        os.mkdir('revertdir')
 
97
        self.run_bzr('add', 'revertdir')
 
98
        self.run_bzr('commit', '-m', 'f')
 
99
        os.rmdir('revertdir')
 
100
        self.run_bzr('revert')
 
101
 
 
102
        if bzrlib.osutils.has_symlinks():
 
103
            os.symlink('/unlikely/to/exist', 'symlink')
 
104
            self.run_bzr('add', 'symlink')
 
105
            self.run_bzr('commit', '-m', 'f')
 
106
            os.unlink('symlink')
 
107
            self.run_bzr('revert')
 
108
            self.failUnlessExists('symlink')
 
109
            os.unlink('symlink')
 
110
            os.symlink('a-different-path', 'symlink')
 
111
            self.run_bzr('revert')
 
112
            self.assertEqual('/unlikely/to/exist',
 
113
                             os.readlink('symlink'))
 
114
        else:
 
115
            self.log("skipping revert symlink tests")
 
116
        
 
117
        file('hello', 'wt').write('xyz')
 
118
        self.run_bzr('commit', '-m', 'xyz', 'hello')
 
119
        self.run_bzr('revert', '-r', '1', 'hello')
 
120
        self.check_file_contents('hello', 'foo')
 
121
        self.run_bzr('revert', 'hello')
 
122
        self.check_file_contents('hello', 'xyz')
 
123
        os.chdir('revertdir')
 
124
        self.run_bzr('revert')
 
125
        os.chdir('..')
 
126