~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Martin
  • Date: 2010-05-16 15:18:43 UTC
  • mfrom: (5235 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5239.
  • Revision ID: gzlist@googlemail.com-20100516151843-lu53u7caehm3ie3i
Merge bzr.dev to resolve conflicts in NEWS and _chk_map_pyx

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    @staticmethod
66
66
    def get_command(options):
67
67
        class cmd_foo(commands.Command):
68
 
            'Bar'
 
68
            __doc__ = 'Bar'
69
69
 
70
70
            takes_options = options
71
71
 
79
79
        c = self.get_command([option.Option('foo', hidden=False)])
80
80
        self.assertContainsRe(c.get_help_text(), '--foo')
81
81
 
 
82
    def test_no_help_init_failure(self):
 
83
        class cmd_foo(commands.Command):
 
84
            pass
 
85
        self.assertRaises(ValueError, cmd_foo)
 
86
 
82
87
 
83
88
class TestGetAlias(tests.TestCase):
84
89
 
120
125
class TestSeeAlso(tests.TestCase):
121
126
    """Tests for the see also functional of Command."""
122
127
 
 
128
    @staticmethod
 
129
    def _get_command_with_see_also(see_also):
 
130
        class ACommand(commands.Command):
 
131
            __doc__ = """A sample command."""
 
132
            _see_also = see_also
 
133
        return ACommand()
 
134
 
123
135
    def test_default_subclass_no_see_also(self):
124
 
        class ACommand(commands.Command):
125
 
            """A sample command."""
126
 
        command = ACommand()
 
136
        command = self._get_command_with_see_also([])
127
137
        self.assertEqual([], command.get_see_also())
128
138
 
129
139
    def test__see_also(self):
130
140
        """When _see_also is defined, it sets the result of get_see_also()."""
131
 
        class ACommand(commands.Command):
132
 
            _see_also = ['bar', 'foo']
133
 
        command = ACommand()
 
141
        command = self._get_command_with_see_also(['bar', 'foo'])
134
142
        self.assertEqual(['bar', 'foo'], command.get_see_also())
135
143
 
136
144
    def test_deduplication(self):
137
145
        """Duplicates in _see_also are stripped out."""
138
 
        class ACommand(commands.Command):
139
 
            _see_also = ['foo', 'foo']
140
 
        command = ACommand()
 
146
        command = self._get_command_with_see_also(['foo', 'foo'])
141
147
        self.assertEqual(['foo'], command.get_see_also())
142
148
 
143
149
    def test_sorted(self):
144
150
        """_see_also is sorted by get_see_also."""
145
 
        class ACommand(commands.Command):
146
 
            _see_also = ['foo', 'bar']
147
 
        command = ACommand()
 
151
        command = self._get_command_with_see_also(['foo', 'bar'])
148
152
        self.assertEqual(['bar', 'foo'], command.get_see_also())
149
153
 
150
154
    def test_additional_terms(self):
151
155
        """Additional terms can be supplied and are deduped and sorted."""
152
 
        class ACommand(commands.Command):
153
 
            _see_also = ['foo', 'bar']
154
 
        command = ACommand()
 
156
        command = self._get_command_with_see_also(['foo', 'bar'])
155
157
        self.assertEqual(['bar', 'foo', 'gam'],
156
158
            command.get_see_also(['gam', 'bar', 'gam']))
157
159
 
212
214
            "extend_command", hook_calls.append, None)
213
215
        # create a command, should not fire
214
216
        class cmd_test_extend_command_hook(commands.Command):
215
 
            """A sample command."""
 
217
            __doc__ = """A sample command."""
216
218
        self.assertEqual([], hook_calls)
217
219
        # -- as a builtin
218
220
        # register the command class, should not fire
249
251
        commands.install_bzr_command_hooks()
250
252
        hook_calls = []
251
253
        class ACommand(commands.Command):
252
 
            """A sample command."""
 
254
            __doc__ = """A sample command."""
253
255
        def get_cmd(cmd_or_None, cmd_name):
254
256
            hook_calls.append(('called', cmd_or_None, cmd_name))
255
257
            if cmd_name in ('foo', 'info'):
280
282
        """Hook get_missing_command for testing."""
281
283
        self.hook_calls = []
282
284
        class ACommand(commands.Command):
283
 
            """A sample command."""
 
285
            __doc__ = """A sample command."""
284
286
        def get_missing_cmd(cmd_name):
285
287
            self.hook_calls.append(('called', cmd_name))
286
288
            if cmd_name in ('foo', 'info'):