~bzr-pqm/bzr/bzr.dev

2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
1
# Copyright (C) 2005, 2006, 2007 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
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
21
from bzrlib.bzrdir import BzrDir
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
22
import bzrlib.errors as errors
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
23
from bzrlib.tests import TestCaseInTempDir
1558.5.1 by Aaron Bentley
Added make-repository command
24
25
class TestSharedRepo(TestCaseInTempDir):
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
26
1558.5.4 by Aaron Bentley
Added bzr init test
27
    def test_make_repository(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
28
        out, err = self.run_bzr("init-repository a")
3535.9.5 by Marius Kruger
remove a trailing space I added
29
        self.assertEqual(out,
3535.9.2 by Marius Kruger
make init and init-repo tests pass again
30
"""Shared repository with trees (format: pack-0.92)
31
Location:
32
  shared repository: a
33
""")
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
34
        self.assertEqual(err, "")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
35
        dir = BzrDir.open('a')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
36
        self.assertIs(dir.open_repository().is_shared(), True)
37
        self.assertRaises(errors.NotBranchError, dir.open_branch)
3535.9.6 by Marius Kruger
add explicit blackbox tests for 'init -q' and 'init-repo -q'
38
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
39
40
    def test_make_repository_quiet(self):
41
        out, err = self.run_bzr("init-repository a -q")
42
        self.assertEqual(out, "")
43
        self.assertEqual(err, "")
44
        dir = BzrDir.open('a')
45
        self.assertIs(dir.open_repository().is_shared(), True)
46
        self.assertRaises(errors.NotBranchError, dir.open_branch)
47
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
1558.5.4 by Aaron Bentley
Added bzr init test
48
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
49
    def test_init_repo_existing_dir(self):
50
        """Make repo in existing directory.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
51
1658.1.6 by Martin Pool
init-repo shouldn't insist on creating a new directory (Malone #38331)
52
        (Malone #38331)
53
        """
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
54
        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)
55
        dir = BzrDir.open('.')
56
        self.assertTrue(dir.open_repository())
57
1558.5.4 by Aaron Bentley
Added bzr init test
58
    def test_init(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
59
        self.run_bzr("init-repo a")
60
        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
61
        dir = BzrDir.open('a')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
62
        self.assertIs(dir.open_repository().is_shared(), True)
63
        self.assertRaises(errors.NotBranchError, dir.open_branch)
64
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
65
        bdir = BzrDir.open('a/b')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
66
        bdir.open_branch()
67
        self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository)
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
68
        wt = bdir.open_workingtree()
1558.5.5 by Aaron Bentley
Added tests for branch
69
70
    def test_branch(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
71
        self.run_bzr("init-repo a")
72
        self.run_bzr("init --format=default a/b")
73
        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
74
        cdir = BzrDir.open('a/c')
1558.5.9 by Aaron Bentley
Updated tests per Robert Collins' suggestions
75
        cdir.open_branch()
76
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
2257.2.1 by Wouter van Heyst
Change the ui level default for init-repo to --trees.
77
        cdir.open_workingtree()
1624.2.2 by Erik Bågfors
tests for --tree
78
79
    def test_branch_tree(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
80
        self.run_bzr("init-repo --trees a")
81
        self.run_bzr("init --format=default b")
1624.2.2 by Erik Bågfors
tests for --tree
82
        file('b/hello', 'wt').write('bar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
83
        self.run_bzr("add b/hello")
84
        self.run_bzr("commit -m bar b/hello")
1624.2.2 by Erik Bågfors
tests for --tree
85
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
86
        self.run_bzr('branch b a/c')
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
87
        cdir = BzrDir.open('a/c')
1624.2.2 by Erik Bågfors
tests for --tree
88
        cdir.open_branch()
89
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
1634.1.2 by Robert Collins
Merge Erik Bågfors --trees option for init-repository.
90
        self.failUnlessExists('a/c/hello')
1624.2.3 by Erik Bågfors
better test for --tree option
91
        cdir.open_workingtree()
1624.2.2 by Erik Bågfors
tests for --tree
92
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
93
    def test_trees_default(self):
94
        # 0.15 switched to trees by default
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
95
        self.run_bzr("init-repo repo")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
96
        repo = BzrDir.open("repo").open_repository()
97
        self.assertEqual(True, repo.make_working_trees())
98
99
    def test_trees_argument(self):
100
        # Supplying the --trees argument should be harmless,
101
        # 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.
102
        self.run_bzr("init-repo --trees trees")
2257.2.2 by Wouter van Heyst
Actually test that `bzr init-repo --{no,}-trees` still works
103
        repo = BzrDir.open("trees").open_repository()
104
        self.assertEqual(True, repo.make_working_trees())
105
106
    def test_no_trees_argument(self):
107
        # --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.
108
        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
109
        repo = BzrDir.open("notrees").open_repository()
110
        self.assertEqual(False, repo.make_working_trees())
4017.3.1 by Robert Collins
Add effort test for init-repo on smart server urls.
111
112
    def test_init_repo_smart_acceptance(self):
113
        # The amount of hpss calls made on init-repo to a smart server should
114
        # be fixed.
115
        self.setup_smart_server_with_call_log()
116
        self.run_bzr(['init-repo', self.get_url('repo')])
117
        # This figure represent the amount of work to perform this use case. It
118
        # is entirely ok to reduce this number if a test fails due to rpc_count
119
        # being too low. If rpc_count increases, more network roundtrips have
120
        # become necessary for this use case. Please do not adjust this number
121
        # upwards without agreement from bzr's network support maintainers.
4145.1.4 by Robert Collins
Prevent regression to overhead of lock_read on pack repositories.
122
        self.assertLength(16, self.hpss_calls)