~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_directory_service.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) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-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
65
65
 
66
66
class TestAliasDirectory(TestCaseWithTransport):
67
67
 
 
68
    def setUp(self):
 
69
        super(TestAliasDirectory, self).setUp()
 
70
        self.branch = self.make_branch('.')
 
71
 
 
72
    def assertAliasFromBranch(self, setter, value, alias):
 
73
        self.branch.lock_write()
 
74
        try:
 
75
            setter(value)
 
76
        finally:
 
77
            self.branch.unlock()
 
78
        self.assertEquals(value, directories.dereference(alias))
 
79
 
68
80
    def test_lookup_parent(self):
69
 
        branch = self.make_branch('.')
70
 
        branch.set_parent('http://a')
71
 
        self.assertEqual('http://a', directories.dereference(':parent'))
 
81
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
 
82
                                  ':parent')
72
83
 
73
84
    def test_lookup_submit(self):
74
 
        branch = self.make_branch('.')
75
 
        branch.set_submit_branch('http://b')
76
 
        self.assertEqual('http://b', directories.dereference(':submit'))
 
85
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
 
86
                                   ':submit')
77
87
 
78
88
    def test_lookup_public(self):
79
 
        branch = self.make_branch('.')
80
 
        branch.set_public_branch('http://c')
81
 
        self.assertEqual('http://c', directories.dereference(':public'))
 
89
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
 
90
                                   ':public')
82
91
 
83
92
    def test_lookup_bound(self):
84
 
        branch = self.make_branch('.')
85
 
        branch.set_bound_location('http://d')
86
 
        self.assertEqual('http://d', directories.dereference(':bound'))
 
93
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
 
94
                                   ':bound')
87
95
 
88
96
    def test_lookup_push(self):
89
 
        branch = self.make_branch('.')
90
 
        branch.set_push_location('http://e')
91
 
        self.assertEqual('http://e', directories.dereference(':push'))
 
97
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
 
98
                                   ':push')
92
99
 
93
100
    def test_lookup_this(self):
94
 
        branch = self.make_branch('.')
95
 
        self.assertEqual(branch.base, directories.dereference(':this'))
 
101
        self.assertEqual(self.branch.base, directories.dereference(':this'))
96
102
 
97
103
    def test_extra_path(self):
98
 
        branch = self.make_branch('.')
99
 
        self.assertEqual(urlutils.join(branch.base, 'arg'),
 
104
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
100
105
                         directories.dereference(':this/arg'))
101
106
 
102
107
    def test_lookup_badname(self):
103
 
        branch = self.make_branch('.')
104
108
        e = self.assertRaises(errors.InvalidLocationAlias,
105
109
                              directories.dereference, ':booga')
106
110
        self.assertEqual('":booga" is not a valid location alias.',
107
111
                         str(e))
108
112
 
109
113
    def test_lookup_badvalue(self):
110
 
        branch = self.make_branch('.')
111
114
        e = self.assertRaises(errors.UnsetLocationAlias,
112
115
                              directories.dereference, ':parent')
113
116
        self.assertEqual('No parent location assigned.', str(e))
114
117
 
115
118
    def test_register_location_alias(self):
116
 
        branch = self.make_branch('.')
117
119
        self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
118
120
        AliasDirectory.branch_aliases.register("booga",
119
121
            lambda b: "UHH?", help="Nobody knows")