~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Vincent Ladeuil
  • Date: 2010-04-23 08:51:52 UTC
  • mfrom: (5131.2.6 support_OO_flag)
  • mto: This revision was merged to the branch mainline in revision 5179.
  • Revision ID: v.ladeuil+lp@free.fr-20100423085152-uoewc1vnkwqhw0pj
Manually assign docstrings to command objects, so that they work with python -OO

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
 
120
120
class TestSeeAlso(tests.TestCase):
121
121
    """Tests for the see also functional of Command."""
122
122
 
 
123
    @staticmethod
 
124
    def _get_command_with_see_also(see_also):
 
125
        class ACommand(commands.Command):
 
126
            __doc__ = """A sample command."""
 
127
            _see_also = see_also
 
128
        return ACommand()
 
129
 
123
130
    def test_default_subclass_no_see_also(self):
124
 
        class ACommand(commands.Command):
125
 
            """A sample command."""
126
 
        command = ACommand()
 
131
        command = self._get_command_with_see_also([])
127
132
        self.assertEqual([], command.get_see_also())
128
133
 
129
134
    def test__see_also(self):
130
135
        """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()
 
136
        command = self._get_command_with_see_also(['bar', 'foo'])
134
137
        self.assertEqual(['bar', 'foo'], command.get_see_also())
135
138
 
136
139
    def test_deduplication(self):
137
140
        """Duplicates in _see_also are stripped out."""
138
 
        class ACommand(commands.Command):
139
 
            _see_also = ['foo', 'foo']
140
 
        command = ACommand()
 
141
        command = self._get_command_with_see_also(['foo', 'foo'])
141
142
        self.assertEqual(['foo'], command.get_see_also())
142
143
 
143
144
    def test_sorted(self):
144
145
        """_see_also is sorted by get_see_also."""
145
 
        class ACommand(commands.Command):
146
 
            _see_also = ['foo', 'bar']
147
 
        command = ACommand()
 
146
        command = self._get_command_with_see_also(['foo', 'bar'])
148
147
        self.assertEqual(['bar', 'foo'], command.get_see_also())
149
148
 
150
149
    def test_additional_terms(self):
151
150
        """Additional terms can be supplied and are deduped and sorted."""
152
 
        class ACommand(commands.Command):
153
 
            _see_also = ['foo', 'bar']
154
 
        command = ACommand()
 
151
        command = self._get_command_with_see_also(['foo', 'bar'])
155
152
        self.assertEqual(['bar', 'foo', 'gam'],
156
153
            command.get_see_also(['gam', 'bar', 'gam']))
157
154
 
212
209
            "extend_command", hook_calls.append, None)
213
210
        # create a command, should not fire
214
211
        class cmd_test_extend_command_hook(commands.Command):
215
 
            """A sample command."""
 
212
            __doc__ = """A sample command."""
216
213
        self.assertEqual([], hook_calls)
217
214
        # -- as a builtin
218
215
        # register the command class, should not fire
249
246
        commands.install_bzr_command_hooks()
250
247
        hook_calls = []
251
248
        class ACommand(commands.Command):
252
 
            """A sample command."""
 
249
            __doc__ = """A sample command."""
253
250
        def get_cmd(cmd_or_None, cmd_name):
254
251
            hook_calls.append(('called', cmd_or_None, cmd_name))
255
252
            if cmd_name in ('foo', 'info'):
280
277
        """Hook get_missing_command for testing."""
281
278
        self.hook_calls = []
282
279
        class ACommand(commands.Command):
283
 
            """A sample command."""
 
280
            __doc__ = """A sample command."""
284
281
        def get_missing_cmd(cmd_name):
285
282
            self.hook_calls.append(('called', cmd_name))
286
283
            if cmd_name in ('foo', 'info'):