~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2007-04-12 21:33:07 UTC
  • mfrom: (2413.4.1 api-doc-builders)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070412213307-kuh07cnzaud12wx1
[merge] api-doc-builder and remove the pydoctor build code for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Tests of simple versioning operations"""
22
22
 
23
23
import os
24
24
 
 
25
from bzrlib.tests import BzrTestBase, TestCaseInTempDir
25
26
from bzrlib.branch import Branch
 
27
from bzrlib.trace import mutter
26
28
from bzrlib.osutils import pathjoin
27
 
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
28
 
from bzrlib.trace import mutter
29
29
from bzrlib.workingtree import WorkingTree
30
30
 
31
31
 
32
32
class TestVersioning(TestCaseInTempDir):
33
 
 
34
 
    def test_mkdir(self):
 
33
    
 
34
    def test_mkdir(self): 
35
35
        """Basic 'bzr mkdir' operation"""
36
36
 
37
37
        self.run_bzr('init')
38
 
        self.run_bzr('mkdir foo')
 
38
        self.run_bzr('mkdir', 'foo')
39
39
        self.assert_(os.path.isdir('foo'))
40
40
 
41
 
        self.run_bzr('mkdir foo', retcode=3)
 
41
        self.run_bzr('mkdir', 'foo', retcode=3)
42
42
 
43
43
        wt = WorkingTree.open('.')
44
 
 
 
44
        
45
45
        delta = wt.changes_from(wt.basis_tree())
46
46
 
47
47
        self.log('delta.added = %r' % delta.added)
54
54
        """'bzr mkdir' operation in subdirectory"""
55
55
 
56
56
        self.run_bzr('init')
57
 
        self.run_bzr('mkdir dir')
 
57
        self.run_bzr('mkdir', 'dir')
58
58
        self.assert_(os.path.isdir('dir'))
59
59
 
60
60
        os.chdir('dir')
61
61
        self.log('Run mkdir in subdir')
62
 
        self.run_bzr('mkdir subdir')
 
62
        self.run_bzr('mkdir', 'subdir')
63
63
        self.assert_(os.path.isdir('subdir'))
64
64
        os.chdir('..')
65
65
 
66
66
        wt = WorkingTree.open('.')
67
 
 
 
67
        
68
68
        delta = wt.changes_from(wt.basis_tree())
69
69
 
70
70
        self.log('delta.added = %r' % delta.added)
86
86
        self.run_bzr('init')
87
87
        os.chdir('../..')
88
88
 
89
 
        self.run_bzr('mkdir dir a/dir a/b/dir')
 
89
        self.run_bzr('mkdir', 'dir', 'a/dir', 'a/b/dir')
90
90
        self.failUnless(os.path.isdir('dir'))
91
91
        self.failUnless(os.path.isdir('a/dir'))
92
92
        self.failUnless(os.path.isdir('a/b/dir'))
94
94
        wt = WorkingTree.open('.')
95
95
        wt_a = WorkingTree.open('a')
96
96
        wt_b = WorkingTree.open('a/b')
97
 
 
 
97
        
98
98
        delta = wt.changes_from(wt.basis_tree())
99
99
        self.assertEquals(len(delta.added), 1)
100
100
        self.assertEquals(delta.added[0][0], 'dir')
116
116
        The upgrade should be a no-op."""
117
117
        b = Branch.open(u'.')
118
118
        mutter('branch has %d revisions', b.revno())
119
 
 
 
119
        
120
120
        mutter('check branch...')
121
121
        from bzrlib.check import check
122
122
        check(b, False)
123
123
 
124
124
 
125
 
class SubdirCommit(TestCaseWithTransport):
 
125
class SubdirCommit(TestCaseInTempDir):
126
126
 
127
127
    def test_subdir_commit(self):
128
 
        """Test committing a subdirectory, and committing a directory."""
129
 
        tree = self.make_branch_and_tree('.')
