~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2009-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
44
44
    def prepare_merge_directive(self):
45
45
        self.tree1 = self.make_branch_and_tree('tree1')
46
46
        self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\n')])
47
 
        self.tree1.branch.get_config().set_user_option('email',
48
 
            'J. Random Hacker <jrandom@example.com>')
 
47
        self.tree1.branch.lock_write()
 
48
        self.tree1.branch.get_config_stack().set(
 
49
            'email', 'J. Random Hacker <jrandom@example.com>')
 
50
        self.tree1.branch.unlock()
49
51
        self.tree1.add('file')
50
52
        self.tree1.commit('foo', rev_id='foo-id')
51
53
        self.tree2 = self.tree1.bzrdir.sprout('tree2').open_workingtree()
223
225
 
224
226
    def test_mail_uses_config(self):
225
227
        tree1, tree2 = self.prepare_merge_directive()
226
 
        tree1.branch.get_config_stack().set('smtp_server', 'bogushost')
 
228
        br = tree1.branch
 
229
        br.lock_write()
 
230
        try:
 
231
            br.get_config_stack().set('smtp_server', 'bogushost')
 
232
        finally:
 
233
            br.unlock()
227
234
        md_text, errr, connect_calls, sendmail_calls =\
228
235
            self.run_bzr_fakemail('merge-directive --mail-to'
229
236
                                  ' pqm@example.com --plain ../tree2 .')
234
241
        foo = self.make_branch_and_tree('foo')
235
242
        foo.commit('rev1')
236
243
        bar = self.make_branch_and_tree('bar')
237
 
        os.chdir('foo')
238
 
        self.run_bzr('merge-directive ../bar')
 
244
        self.run_bzr('merge-directive ../bar', working_dir='foo')
239
245
 
240
246
    def test_no_commits(self):
241
247
        foo = self.make_branch_and_tree('foo')
242
248
        bar = self.make_branch_and_tree('bar')
243
 
        os.chdir('foo')
244
249
        self.run_bzr_error(('No revisions to bundle.', ),
245
 
                            'merge-directive ../bar')
 
250
                            'merge-directive ../bar', working_dir='foo')
246
251
 
247
252
    def test_encoding_exact(self):
248
253
        tree1, tree2 = self.prepare_merge_directive()