~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import sys
18
19
 
19
20
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
20
21
from bzrlib.clone import copy_branch
22
23
import bzrlib.errors as errors
23
24
from bzrlib.errors import NoSuchRevision, UnlistableBranch, NotBranchError
24
25
import bzrlib.gpg
25
 
from bzrlib.selftest import TestCase, TestCaseInTempDir
26
 
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
 
26
from bzrlib.osutils import getcwd
 
27
from bzrlib.tests import TestCase, TestCaseInTempDir
 
28
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
27
29
from bzrlib.trace import mutter
28
30
import bzrlib.transactions as transactions
29
31
from bzrlib.revision import NULL_REVISION
36
38
 
37
39
    def test_append_revisions(self):
38
40
        """Test appending more than one revision"""
39
 
        br = Branch.initialize(".")
 
41
        br = Branch.initialize(u".")
40
42
        br.append_revision("rev1")
41
43
        self.assertEquals(br.revision_history(), ["rev1",])
42
44
        br.append_revision("rev2", "rev3")
49
51
        os.mkdir('b2')
50
52
        b1 = Branch.initialize('b1')
51
53
        b2 = Branch.initialize('b2')
52
 
        file(os.sep.join(['b1', 'foo']), 'w').write('hello')
 
54
        file('b1/foo', 'w').write('hello')
53
55
        b1.working_tree().add(['foo'], ['foo-id'])
54
56
        b1.working_tree().commit('lala!', rev_id='revision-1', allow_pointless=False)
55
57
 
64
66
        eq(tree.get_file_text('foo-id'), 'hello')
65
67
 
66
68
    def test_revision_tree(self):
67
 
        b1 = Branch.initialize('.')
 
69
        b1 = Branch.initialize(u'.')
68
70
        b1.working_tree().commit('lala!', rev_id='revision-1', allow_pointless=True)
69
71
        tree = b1.revision_tree('revision-1')
70
72
        tree = b1.revision_tree(None)
128
130
        
129
131
    def test_record_initial_ghost_merge(self):
130
132
        """A pending merge with no revision present is still a merge."""
131
 
        branch = Branch.initialize('.')
 
133
        branch = Branch.initialize(u'.')
132
134
        branch.working_tree().add_pending_merge('non:existent@rev--ision--0--2')
133
135
        branch.working_tree().commit('pretend to merge nonexistent-revision', rev_id='first')
134
136
        rev = branch.get_revision(branch.last_revision())
138
140
        self.assertEqual(rev.parent_ids[0], 'non:existent@rev--ision--0--2')
139
141
 
140
142
    def test_bad_revision(self):
141
 
        branch = Branch.initialize('.')
 
143
        branch = Branch.initialize(u'.')
142
144
        self.assertRaises(errors.InvalidRevisionId, branch.get_revision, None)
143
145
 
144
146
# TODO 20051003 RBC:
148
150
        
149
151
    def test_pending_merges(self):
150
152
        """Tracking pending-merged revisions."""
151
 
        b = Branch.initialize('.')
 
153
        b = Branch.initialize(u'.')
152
154
        wt = b.working_tree()
153
155
        self.assertEquals(wt.pending_merges(), [])
154
156
        wt.add_pending_merge('foo@azkhazan-123123-abcabc')
170
172
        self.assertEquals(wt.pending_merges(), [])
171
173
 
172
174
    def test_sign_existing_revision(self):
173
 
        branch = Branch.initialize('.')
 
175
        branch = Branch.initialize(u'.')
174
176
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
175
177
        from bzrlib.testament import Testament
176
178
        branch.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
178
180
                         branch.revision_store.get('A', 'sig').read())
179
181
 
180
182
    def test_store_signature(self):
181
 
        branch = Branch.initialize('.')
 
183
        branch = Branch.initialize(u'.')
182
184
        branch.store_revision_signature(bzrlib.gpg.LoopbackGPGStrategy(None),
183
185
                                        'FOO', 'A')
184
186
        self.assertEqual('FOO', branch.revision_store.get('A', 'sig').read())
185
187
 
186
188
    def test__relcontrolfilename(self):
187
 
        branch = Branch.initialize('.')
 
189
        branch = Branch.initialize(u'.')
188
190
        self.assertEqual('.bzr/%25', branch._rel_controlfilename('%'))
189
191
        
190
192
    def test__relcontrolfilename_empty(self):
191
 
        branch = Branch.initialize('.')
 
193
        branch = Branch.initialize(u'.')
192
194
        self.assertEqual('.bzr', branch._rel_controlfilename(''))
193
195
 
194
196
    def test_nicks(self):
227
229
                          self.get_remote_url(''))
228
230
        self.assertRaises(NotBranchError, Branch.open_containing,
229
231
                          self.get_remote_url('g/p/q'))
230
 
        b = Branch.initialize('.')
 
232
        b = Branch.initialize(u'.')
231
233
        branch, relpath = Branch.open_containing(self.get_remote_url(''))
232
234
        self.assertEqual('', relpath)
233
235
        branch, relpath = Branch.open_containing(self.get_remote_url('g/p/q'))
319
321
 
320
322
    def setUp(self):
321
323
        super(TestBranchTransaction, self).setUp()
322
 
        self.branch = Branch.initialize('.')
 
324
        self.branch = Branch.initialize(u'.')
323
325
        
324
326
    def test_default_get_transaction(self):
325
327
        """branch.get_transaction on a new branch should give a PassThrough."""
368
370
 
369
371
    def setUp(self):
370
372
        super(TestBranchPushLocations, self).setUp()
371
 
        self.branch = Branch.initialize('.')
 
373
        self.branch = Branch.initialize(u'.')
372
374
        
373
375
    def test_get_push_location_unset(self):
374
376
        self.assertEqual(None, self.branch.get_push_location())
375
377
 
376
378
    def test_get_push_location_exact(self):
377
 
        self.build_tree(['.bazaar/'])
378
 
        print >> open('.bazaar/branches.conf', 'wt'), ("[%s]\n"
379
 
                                                       "push_location=foo" %
380
 
                                                       os.getcwdu())
 
379
        from bzrlib.config import (branches_config_filename,
 
380
                                   ensure_config_dir_exists)
 
381
        ensure_config_dir_exists()
 
382
        fn = branches_config_filename()
 
383
        print >> open(fn, 'wt'), ("[%s]\n"
 
384
                                  "push_location=foo" %
 
385
                                  getcwd())
381
386
        self.assertEqual("foo", self.branch.get_push_location())
382
387
 
383
388
    def test_set_push_location(self):
 
389
        from bzrlib.config import (branches_config_filename,
 
390
                                   ensure_config_dir_exists)
 
391
        ensure_config_dir_exists()
 
392
        fn = branches_config_filename()
384
393
        self.branch.set_push_location('foo')
385
394
        self.assertFileEqual("[%s]\n"
386
 
                             "push_location = foo" % os.getcwdu(),
387
 
                             '.bazaar/branches.conf')
 
395
                             "push_location = foo" % getcwd(),
 
396
                             fn)
388
397
 
389
398
    # TODO RBC 20051029 test getting a push location from a branch in a 
390
399
    # recursive section - that is, it appends the branch name.