130
 
        b = tree.branch
 
128
        """Test committing a subdirectory, and committing within a directory."""
 
129
        run_bzr = self.run_bzr
 
130
        eq = self.assertEqual
 
131
 
131
132
        self.build_tree(['a/', 'b/'])
132
 
        def set_contents(contents):
133
 
            self.build_tree_contents([
134
 
                ('a/one', contents),
135
 
                ('b/two', contents),
136
 
                ('top', contents),
137
 
                ])
138
 
        set_contents('old contents')
139
 
        tree.smart_add(['.'])
140
 
        tree.commit('first revision')
141
 
        set_contents('new contents')
142
 
 
 
133
        
 
134
        run_bzr('init')
 
135
        b = Branch.open(u'.')
 
136
        
 
137
        for fn in ('a/one', 'b/two', 'top'):
 
138
            file(fn, 'w').write('old contents')
 
139
            
 
140
        run_bzr('add')
 
141
        run_bzr('commit', '-m', 'first revision')
 
142
        
 
143
        for fn in ('a/one', 'b/two', 'top'):
 
144
            file(fn, 'w').write('new contents')
 
145
            
143
146
        mutter('start selective subdir commit')
144
 
        self.run_bzr(['commit', 'a', '-m', 'commit a only'])
145
 
 
 
147
        run_bzr('commit', 'a', '-m', 'commit a only')
 
148
        
 
149
        old = b.repository.revision_tree(b.get_rev_id(1))
146
150
        new = b.repository.revision_tree(b.get_rev_id(2))
147
 
        new.lock_read()
148
 
 
149
 
        self.assertEqual(new.get_file_by_path('b/two').read(), 'old contents')
150
 
        self.assertEqual(new.get_file_by_path('top').read(), 'old contents')
151
 
        self.assertEqual(new.get_file_by_path('a/one').read(), 'new contents')
152
 
        new.unlock()
153
 
 
 
151
        
 
152
        eq(new.get_file_by_path('b/two').read(), 'old contents')
 
153
        eq(new.get_file_by_path('top').read(), 'old contents')
 
154
        eq(new.get_file_by_path('a/one').read(), 'new contents')
 
155
        
154
156
        os.chdir('a')
155
157
        # commit from here should do nothing
156
 
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
 
158
        run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged')
157
159
        v3 = b.repository.revision_tree(b.get_rev_id(3))
158
 
        v3.lock_read()
159
 
        self.assertEqual(v3.get_file_by_path('b/two').read(), 'old contents')
160
 
        self.assertEqual(v3.get_file_by_path('top').read(), 'old contents')
161
 
        self.assertEqual(v3.get_file_by_path('a/one').read(), 'new contents')
162
 
        v3.unlock()
163
 
 
 
160
        eq(v3.get_file_by_path('b/two').read(), 'old contents')
 
161
        eq(v3.get_file_by_path('top').read(), 'old contents')
 
162
        eq(v3.get_file_by_path('a/one').read(), 'new contents')
 
163
                
164
164
        # commit in subdirectory commits whole tree
165
 
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
 
165
        run_bzr('commit', '-m', 'commit whole tree from subdir')
166
166
        v4 = b.repository.revision_tree(b.get_rev_id(4))
167
 
        v4.lock_read()
168
 
        self.assertEqual(v4.get_file_by_path('b/two').read(), 'new contents')
169
 
        self.assertEqual(v4.get_file_by_path('top').read(), 'new contents')
170
 
        v4.unlock()
171
 
 
 
167
        eq(v4.get_file_by_path('b/two').read(), 'new contents')        
 
168
        eq(v4.get_file_by_path('top').read(), 'new contents')
 
169
        
172
170
        # TODO: factor out some kind of assert_tree_state() method
 
171
        
 
172
 
 
173
if __name__ == '__main__':
 
174
    import unittest
 
175
    unittest.main()
 
176