~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2009-08-14 15:35:31 UTC
  • mto: (4603.1.22 shelve-editor)
  • mto: This revision was merged to the branch mainline in revision 4795.
  • Revision ID: aaron@aaronbentley.com-20090814153531-t3t34s2obh05uga7
Simplify unchanged case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005 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
22
22
 
23
23
import os
24
24
 
 
25
from bzrlib.tests import 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
 
class TestMkdir(TestCaseWithTransport):
33
 
 
34
 
    def test_mkdir_fails_cleanly(self):
35
 
        """'mkdir' fails cleanly when no working tree is available.
36
 
        https://bugs.launchpad.net/bzr/+bug/138600
37
 
        """
38
 
        # Since there is a safety working tree above us, we create a bare repo
39
 
        # here locally.
40
 
        shared_repo = self.make_repository('.')
41
 
        self.run_bzr(['mkdir', 'abc'], retcode=3)
42
 
        self.assertPathDoesNotExist('abc')
 
32
class TestVersioning(TestCaseInTempDir):
43
33
 
44
34
    def test_mkdir(self):
45
35
        """Basic 'bzr mkdir' operation"""
46
36
 
47
 
        self.make_branch_and_tree('.')
48
 
        self.run_bzr(['mkdir', 'foo'])
 
37
        self.run_bzr('init')
 
38
        self.run_bzr('mkdir foo')
49
39
        self.assert_(os.path.isdir('foo'))
50
40
 
51
 
        self.run_bzr(['mkdir', 'foo'], retcode=3)
 
41
        self.run_bzr('mkdir foo', retcode=3)
52
42
 
53
43
        wt = WorkingTree.open('.')
54
44
 
58
48
 
59
49
        self.assertEquals(len(delta.added), 1)
60
50
        self.assertEquals(delta.added[0][0], 'foo')
61
 
        self.assertFalse(delta.modified)
 
51
        self.failIf(delta.modified)
62
52
 
63
53
    def test_mkdir_in_subdir(self):
64
54
        """'bzr mkdir' operation in subdirectory"""
65
55
 
66
 
        self.make_branch_and_tree('.')
67
 
        self.run_bzr(['mkdir', 'dir'])
 
56
        self.run_bzr('init')
 
57
        self.run_bzr('mkdir dir')
68
58
        self.assert_(os.path.isdir('dir'))
69
59
 
70
60
        os.chdir('dir')
71
61
        self.log('Run mkdir in subdir')
72
 
        self.run_bzr(['mkdir', 'subdir'])
 
62
        self.run_bzr('mkdir subdir')
73
63
        self.assert_(os.path.isdir('subdir'))
74
64
        os.chdir('..')
75
65
 
82
72
        self.assertEquals(len(delta.added), 2)
83
73
        self.assertEquals(delta.added[0][0], 'dir')
84
74
        self.assertEquals(delta.added[1][0], pathjoin('dir','subdir'))
85
 
        self.assertFalse(delta.modified)
 
75
        self.failIf(delta.modified)
86
76
 
87
77
    def test_mkdir_w_nested_trees(self):
88
78
        """'bzr mkdir' with nested trees"""
89
79
 
90
 
        self.make_branch_and_tree('.')
91
 
        self.make_branch_and_tree('a')
92
 
        self.make_branch_and_tree('a/b')
 
80
        self.run_bzr('init')
 
81
        os.mkdir('a')
 
82
        os.chdir('a')
 
83
        self.run_bzr('init')
 
84
        os.mkdir('b')
 
85
        os.chdir('b')
 
86
        self.run_bzr('init')
 
87
        os.chdir('../..')
93
88
 
94
 
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
95
 
        self.assertTrue(os.path.isdir('dir'))
96
 
        self.assertTrue(os.path.isdir('a/dir'))
97
 
        self.assertTrue(os.path.isdir('a/b/dir'))
 
89
        self.run_bzr('mkdir dir a/dir a/b/dir')
 
90
        self.failUnless(os.path.isdir('dir'))
 
91
        self.failUnless(os.path.isdir('a/dir'))
 
92
        self.failUnless(os.path.isdir('a/b/dir'))
98
93
 
99
94
        wt = WorkingTree.open('.')
100
95
        wt_a = WorkingTree.open('a')
103
98
        delta = wt.changes_from(wt.basis_tree())
104
99
        self.assertEquals(len(delta.added), 1)
105
100
        self.assertEquals(delta.added[0][0], 'dir')
106
 
        self.assertFalse(delta.modified)
 
101
        self.failIf(delta.modified)
107
102
 
108
103
        delta = wt_a.changes_from(wt_a.basis_tree())
109
104
        self.assertEquals(len(delta.added), 1)
110
105
        self.assertEquals(delta.added[0][0], 'dir')
