~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1558.5.1 by Aaron Bentley
Added make-repository command
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1558.5.1 by Aaron Bentley
Added make-repository command
16
17
"""Black-box tests for repositories with shared branches"""
18
19
import os
20
5187.2.4 by Parth Malwankar
added tests.
21
from bzrlib import osutils
4734.4.9 by Andrew Bennetts
More tests and comments.
22
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
23
import bzrlib.errors as errors
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
24
from bzrlib.tests import TestCaseInTempDir
1558.5.1 by Aaron Bentley
Added make-repository command
25
26
class TestSharedRepo(TestCaseInTempDir):
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
27
1558.5.4 by Aaron Bentley
Added bzr init test
28
    def test_make_repository(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
29
        out, err = self.run_bzr("init-repository a")
3535.9.5 by Marius Kruger
remove a trailing space I added
30
        self.assertEqual(out,
4599.4.8 by Robert Collins
Update blackbox.test_shared_repository for 2a as default.
31
"""Shared repository with trees (format: 2a)
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
32
Location:
33
  shared repository: a
34
""")
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
35
        self.assertEqual(err, "")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
36
        dir = BzrDir.open('a')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
37
        self.assertIs(dir.open_repository().is_shared(), True)
38
        self.assertRaises(errors.NotBranchError, dir.open_branch)
3535.9.6 by Marius Kruger
add explicit blackbox tests for 'init -q' and 'init-repo -q'
39
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
40
41
    def test_make_repository_quiet(self):
42
        out, err = self.run_bzr("init-repository a -q")
43
        self.assertEqual(out, "")
44
        self.assertEqual(err, "")
45
        dir = BzrDir.open('a')
46
        self.assertIs(dir.open_repository().is_shared(), True)
47
        self.assertRaises(errors.NotBranchError, dir.open_branch)
48
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
1558.5.4 by Aaron Bentley
Added bzr init test
49
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
50
    def test_init_repo_existing_dir(self):
51
        """Make repo in existing directory.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
52
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
53
        (Malone #38331)
54
        """
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
55
        out, err = self.run_bzr("init-repository .")
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
56
        dir = BzrDir.open('.')
57
        self.assertTrue(dir.open_repository())
58
1558.5.4 by Aaron Bentley
Added bzr init test
59
    def test_init(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
60
        self.run_bzr("init-repo a")
61
        self.run_bzr("init --format=default a/b")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
62
        dir = BzrDir.open('a')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
63
        self.assertIs(dir.open_repository().is_shared(), True)
64
        self.assertRaises(errors.NotBranchError, dir.open_branch)
65
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
66
        bdir = BzrDir.open('a/b')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
67
        bdir.open_branch()
68
        self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository)
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
69
        wt = bdir.open_workingtree()
1558.5.5 by Aaron Bentley
Added tests for branch
70
71
    def test_branch(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
72
        self.run_bzr("init-repo a")
73
        self.run_bzr("init --format=default a/b")
74
        self.run_bzr('branch a/b a/c')
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
75
        cdir = BzrDir.open('a/c')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
76
        cdir.open_branch()
77
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
78
        cdir.open_workingtree()
1624.2.2 by Erik Bågfors
tests for --tree
79
80
    def test_branch_tree(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
81
        self.run_bzr("init-repo --trees a")
82
        self.run_bzr("init --format=default b")
1624.2.2 by Erik Bågfors
tests for --tree
83
        file('b/hello', 'wt').write('bar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
84
        self.run_bzr("add b/hello")
85
        self.run_bzr("commit -m bar b/hello")
1624.2.2 by Erik Bågfors
tests for --tree
86
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
87
        self.run_bzr('branch b a/c')
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
88
        cdir = BzrDir.open('a/c')
1624.2.2 by Erik Bågfors
tests for --tree
89
        cdir.open_branch()
90
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
91
        self.assertPathExists('a/c/hello')
1624.2.3 by Erik Bågfors
better test for --tree option
92
        cdir.open_workingtree()
1624.2.2 by Erik Bågfors
tests for --tree
93
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
94
    def test_trees_default(self):
95
        # 0.15 switched to trees by default
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
96
        self.run_bzr("init-repo repo")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
97
        repo = BzrDir.open("repo").open_repository()
98
        self.assertEqual(True, repo.make_working_trees())
99
100
    def test_trees_argument(self):
101
        # Supplying the --trees argument should be harmless,
102
        # as it was previously non-default we need to get it right.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
103
        self.run_bzr("init-repo --trees trees")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
104
        repo = BzrDir.open("trees").open_repository()
105
        self.assertEqual(True, repo.make_working_trees())
106
107
    def test_no_trees_argument(self):
108
        # --no-trees should make it so that there is no working tree
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
109
        self.run_bzr("init-repo --no-trees notrees")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
110
        repo = BzrDir.open("notrees").open_repository()
111
        self.assertEqual(False, repo.make_working_trees())
4017.3.1 by Robert Collins
Add effort test for init-repo on smart server urls.
112
113
    def test_init_repo_smart_acceptance(self):
114
        # The amount of hpss calls made on init-repo to a smart server should
115
        # be fixed.
116
        self.setup_smart_server_with_call_log()
117
        self.run_bzr(['init-repo', self.get_url('repo')])
118
        # This figure represent the amount of work to perform this use case. It
119
        # is entirely ok to reduce this number if a test fails due to rpc_count
120
        # being too low. If rpc_count increases, more network roundtrips have
121
        # become necessary for this use case. Please do not adjust this number
122
        # upwards without agreement from bzr's network support maintainers.
4634.47.7 by Andrew Bennetts
Tighten test_init_repo_smart_acceptance ratchet from 16 to 15.
123
        self.assertLength(15, self.hpss_calls)
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
124
125
    def test_notification_on_branch_from_repository(self):
126
        out, err = self.run_bzr("init-repository -q a")
127
        self.assertEqual(out, "")
128
        self.assertEqual(err, "")
129
        dir = BzrDir.open('a')
4734.4.7 by Andrew Bennetts
Defer checking for a repository in NotBranchError case until we format the error as a string. (test_smart currently fails)
130
        dir.open_repository() # there is a repository there
4734.4.4 by Brian de Alwis
Added tests to ensure branching-from-repository error returns detail
131
        e = self.assertRaises(errors.NotBranchError, dir.open_branch)
4734.4.7 by Andrew Bennetts
Defer checking for a repository in NotBranchError case until we format the error as a string. (test_smart currently fails)
132
        self.assertContainsRe(str(e), "location is a repository")
4734.4.9 by Andrew Bennetts
More tests and comments.
133
134
    def test_notification_on_branch_from_nonrepository(self):
135
        fmt = BzrDirMetaFormat1()
136
        t = self.get_transport()
137
        t.mkdir('a')
138
        dir = fmt.initialize_on_transport(t.clone('a'))
139
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
140
        e = self.assertRaises(errors.NotBranchError, dir.open_branch)
141
        self.assertNotContainsRe(str(e), "location is a repository")
5107.3.6 by Marco Pantaleoni
Documented behaviour of 'post_branch_init' for lightweight checkouts.
142
143
    def test_init_repo_with_post_repo_init_hook(self):
144
        calls = []
145
        BzrDir.hooks.install_named_hook('post_repo_init', calls.append, None)
146
        self.assertLength(0, calls)
147
        self.run_bzr("init-repository a")
148
        self.assertLength(1, calls)
5187.2.4 by Parth Malwankar
added tests.
149
5187.2.6 by Parth Malwankar
lockdir no long mandates whoami but uses unicode version of getuser
150
    def test_init_repo_without_username(self):
151
        """Ensure init-repo works if username is not set.
5187.2.4 by Parth Malwankar
added tests.
152
        """
5187.2.9 by Parth Malwankar
added comment to init/init-repo pass tests for lacking whoami.
153
        # bzr makes user specified whoami mandatory for operations
154
        # like commit as whoami is recorded. init-repo however is not so final
155
        # and uses whoami only in a lock file. Without whoami the login name
156
        # is used. This test is to ensure that init-repo passes even when whoami
157
        # is not available.
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
158
        self.overrideEnv('EMAIL', None)
159
        self.overrideEnv('BZR_EMAIL', None)
5187.2.6 by Parth Malwankar
lockdir no long mandates whoami but uses unicode version of getuser
160
        out, err = self.run_bzr(['init-repo', 'foo'])
161
        self.assertEqual(err, '')
162
        self.assertTrue(os.path.exists('foo'))