~bzr-pqm/bzr/bzr.dev

5036.2.9 by Vincent Ladeuil
Keep only the relevant tests.
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
743 by Martin Pool
- new simple versioning test cases
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
743 by Martin Pool
- new simple versioning test cases
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
743 by Martin Pool
- new simple versioning test cases
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
743 by Martin Pool
- new simple versioning test cases
16
17
18
"""Tests of simple versioning operations"""
19
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
20
# TODO: test trying to commit within a directory that is not yet added
21
22
23
import os
1125 by Martin Pool
- test code exercises a successful check and null upgrade of a branch
24
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
25
from bzrlib.branch import Branch
5036.2.3 by Parth Malwankar
intermediate checkin. Repo test case passing.
26
from bzrlib.osutils import pathjoin
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
27
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
1185.33.12 by Martin Pool
Remove some direct calls to logging, and some dead code
28
from bzrlib.trace import mutter
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
29
from bzrlib.workingtree import WorkingTree
1125 by Martin Pool
- test code exercises a successful check and null upgrade of a branch
30
743 by Martin Pool
- new simple versioning test cases
31
5036.2.3 by Parth Malwankar
intermediate checkin. Repo test case passing.
32
class TestMkdir(TestCaseWithTransport):
33
5036.2.9 by Vincent Ladeuil
Keep only the relevant tests.
34
    def test_mkdir_fails_cleanly(self):
35
        """'mkdir' fails cleanly when no working tree is available.
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
36
        https://bugs.launchpad.net/bzr/+bug/138600
5036.2.9 by Vincent Ladeuil
Keep only the relevant tests.
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)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
42
        self.assertPathDoesNotExist('abc')
5036.2.7 by Parth Malwankar
fixed mkdir and added test case for unversioned dir within branch
43
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
44
    def test_mkdir(self):
744 by Martin Pool
- show nicer descriptions while running tests
45
        """Basic 'bzr mkdir' operation"""
743 by Martin Pool
- new simple versioning test cases
46
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
47
        self.make_branch_and_tree('.')
5036.2.8 by Parth Malwankar
updated based on review comments.
48
        self.run_bzr(['mkdir', 'foo'])
743 by Martin Pool
- new simple versioning test cases
49
        self.assert_(os.path.isdir('foo'))
50
5036.2.8 by Parth Malwankar
updated based on review comments.
51
        self.run_bzr(['mkdir', 'foo'], retcode=3)
749 by Martin Pool
- More tests for bzr mkdir
52
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
53
        wt = WorkingTree.open('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
54
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
55
        delta = wt.changes_from(wt.basis_tree())
749 by Martin Pool
- More tests for bzr mkdir
56
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
57
        self.log('delta.added = %r' % delta.added)
58
749 by Martin Pool
- More tests for bzr mkdir
59
        self.assertEquals(len(delta.added), 1)
60
        self.assertEquals(delta.added[0][0], 'foo')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
61
        self.assertFalse(delta.modified)
749 by Martin Pool
- More tests for bzr mkdir
62
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
63
    def test_mkdir_in_subdir(self):
64
        """'bzr mkdir' operation in subdirectory"""
65
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
66
        self.make_branch_and_tree('.')
5036.2.8 by Parth Malwankar
updated based on review comments.
67
        self.run_bzr(['mkdir', 'dir'])
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
68
        self.assert_(os.path.isdir('dir'))
69
70
        os.chdir('dir')
71
        self.log('Run mkdir in subdir')
5036.2.8 by Parth Malwankar
updated based on review comments.
72
        self.run_bzr(['mkdir', 'subdir'])
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
73
        self.assert_(os.path.isdir('subdir'))
74
        os.chdir('..')
75
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
76
        wt = WorkingTree.open('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
77
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
78
        delta = wt.changes_from(wt.basis_tree())
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
79
80
        self.log('delta.added = %r' % delta.added)
81
82
        self.assertEquals(len(delta.added), 2)
83
        self.assertEquals(delta.added[0][0], 'dir')
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
84
        self.assertEquals(delta.added[1][0], pathjoin('dir','subdir'))
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
85
        self.assertFalse(delta.modified)
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
86
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
87
    def test_mkdir_w_nested_trees(self):
88
        """'bzr mkdir' with nested trees"""
89
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
90
        self.make_branch_and_tree('.')
91
        self.make_branch_and_tree('a')
92
        self.make_branch_and_tree('a/b')
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
93
5036.2.8 by Parth Malwankar
updated based on review comments.
94
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
95
        self.assertTrue(os.path.isdir('dir'))
96
        self.assertTrue(os.path.isdir('a/dir'))
97
        self.assertTrue(os.path.isdir('a/b/dir'))
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
98
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
99
        wt = WorkingTree.open('.')
100
        wt_a = WorkingTree.open('a')
101
        wt_b = WorkingTree.open('a/b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
102
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
103
        delta = wt.changes_from(wt.basis_tree())
104
        self.assertEquals(len(delta.added), 1)
105
        self.assertEquals(delta.added[0][0], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
106
        self.assertFalse(delta.modified)
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
107
108
        delta = wt_a.changes_from(wt_a.basis_tree())
109
        self.assertEquals(len(delta.added), 1)
110
        self.assertEquals(delta.added[0][0], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
111
        self.assertFalse(delta.modified)
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
112
113
        delta = wt_b.changes_from(wt_b.basis_tree())
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
114
        self.assertEquals(len(delta.added), 1)
115
        self.assertEquals(delta.added[0][0], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
116
        self.assertFalse(delta.modified)
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
117
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
118
    def test_mkdir_quiet(self):
119
        """'bzr mkdir --quiet' should not print a status message"""
120
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
121
        self.make_branch_and_tree('.')
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
122
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
123
        self.assertEquals('', err)
124
        self.assertEquals('', out)
125
1506 by Robert Collins
Merge Johns current integration work.
126
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
127
class SubdirCommit(TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
128
129
    def test_subdir_commit(self):
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
130
        """Test committing a subdirectory, and committing a directory."""
131
        tree = self.make_branch_and_tree('.')
132
        b = tree.branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
133
        self.build_tree(['a/', 'b/'])
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
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')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
144
1185.33.12 by Martin Pool
Remove some direct calls to logging, and some dead code
145
        mutter('start selective subdir commit')
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
146
        self.run_bzr(['commit', 'a', '-m', 'commit a only'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
147
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
148
        new = b.repository.revision_tree(b.get_rev_id(2))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
149
        new.lock_read()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
150
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
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')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
154
        new.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
155
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
156
        os.chdir('a')
157
        # commit from here should do nothing
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
158
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'])
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
159
        v3 = b.repository.revision_tree(b.get_rev_id(3))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
160
        v3.lock_read()
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
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')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
164
        v3.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
165
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
166
        # commit in subdirectory commits whole tree
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
167
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'])
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
168
        v4 = b.repository.revision_tree(b.get_rev_id(4))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
169
        v4.lock_read()
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
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')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
172
        v4.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
173
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
174
        # TODO: factor out some kind of assert_tree_state() method