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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
16
16
 
17
17
import re
18
18
 
19
 
from .. import (
20
 
    bzr,
 
19
from bzrlib import (
 
20
    bzrdir,
21
21
    commands,
22
22
    controldir,
23
23
    errors,
24
24
    option,
25
25
    registry,
26
26
    )
27
 
from ..builtins import cmd_commit
28
 
from ..commands import parse_args
29
 
from . import TestCase
30
 
from ..bzr import knitrepo
 
27
from bzrlib.builtins import cmd_commit
 
28
from bzrlib.commands import parse_args
 
29
from bzrlib.tests import TestCase
 
30
from bzrlib.repofmt import knitrepo
31
31
 
32
32
 
33
33
def parse(options, args):
118
118
 
119
119
    def test_registry_conversion(self):
120
120
        registry = controldir.ControlDirFormatRegistry()
121
 
        bzr.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
122
 
        bzr.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
123
 
        bzr.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
 
121
        bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
 
122
        bzrdir.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
 
123
        bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
124
124
            'two help', hidden=True)
125
125
        registry.set_default('one')
126
126
        options = [option.RegistryOption('format', '', registry, str)]
128
128
        self.assertEqual({'format':'one'}, opts)
129
129
        opts, args = self.parse(options, ['--format', 'two'])
130
130
        self.assertEqual({'format':'two'}, opts)
131
 
        self.assertRaises(option.BadOptionValue, self.parse, options,
 
131
        self.assertRaises(errors.BadOptionValue, self.parse, options,
132
132
                          ['--format', 'three'])
133
133
        self.assertRaises(errors.BzrCommandError, self.parse, options,
134
134
                          ['--two'])
160
160
 
161
161
    def test_registry_converter(self):
162
162
        options = [option.RegistryOption('format', '',
163
 
                   controldir.format_registry, controldir.format_registry.make_controldir)]
 
163
                   controldir.format_registry, controldir.format_registry.make_bzrdir)]
164
164
        opts, args = self.parse(options, ['--format', 'knit'])
165
165
        self.assertIsInstance(opts.format.repository_format,
166
166
                              knitrepo.RepositoryFormatKnit1)
167
167
 
168
168
    def test_lazy_registry(self):
169
169
        options = [option.RegistryOption('format', '',
170
 
                   lazy_registry=('breezy.controldir', 'format_registry'),
 
170
                   lazy_registry=('bzrlib.controldir','format_registry'),
171
171
                   converter=str)]
172
172
        opts, args = self.parse(options, ['--format', 'knit'])
173
173
        self.assertEqual({'format': 'knit'}, opts)
174
174
        self.assertRaises(
175
 
            option.BadOptionValue, self.parse, options, ['--format', 'BAD'])
 
175
            errors.BadOptionValue, self.parse, options, ['--format', 'BAD'])
176
176
 
177
177
    def test_from_kwargs(self):
