/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/test_controldir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-24 12:08:37 UTC
  • mto: (5676.1.5 per_interrepo-extra)
  • mto: This revision was merged to the branch mainline in revision 5686.
  • Revision ID: jelmer@samba.org-20110224120837-73x5dp7h8w6fusfz
Refactor, move to bzrlib.controldir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for the ControlDir facility.
 
18
 
 
19
For interface contract tests, see tests/per_control_dir.
 
20
"""
 
21
 
 
22
from bzrlib import (
 
23
    controldir,
 
24
    )
 
25
from bzrlib.tests import (
 
26
    TestCase,
 
27
    )
 
28
 
 
29
 
 
30
class SampleComponentFormat(controldir.MetaComponentFormat):
 
31
 
 
32
    def get_format_string(self):
 
33
        return "Example component format."
 
34
 
 
35
 
 
36
class SampleExtraComponentFormat(controldir.MetaComponentFormat):
 
37
    """Extra format, no format string."""
 
38
 
 
39
 
 
40
class TestMetaComponentFormatRegistry(TestCase):
 
41
 
 
42
    def setUp(self):
 
43
        super(TestMetaComponentFormatRegistry, self).setUp()
 
44
        self.registry = controldir.ControlDirComponentFormatRegistry()
 
45
 
 
46
    def test_register_unregister_format(self):
 
47
        format = SampleComponentFormat()
 
48
        self.registry.register(format)
 
49
        self.assertEquals(format,
 
50
            self.registry.get("Example component format."))
 
51
        self.registry.remove(format)
 
52
        self.assertRaises(KeyError, self.registry.get,
 
53
            "Example component format.")
 
54
 
 
55
    def test_get_all(self):
 
56
        format = SampleComponentFormat()
 
57
        self.assertEquals([], self.registry._get_all())
 
58
        self.registry.register(format)
 
59
        self.assertEquals([format], self.registry._get_all())
 
60
 
 
61
    def test_register_extra(self):
 
62
        format = SampleExtraComponentFormat()
 
63
        self.assertEquals([], self.registry._get_all())
 
64
        self.registry.register_extra(format)
 
65
        self.assertEquals([format], self.registry._get_all())
 
66
 
 
67
    def test_register_extra_lazy(self):
 
68
        self.assertEquals([], self.registry._get_all())
 
69
        self.registry.register_extra_lazy("bzrlib.tests.test_controldir",
 
70
            "SampleExtraComponentFormat")
 
71
        formats = self.registry._get_all()
 
72
        self.assertEquals(1, len(formats))
 
73
        self.assertIsInstance(formats[0], SampleExtraComponentFormat)