111
 
        self.assertFalse(delta.modified)
 
106
        self.failIf(delta.modified)
112
107
 
113
108
        delta = wt_b.changes_from(wt_b.basis_tree())
114
109
        self.assertEquals(len(delta.added), 1)
115
110
        self.assertEquals(delta.added[0][0], 'dir')
116
 
        self.assertFalse(delta.modified)
117
 
 
118
 
    def test_mkdir_quiet(self):
119
 
        """'bzr mkdir --quiet' should not print a status message"""
120
 
 
121
 
        self.make_branch_and_tree('.')
122
 
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
123
 
        self.assertEquals('', err)
124
 
        self.assertEquals('', out)
125
 
 
126
 
 
127
 
class SubdirCommit(TestCaseWithTransport):
 
111
        self.failIf(delta.modified)
 
112
 
 
113
    def check_branch(self):
 
114
        """After all the above changes, run the check and upgrade commands.
 
115
 
 
116
        The upgrade should be a no-op."""
 
117
        b = Branch.open(u'.')
 
118
        mutter('branch has %d revisions', b.revno())
 
119
 
 
120
        mutter('check branch...')
 
121
        from bzrlib.check import check
 
122
        check(b, False)
 
123
 
 
124
 
 
125
class SubdirCommit(TestCaseInTempDir):
128
126
 
129
127
    def test_subdir_commit(self):
130
 
        """Test committing a subdirectory, and committing a directory."""
131
 
        tree = self.make_branch_and_tree('.')
132
 
        b = tree.branch
 
128
        """Test committing a subdirectory, and committing within a directory."""
 
129
        run_bzr = self.run_bzr
 
130
        eq = self.assertEqual
 
131
 
133
132
        self.build_tree(['a/', 'b/'])
134
 
        def set_contents(contents):
135
 
            self.build_tree_contents([
136
 
                ('a/one', contents),
137
 
                ('b/two', contents),
138
 
                ('top', contents),
139
 
                ])
140
 
        set_contents('old contents')
141
 
        tree.smart_add(['.'])
142
 
        tree.commit('first revision')
143
 
        set_contents('new contents')
 
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')
144
145
 
145
146
        mutter('start selective subdir commit')
146
 
        self.run_bzr(['commit', 'a', '-m', 'commit a only'])
 
147
        run_bzr(['commit', 'a', '-m', 'commit a only'])
147
148
 
 
149
        old = b.repository.revision_tree(b.get_rev_id(1))
148
150
        new = b.repository.revision_tree(b.get_rev_id(2))
149
151
        new.lock_read()
150
152
 
151
 
        self.assertEqual(new.get_file_by_path('b/two').read(), 'old contents')
152
 
        self.assertEqual(new.get_file_by_path('top').read(), 'old contents')
153
 
        self.assertEqual(new.get_file_by_path('a/one').read(), 'new contents')
 
153
        eq(new.get_file_by_path('b/two').read(), 'old contents')
 
154
        eq(new.get_file_by_path('top').read(), 'old contents')
 
155
        eq(new.get_file_by_path('a/one').read(), 'new contents')
154
156
        new.unlock()
155
157
 
156
158
        os.chdir('a')
157
159
        # commit from here should do nothing
158
 
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
 
160
        run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
159
161
        v3 = b.repository.revision_tree(b.get_rev_id(3))
160
162
        v3.lock_read()
161
 
        self.assertEqual(v3.get_file_by_path('b/two').read(), 'old contents')
162
 
        self.assertEqual(v3.get_file_by_path('top').read(), 'old contents')
163
 
        self.assertEqual(v3.get_file_by_path('a/one').read(), 'new contents')
 
163
        eq(v3.get_file_by_path('b/two').read(), 'old contents')
 
164
        eq(v3.get_file_by_path('top').read(), 'old contents')
 
165
        eq(v3.get_file_by_path('a/one').read(), 'new contents')
164
166
        v3.unlock()
165
167
 
166
168
        # commit in subdirectory commits whole tree
167
 
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
 
169
        run_bzr(['commit', '-m', 'commit whole tree from subdir'])
168
170
        v4 = b.repository.revision_tree(b.get_rev_id(4))
169
171
        v4.lock_read()
170
 
        self.assertEqual(v4.get_file_by_path('b/two').read(), 'new contents')
171
 
        self.assertEqual(v4.get_file_by_path('top').read(), 'new contents')
 
172
        eq(v4.get_file_by_path('b/two').read(), 'new contents')
 
173
        eq(v4.get_file_by_path('top').read(), 'new contents')
172
174
        v4.unlock()
173
175
 
174
176
        # TODO: factor out some kind of assert_tree_state() method
 
177
 
 
178
 
 
179
if __name__ == '__main__':
 
180
    import unittest
 
181
    unittest.main()