/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-03-11 15:34:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110311153414-i7vjkje5p8s2ozo9
Move more weave code.

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
    tests,
 
25
    )
 
26
 
 
27
 
 
28
class SampleComponentFormat(controldir.ControlComponentFormat):
 
29
 
 
30
    def get_format_string(self):
 
31
        return "Example component format."
 
32
 
 
33
 
 
34
class SampleExtraComponentFormat(controldir.ControlComponentFormat):
 
35
    """Extra format, no format string."""
 
36
 
 
37
 
 
38
class TestMetaComponentFormatRegistry(tests.TestCase):
 
39
 
 
40
    def setUp(self):
 
41
        super(TestMetaComponentFormatRegistry, self).setUp()
 
42
        self.registry = controldir.ControlComponentFormatRegistry()
 
43
 
 
44
    def test_register_unregister_format(self):
 
45
        format = SampleComponentFormat()
 
46
        self.registry.register(format)
 
47
        self.assertEquals(format,
 
48
            self.registry.get("Example component format."))
 
49
        self.registry.remove(format)
 
50
        self.assertRaises(KeyError, self.registry.get,
 
51
            "Example component format.")
 
52
 
 
53
    def test_get_all(self):
 
54
        format = SampleComponentFormat()
 
55
        self.assertEquals([], self.registry._get_all())
 
56
        self.registry.register(format)
 
57
        self.assertEquals([format], self.registry._get_all())
 
58
 
 
59
    def test_get_all_modules(self):
 
60
        format = SampleComponentFormat()
 
61
        self.assertEquals(set(), self.registry._get_all_modules())
 
62
        self.registry.register(format)
 
63
        self.assertEquals(
 
64
            set(["bzrlib.tests.test_controldir"]),
 
65
            self.registry._get_all_modules())
 
66
 
 
67
    def test_register_extra(self):
 
68
        format = SampleExtraComponentFormat()
 
69
        self.assertEquals([], self.registry._get_all())
 
70
        self.registry.register_extra(format)
 
71
        self.assertEquals([format], self.registry._get_all())
 
72
 
 
73
    def test_register_extra_lazy(self):
 
74
        self.assertEquals([], self.registry._get_all())
 
75
        self.registry.register_extra_lazy("bzrlib.tests.test_controldir",
 
76
            "SampleExtraComponentFormat")
 
77
        formats = self.registry._get_all()
 
78
        self.assertEquals(1, len(formats))
 
79
        self.assertIsInstance(formats[0], SampleExtraComponentFormat)
 
80
 
 
81
 
 
82
class ControlDirFormatTest1(controldir.ControlDirFormat):
 
83
    """A test control dir format."""
 
84
 
 
85
 
 
86
class TestControlDirFormat(tests.TestCaseWithTransport):
 
87
    """Tests for the ControlDirFormat facility."""
 
88
 
 
89
    def test_register_unregister_format(self):
 
90
        format = ControlDirFormatTest1()
 
91
        controldir.ControlDirFormat.register_format(format)
 
92
        self.assertTrue(format in controldir.ControlDirFormat.known_formats())
 
93
        controldir.ControlDirFormat.unregister_format(format)
 
94
        self.assertFalse(format in controldir.ControlDirFormat.known_formats())
 
95
 
 
96
    def test_register_unregister_format_lazy(self):
 
97
        controldir.ControlDirFormat.register_lazy_format(
 
98
            "bzrlib.tests.test_controldir", "ControlDirFormatTest1")
 
99
        self.assertTrue(
 
100
            ControlDirFormatTest1 in
 
101
            controldir.ControlDirFormat.known_formats())
 
102
        controldir.ControlDirFormat.unregister_lazy_format(
 
103
            "bzrlib.tests.test_controldir", "ControlDirFormatTest1")
 
104
        self.assertFalse(
 
105
            ControlDirFormatTest1 in
 
106
            controldir.ControlDirFormat.known_formats())