/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
1
# Copyright (C) 2005, 2006, 2007, 2009-2012, 2016 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy.branch import Branch
26
from breezy.osutils import pathjoin
27
from breezy.tests import TestCaseInTempDir, TestCaseWithTransport
28
from breezy.trace import mutter
29
from breezy.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):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
45
        """Basic 'brz 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'])
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
49
        self.assertTrue(os.path.isdir('foo'))
743 by Martin Pool
- new simple versioning test cases
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
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
59
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
60
        self.assertEqual(delta.added[0].path[1], '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):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
64
        """'brz mkdir' operation in subdirectory"""
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
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'])
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
68
        self.assertTrue(os.path.isdir('dir'))
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
69
70
        self.log('Run mkdir in subdir')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
71
        self.run_bzr(['mkdir', 'subdir'], working_dir='dir')
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
72
        self.assertTrue(os.path.isdir('dir/subdir'))
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
73
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
74
        wt = WorkingTree.open('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
75
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
76
        delta = wt.changes_from(wt.basis_tree())
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
77
78
        self.log('delta.added = %r' % delta.added)
79
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
80
        self.assertEqual(len(delta.added), 2)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
81
        self.assertEqual(delta.added[0].path[1], 'dir')
82
        self.assertEqual(delta.added[1].path[1], pathjoin('dir', 'subdir'))
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
83
        self.assertFalse(delta.modified)
1185.31.7 by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls
84
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
85
    def test_mkdir_w_nested_trees(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
86
        """'brz mkdir' with nested trees"""
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
87
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
88
        self.make_branch_and_tree('.')
89
        self.make_branch_and_tree('a')
90
        self.make_branch_and_tree('a/b')
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
91
5036.2.8 by Parth Malwankar
updated based on review comments.
92
        self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
93
        self.assertTrue(os.path.isdir('dir'))
94
        self.assertTrue(os.path.isdir('a/dir'))
95
        self.assertTrue(os.path.isdir('a/b/dir'))
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
96
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
97
        wt = WorkingTree.open('.')
98
        wt_a = WorkingTree.open('a')
99
        wt_b = WorkingTree.open('a/b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
100
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
101
        delta = wt.changes_from(wt.basis_tree())
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
102
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
103
        self.assertEqual(delta.added[0].path[1], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
104
        self.assertFalse(delta.modified)
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
105
106
        delta = wt_a.changes_from(wt_a.basis_tree())
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
107
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
108
        self.assertEqual(delta.added[0].path[1], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
109
        self.assertFalse(delta.modified)
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
110
111
        delta = wt_b.changes_from(wt_b.basis_tree())
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
112
        self.assertEqual(len(delta.added), 1)
7358.11.3 by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes.
113
        self.assertEqual(delta.added[0].path[1], 'dir')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
114
        self.assertFalse(delta.modified)
1185.31.8 by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees.
115
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
116
    def test_mkdir_quiet(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
117
        """'brz mkdir --quiet' should not print a status message"""
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
118
5071.1.6 by Martin von Gagern
Cleaned up selftest code in response to suggestions by Martin Packman.
119
        self.make_branch_and_tree('.')
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
120
        out, err = self.run_bzr(['mkdir', '--quiet', 'foo'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
121
        self.assertEqual('', err)
122
        self.assertEqual('', out)
5071.1.1 by Martin von Gagern
Added blackbox test expectig "bzr mkdir --quiet foo" to not print anything.
123
1506 by Robert Collins
Merge Johns current integration work.
124
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.
125
class SubdirCommit(TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
126
127
    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.
128
        """Test committing a subdirectory, and committing a directory."""
129
        tree = self.make_branch_and_tree('.')
130
        b = tree.branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
131
        self.build_tree(['a/', 'b/'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
132
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.
133
        def set_contents(contents):
134
            self.build_tree_contents([
135
                ('a/one', contents),
136
                ('b/two', contents),
137
                ('top', contents),
138
                ])
6855.4.1 by Jelmer Vernooij
Yet more bees.
139
        set_contents(b'old contents')
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.
140
        tree.smart_add(['.'])
141
        tree.commit('first revision')
6855.4.1 by Jelmer Vernooij
Yet more bees.
142
        set_contents(b'new contents')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
143
1185.33.12 by Martin Pool
Remove some direct calls to logging, and some dead code
144
        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.
145
        self.run_bzr(['commit', 'a', '-m', 'commit a only'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
146
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
147
        new = b.repository.revision_tree(b.get_rev_id(2))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
148
        new.lock_read()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
149
6290.1.1 by Jelmer Vernooij
Remove broken Tree.get_file_by_path.
150
        def get_text_by_path(tree, path):
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
151
            return tree.get_file_text(path)
6290.1.1 by Jelmer Vernooij
Remove broken Tree.get_file_by_path.
152
6973.13.2 by Jelmer Vernooij
Fix some more tests.
153
        self.assertEqual(get_text_by_path(new, 'b/two'), b'old contents')
154
        self.assertEqual(get_text_by_path(new, 'top'), b'old contents')
155
        self.assertEqual(get_text_by_path(new, 'a/one'), b'new contents')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
156
        new.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
157
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
158
        # commit from here should do nothing
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
159
        self.run_bzr(['commit', '.', '-m', 'commit subdir only', '--unchanged'],
160
                     working_dir='a')
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
161
        v3 = b.repository.revision_tree(b.get_rev_id(3))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
162
        v3.lock_read()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
163
        self.assertEqual(get_text_by_path(v3, 'b/two'), b'old contents')
164
        self.assertEqual(get_text_by_path(v3, 'top'), b'old contents')
165
        self.assertEqual(get_text_by_path(v3, 'a/one'), b'new contents')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
166
        v3.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
167
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
168
        # commit in subdirectory commits whole tree
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
169
        self.run_bzr(['commit', '-m', 'commit whole tree from subdir'],
170
                     working_dir='a')
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
171
        v4 = b.repository.revision_tree(b.get_rev_id(4))
3010.1.16 by Robert Collins
Lock correctness in test_versioning
172
        v4.lock_read()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
173
        self.assertEqual(get_text_by_path(v4, 'b/two'), b'new contents')
174
        self.assertEqual(get_text_by_path(v4, 'top'), b'new contents')
3010.1.16 by Robert Collins
Lock correctness in test_versioning
175
        v4.unlock()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
176
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
177
        # TODO: factor out some kind of assert_tree_state() method