178
178
        my_option = option.RegistryOption.from_kwargs('my-option',
188
188
 
189
189
    def test_help(self):
190
190
        registry = controldir.ControlDirFormatRegistry()
191
 
        bzr.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
192
 
        bzr.register_metadir(registry, 'two',
193
 
            'breezy.bzr.knitrepo.RepositoryFormatKnit1',
 
191
        bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
 
192
        bzrdir.register_metadir(registry, 'two',
 
193
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
194
194
            'two help',
195
195
            )
196
 
        bzr.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
 
196
        bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
197
197
            hidden=True)
198
198
        registry.set_default('one')
199
199
        options = [option.RegistryOption('format', 'format help', registry,
216
216
        self.assertEqual(list(opt.iter_switches()),
217
217
                         [('hello', None, 'GAR', 'fg')])
218
218
        registry = controldir.ControlDirFormatRegistry()
219
 
        bzr.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
220
 
        bzr.register_metadir(registry, 'two',
221
 
                'breezy.bzr.knitrepo.RepositoryFormatKnit1',
 
219
        bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
 
220
        bzrdir.register_metadir(registry, 'two',
 
221
                'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
222
222
                'two help',
223
223
                )
224
224
        registry.set_default('one')
239
239
        "Test booleans get True and False passed correctly to a callback."""
240
240
        cb_calls = []
241
241
        def cb(option, name, value, parser):
242
 
            cb_calls.append((option, name, value, parser))
 
242
            cb_calls.append((option,name,value,parser))
243
243
        options = [option.Option('hello', custom_callback=cb)]
244
244
        opts, args = self.parse(options, ['--hello', '--no-hello'])
245
245
        self.assertEqual(2, len(cb_calls))
246
 
        opt, name, value, parser = cb_calls[0]
 
246
        opt,name,value,parser = cb_calls[0]
247
247
        self.assertEqual('hello', name)
248
248
        self.assertTrue(value)
249
 
        opt, name, value, parser = cb_calls[1]
 
249
        opt,name,value,parser = cb_calls[1]
250
250
        self.assertEqual('hello', name)
251
251
        self.assertFalse(value)
252
252
 
254
254
        """Test callbacks work for string options both long and short."""
255
255
        cb_calls = []
256
256
        def cb(option, name, value, parser):
257
 
            cb_calls.append((option, name, value, parser))
 
257
            cb_calls.append((option,name,value,parser))
258
258
        options = [option.Option('hello', type=str, custom_callback=cb,
259
259
            short_name='h')]
260
260
        opts, args = self.parse(options, ['--hello', 'world', '-h', 'mars'])
261
261
        self.assertEqual(2, len(cb_calls))
262
 
        opt, name, value, parser = cb_calls[0]
 
262
        opt,name,value,parser = cb_calls[0]
263
263
        self.assertEqual('hello', name)
264
264
        self.assertEqual('world', value)
265
 
        opt, name, value, parser = cb_calls[1]
 
265
        opt,name,value,parser = cb_calls[1]
266
266
        self.assertEqual('hello', name)
267
267
        self.assertEqual('mars', value)
268
268
 
313
313
        cb_calls = []
314
314
        def cb(option, name, value, parser):
315
315
            # Note that the value is a reference so copy to keep it
316
 
            cb_calls.append((option, name, value[:], parser))
 
316
            cb_calls.append((option,name,value[:],parser))
317
317
        options = [option.ListOption('hello', type=str, custom_callback=cb)]
318
318
        opts, args = self.parse(options, ['--hello=world', '--hello=mars',
319
319
            '--hello=-'])
320
320
        self.assertEqual(3, len(cb_calls))
321
 
        opt, name, value, parser = cb_calls[0]
 
321
        opt,name,value,parser = cb_calls[0]
322
322
        self.assertEqual('hello', name)
323
323
        self.assertEqual(['world'], value)
324
 
        opt, name, value, parser = cb_calls[1]
 
324
        opt,name,value,parser = cb_calls[1]
325
325
        self.assertEqual('hello', name)
326
326
        self.assertEqual(['world', 'mars'], value)
327
 
        opt, name, value, parser = cb_calls[2]
 
327
        opt,name,value,parser = cb_calls[2]
328
328
        self.assertEqual('hello', name)
329
329
        self.assertEqual([], value)
330
330
 
346
346
            cmd = commands.get_cmd_object(cmd_name)
347
347
            for opt_name, opt in sorted(cmd.options().items()):
348
348
                g.append((cmd_name, opt))
349
 
        self.assertTrue(g)
 
349
        self.assert_(g)
350
350
        return g
351
351
 
352
352
    def test_option_grammar(self):
377
377
 
378
378
    def test_is_hidden(self):
379
379
        registry = controldir.ControlDirFormatRegistry()
380
 
        bzr.register_metadir(registry, 'hidden', 'HiddenFormat',
 
380
        bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',
381
381
            'hidden help text', hidden=True)
382
 
        bzr.register_metadir(registry, 'visible', 'VisibleFormat',
 
382
        bzrdir.register_metadir(registry, 'visible', 'VisibleFormat',
383
383
            'visible help text', hidden=False)
384
384
        format = option.RegistryOption('format', '', registry, str)
385
385
        self.assertTrue(format.is_hidden('hidden'))
388
388
    def test_short_name(self):
389
389
        registry = controldir.ControlDirFormatRegistry()
390
390
        opt = option.RegistryOption('format', help='', registry=registry)
391
 
        self.assertEqual(None, opt.short_name())
 
391
        self.assertEquals(None, opt.short_name())
392
392
        opt = option.RegistryOption('format', short_name='F', help='',
393
393
            registry=registry)
394
 
        self.assertEqual('F', opt.short_name())
 
394
        self.assertEquals('F', opt.short_name())
395
395
 
396
396
    def test_option_custom_help(self):
397
397
        the_opt = option.Option.OPTIONS['help']