~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-03-13 17:25:29 UTC
  • mfrom: (6499 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6501.
  • Revision ID: v.ladeuil+lp@free.fr-20120313172529-i0suyjnepsor25i7
Merge trunk

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
21
21
    transport,
22
22
    urlutils,
23
23
    )
24
 
from bzrlib.directory_service import DirectoryServiceRegistry, directories
 
24
from bzrlib.directory_service import (
 
25
    AliasDirectory,
 
26
    DirectoryServiceRegistry,
 
27
    directories,
 
28
    )
25
29
from bzrlib.tests import TestCase, TestCaseWithTransport
26
30
 
27
31
 
61
65
 
62
66
class TestAliasDirectory(TestCaseWithTransport):
63
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
        setter(value)
 
74
        self.assertEquals(value, directories.dereference(alias))
 
75
 
64
76
    def test_lookup_parent(self):
65
 
        branch = self.make_branch('.')
66
 
        branch.set_parent('http://a')
67
 
        self.assertEqual('http://a', directories.dereference(':parent'))
 
77
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
 
78
                                  ':parent')
68
79
 
69
80
    def test_lookup_submit(self):
70
 
        branch = self.make_branch('.')
71
 
        branch.set_submit_branch('http://b')
72
 
        self.assertEqual('http://b', directories.dereference(':submit'))
 
81
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
 
82
                                   ':submit')
73
83
 
74
84
    def test_lookup_public(self):
75
 
        branch = self.make_branch('.')
76
 
        branch.set_public_branch('http://c')
77
 
        self.assertEqual('http://c', directories.dereference(':public'))
 
85
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
 
86
                                   ':public')
78
87
 
79
88
    def test_lookup_bound(self):
80
 
        branch = self.make_branch('.')
81
 
        branch.set_bound_location('http://d')
82
 
        self.assertEqual('http://d', directories.dereference(':bound'))
 
89
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
 
90
                                   ':bound')
83
91
 
84
92
    def test_lookup_push(self):
85
 
        branch = self.make_branch('.')
86
 
        branch.set_push_location('http://e')
87
 
        self.assertEqual('http://e', directories.dereference(':push'))
 
93
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
 
94
                                   ':push')
88
95
 
89
96
    def test_lookup_this(self):
90
 
        branch = self.make_branch('.')
91
 
        self.assertEqual(branch.base, directories.dereference(':this'))
 
97
        self.assertEqual(self.branch.base, directories.dereference(':this'))
92
98
 
93
99
    def test_extra_path(self):
94
 
        branch = self.make_branch('.')
95
 
        self.assertEqual(urlutils.join(branch.base, 'arg'),
 
100
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
96
101
                         directories.dereference(':this/arg'))
97
102
 
98
103
    def test_lookup_badname(self):
99
 
        branch = self.make_branch('.')
100
104
        e = self.assertRaises(errors.InvalidLocationAlias,
101
105
                              directories.dereference, ':booga')
102
106
        self.assertEqual('":booga" is not a valid location alias.',
103
107
                         str(e))
104
108
 
105
109
    def test_lookup_badvalue(self):
106
 
        branch = self.make_branch('.')
107
110
        e = self.assertRaises(errors.UnsetLocationAlias,
108
111
                              directories.dereference, ':parent')
109
112
        self.assertEqual('No parent location assigned.', str(e))
 
113
 
 
114
    def test_register_location_alias(self):
 
115
        self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
 
116
        AliasDirectory.branch_aliases.register("booga",
 
117
            lambda b: "UHH?", help="Nobody knows")
 
118
        self.assertEquals("UHH?", directories.dereference(":booga"))