/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
 
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
#
 
17
 
 
18
"""Tests of the 'bzr add' command."""
 
19
 
 
20
import os
 
21
 
 
22
from bzrlib.tests.blackbox import ExternalBase
 
23
 
 
24
 
 
25
class TestAdd(ExternalBase):
 
26
        
 
27
    def test_add_reports(self):
 
28
        """add command prints the names of added files."""
 
29
        self.runbzr('init')
 
30
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
 
31
        self.build_tree_contents([('.bzrignore', 'CVS\n')])
 
32
        out = self.run_bzr_captured(['add'], retcode=0)[0]
 
33
        # the ordering is not defined at the moment
 
34
        results = sorted(out.rstrip('\n').split('\n'))
 
35
        self.assertEquals(['If you wish to add some of these files, please'\
 
36
                           ' add them by name.',
 
37
                           'added .bzrignore',
 
38
                           'added dir',
 
39
                           'added dir/sub.txt',
 
40
                           'added top.txt',
 
41
                           'ignored 1 file(s).'],
 
42
                          results)
 
43
        out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
 
44
        results = sorted(out.rstrip('\n').split('\n'))
 
45
        self.assertEquals(['If you wish to add some of these files, please'\
 
46
                           ' add them by name.',
 
47
                           'ignored CVS matching "CVS"'],
 
48
                          results)
 
49
 
 
50
    def test_add_quiet_is(self):
 
51
        """add -q does not print the names of added files."""
 
52
        self.runbzr('init')
 
53
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
54
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
 
55
        # the ordering is not defined at the moment
 
56
        results = sorted(out.rstrip('\n').split('\n'))
 
57
        self.assertEquals([''], results)
 
58
 
 
59
    def test_add_in_unversioned(self):
 
60
        """Try to add a file in an unversioned directory.
 
61
 
 
62
        "bzr add" should add the parent(s) as necessary.
 
63
        """
 
64
        self.runbzr('init')
 
65
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
66
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
67
        self.run_bzr('add', 'inertiatic/esp')
 
68
        self.assertEquals(self.capture('unknowns'), '')
 
69
 
 
70
        # Multiple unversioned parents
 
71
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
 
72
        self.assertEquals(self.capture('unknowns'), 'veil\n')
 
73
        self.run_bzr('add', 'veil/cerpin/taxt')
 
74
        self.assertEquals(self.capture('unknowns'), '')
 
75
 
 
76
        # Check whacky paths work
 
77
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
 
78
        self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
 
79
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
 
80
        self.assertEquals(self.capture('unknowns'), '')
 
81
 
 
82
    def test_add_in_versioned(self):
 
83
        """Try to add a file in a versioned directory.
 
84
 
 
85
        "bzr add" should do this happily.
 
86
        """
 
87
        self.runbzr('init')
 
88
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
 
89
        self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
 
90
        self.run_bzr('add', '--no-recurse', 'inertiatic')
 
91
        self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
 
92
        self.run_bzr('add', 'inertiatic/esp')
 
93
        self.assertEquals(self.capture('unknowns'), '')
 
94
 
 
95
    def test_subdir_add(self):
 
96
        """Add in subdirectory should add only things from there down"""
 
97
        from bzrlib.workingtree import WorkingTree
 
98
 
 
99
        eq = self.assertEqual
 
100
        ass = self.assertTrue
 
101
        chdir = os.chdir
 
102
        
 
103
        t = self.make_branch_and_tree('.')
 
104
        b = t.branch
 
105
        self.build_tree(['src/', 'README'])
 
106
        
 
107
        eq(sorted(t.unknowns()),
 
108
           ['README', 'src'])
 
109
        
 
110
        self.run_bzr('add', 'src')
 
111
        
 
112
        self.build_tree(['src/foo.c'])
 
113
        
 
114
        chdir('src')
 
115
        self.run_bzr('add')
 
116
        
 
117
        self.assertEquals(self.capture('unknowns'), 'README\n')
 
118
        eq(len(t.read_working_inventory()), 3)
 
119
                
 
120
        chdir('..')
 
121
        self.run_bzr('add')
 
122
        self.assertEquals(self.capture('unknowns'), '')
 
123
        self.run_bzr('check')
 
124
 
 
125
    def test_add_missing(self):
 
126
        """bzr add foo where foo is missing should error."""
 
127
        self.make_branch_and_tree('.')
 
128
        self.run_bzr('add', 'missing-file', retcode=3)
 
129
 
 
130
    def test_add_from(self):
 
131
        base_tree = self.make_branch_and_tree('base')
 
132
        self.build_tree(['base/a', 'base/b/', 'base/b/c'])
 
133
        base_tree.add(['a', 'b', 'b/c'])
 
134
        base_tree.commit('foo')
 
135
 
 
136
        new_tree = self.make_branch_and_tree('new')
 
137
        self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
 
138
 
 
139
        os.chdir('new')
 
140
        out, err = self.run_bzr('add', '--file-ids-from', '../base')
 
141
        self.assertEqual('', err)
 
142
        self.assertEqualDiff('added a w/ file id from a\n'
 
143
                             'added b w/ file id from b\n'
 
144
                             'added b/c w/ file id from b/c\n',
 
145
                             out)
 
146
 
 
147
        new_tree.read_working_inventory()
 
148
        self.assertEqual(base_tree.path2id('a'), new_tree.path2id('a'))
 
149
        self.assertEqual(base_tree.path2id('b'), new_tree.path2id('b'))
 
150
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('b/c'))
 
151
 
 
152
    def test_add_from_subdir(self):
 
153
        base_tree = self.make_branch_and_tree('base')
 
154
        self.build_tree(['base/a', 'base/b/', 'base/b/c', 'base/b/d'])
 
155
        base_tree.add(['a', 'b', 'b/c', 'b/d'])
 
156
        base_tree.commit('foo')
 
157
 
 
158
        new_tree = self.make_branch_and_tree('new')
 
159
        self.build_tree(['new/c', 'new/d'])
 
160
 
 
161
        os.chdir('new')
 
162
        out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
 
163
        self.assertEqual('', err)
 
164
        self.assertEqualDiff('added c w/ file id from b/c\n'
 
165
                             'added d w/ file id from b/d\n',
 
166
                             out)
 
167
 
 
168
        new_tree.read_working_inventory()
 
169
        self.assertEqual(base_tree.path2id('b/c'), new_tree.path2id('c'))
 
170
        self.assertEqual(base_tree.path2id('b/d'), new_tree.path2id('d'))
 
171
 
 
172
    def test_add_dry_run(self):
 
173
        # ensure that --dry-run actually don't add anything
 
174
        base_tree = self.make_branch_and_tree('.')
 
175
        self.build_tree(['spam'])
 
176
        out = self.run_bzr_captured(['add', '--dry-run'], retcode=0)[0]
 
177
        self.assertEquals('added spam\n', out)
 
178
        out = self.run_bzr_captured(['added'], retcode=0)[0]
 
179
        self.assertEquals('', out)