~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Patch Queue Manager
  • Date: 2012-01-28 16:56:12 UTC
  • mfrom: (6449.2.4 config-registry-option)
  • Revision ID: pqm@pqm.ubuntu.com-20120128165612-ji88oyq3ghpmzy0g
(jelmer) Add bzrlib.config.RegistryOption. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    mail_client,
36
36
    ui,
37
37
    urlutils,
 
38
    registry as _mod_registry,
38
39
    remote,
39
40
    tests,
40
41
    trace,
2480
2481
        self.assertConverted([u'bar'], opt, u'bar')
2481
2482
 
2482
2483
 
 
2484
class TestRegistryOption(tests.TestCase, TestOptionConverterMixin):
 
2485
 
 
2486
    def get_option(self, registry):
 
2487
        return config.RegistryOption('foo', registry,
 
2488
                help='A registry option.')
 
2489
 
 
2490
    def test_convert_invalid(self):
 
2491
        registry = _mod_registry.Registry()
 
2492
        opt = self.get_option(registry)
 
2493
        self.assertConvertInvalid(opt, [1])
 
2494
        self.assertConvertInvalid(opt, u"notregistered")
 
2495
 
 
2496
    def test_convert_valid(self):
 
2497
        registry = _mod_registry.Registry()
 
2498
        registry.register("someval", 1234)
 
2499
        opt = self.get_option(registry)
 
2500
        # Using a bare str() just in case
 
2501
        self.assertConverted(1234, opt, "someval")
 
2502
        self.assertConverted(1234, opt, u'someval')
 
2503
        self.assertConverted(None, opt, None)
 
2504
 
 
2505
    def test_help(self):
 
2506
        registry = _mod_registry.Registry()
 
2507
        registry.register("someval", 1234, help="some option")
 
2508
        registry.register("dunno", 1234, help="some other option")
 
2509
        opt = self.get_option(registry)
 
2510
        self.assertEquals(
 
2511
            'A registry option.\n'
 
2512
            '\n'
 
2513
            'The following values are supported:\n'
 
2514
            ' dunno - some other option\n'
 
2515
            ' someval - some option\n',
 
2516
            opt.help)
 
2517
 
 
2518
    def test_get_help_text(self):
 
2519
        registry = _mod_registry.Registry()
 
2520
        registry.register("someval", 1234, help="some option")
 
2521
        registry.register("dunno", 1234, help="some other option")
 
2522
        opt = self.get_option(registry)
 
2523
        self.assertEquals(
 
2524
            'A registry option.\n'
 
2525
            '\n'
 
2526
            'The following values are supported:\n'
 
2527
            ' dunno - some other option\n'
 
2528
            ' someval - some option\n',
 
2529
            opt.get_help_text())
 
2530
 
 
2531
 
2483
2532
class TestOptionRegistry(tests.TestCase):
2484
2533
 
2485
2534
    def setUp(self):