1903
1907
location='http://example.com/specific')
1904
1908
self.assertEqual(my_config.get_user_option('option'), 'exact')
1906
def test_get_mail_client(self):
1907
config = self.get_branch_config()
1908
client = config.get_mail_client()
1909
self.assertIsInstance(client, mail_client.DefaultMail)
1912
config.set_user_option('mail_client', 'evolution')
1913
client = config.get_mail_client()
1914
self.assertIsInstance(client, mail_client.Evolution)
1916
config.set_user_option('mail_client', 'kmail')
1917
client = config.get_mail_client()
1918
self.assertIsInstance(client, mail_client.KMail)
1920
config.set_user_option('mail_client', 'mutt')
1921
client = config.get_mail_client()
1922
self.assertIsInstance(client, mail_client.Mutt)
1924
config.set_user_option('mail_client', 'thunderbird')
1925
client = config.get_mail_client()
1926
self.assertIsInstance(client, mail_client.Thunderbird)
1929
config.set_user_option('mail_client', 'default')
1930
client = config.get_mail_client()
1931
self.assertIsInstance(client, mail_client.DefaultMail)
1933
config.set_user_option('mail_client', 'editor')
1934
client = config.get_mail_client()
1935
self.assertIsInstance(client, mail_client.Editor)
1937
config.set_user_option('mail_client', 'mapi')
1938
client = config.get_mail_client()
1939
self.assertIsInstance(client, mail_client.MAPIClient)
1941
config.set_user_option('mail_client', 'xdg-email')
1942
client = config.get_mail_client()
1943
self.assertIsInstance(client, mail_client.XDGEmail)
1945
config.set_user_option('mail_client', 'firebird')
1946
self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
1949
1911
class TestMailAddressExtraction(tests.TestCase):
2480
2442
self.assertConverted([u'bar'], opt, u'bar')
2445
class TestRegistryOption(tests.TestCase, TestOptionConverterMixin):
2447
def get_option(self, registry):
2448
return config.RegistryOption('foo', registry,
2449
help='A registry option.')
2451
def test_convert_invalid(self):
2452
registry = _mod_registry.Registry()
2453
opt = self.get_option(registry)
2454
self.assertConvertInvalid(opt, [1])
2455
self.assertConvertInvalid(opt, u"notregistered")
2457
def test_convert_valid(self):
2458
registry = _mod_registry.Registry()
2459
registry.register("someval", 1234)
2460
opt = self.get_option(registry)
2461
# Using a bare str() just in case
2462
self.assertConverted(1234, opt, "someval")
2463
self.assertConverted(1234, opt, u'someval')
2464
self.assertConverted(None, opt, None)
2466
def test_help(self):
2467
registry = _mod_registry.Registry()
2468
registry.register("someval", 1234, help="some option")
2469
registry.register("dunno", 1234, help="some other option")
2470
opt = self.get_option(registry)
2472
'A registry option.\n'
2474
'The following values are supported:\n'
2475
' dunno - some other option\n'
2476
' someval - some option\n',
2479
def test_get_help_text(self):
2480
registry = _mod_registry.Registry()
2481
registry.register("someval", 1234, help="some option")
2482
registry.register("dunno", 1234, help="some other option")
2483
opt = self.get_option(registry)
2485
'A registry option.\n'
2487
'The following values are supported:\n'
2488
' dunno - some other option\n'
2489
' someval - some option\n',
2490
opt.get_help_text())
2483
2493
class TestOptionRegistry(tests.TestCase):
2485
2495
def setUp(self):
3367
3377
def get_section(self, options, extra_path):
3368
3378
section = config.Section('foo', options)
3369
# We don't care about the length so we use '0'
3370
return config.LocationSection(section, 0, extra_path)
3379
return config.LocationSection(section, extra_path)
3372
3381
def test_simple_option(self):
3373
3382
section = self.get_section({'foo': 'bar'}, '')
3411
3420
[section.id for _, section in store.get_sections()])
3412
3421
matcher = config.LocationMatcher(store, '/foo/bar/quux')
3413
sections = [section for s, section in matcher.get_sections()]
3414
self.assertEquals([3, 2],
3415
[section.length for section in sections])
3422
sections = [section for _, section in matcher.get_sections()]
3416
3423
self.assertEquals(['/foo/bar', '/foo'],
3417
3424
[section.id for section in sections])
3418
3425
self.assertEquals(['quux', 'bar/quux'],
3429
3436
self.assertEquals(['/foo', '/foo/bar'],
3430
3437
[section.id for _, section in store.get_sections()])
3431
3438
matcher = config.LocationMatcher(store, '/foo/bar/baz')
3432
sections = [section for s, section in matcher.get_sections()]
3433
self.assertEquals([3, 2],
3434
[section.length for section in sections])
3439
sections = [section for _, section in matcher.get_sections()]
3435
3440
self.assertEquals(['/foo/bar', '/foo'],
3436
3441
[section.id for section in sections])
3437
3442
self.assertEquals(['baz', 'bar/baz'],
3462
3467
self.assertEquals(expected_location, matcher.location)
3470
class TestStartingPathMatcher(TestStore):
3473
super(TestStartingPathMatcher, self).setUp()
3474
# Any simple store is good enough
3475
self.store = config.IniFileStore()
3477
def assertSectionIDs(self, expected, location, content):
3478
self.store._load_from_string(content)
3479
matcher = config.StartingPathMatcher(self.store, location)
3480
sections = list(matcher.get_sections())
3481
self.assertLength(len(expected), sections)
3482
self.assertEqual(expected, [section.id for _, section in sections])
3485
def test_empty(self):
3486
self.assertSectionIDs([], self.get_url(), '')
3488
def test_url_vs_local_paths(self):
3489
# The matcher location is an url and the section names are local paths
3490
sections = self.assertSectionIDs(['/foo/bar', '/foo'],
3491
'file:///foo/bar/baz', '''\
3496
def test_local_path_vs_url(self):
3497
# The matcher location is a local path and the section names are urls
3498
sections = self.assertSectionIDs(['file:///foo/bar', 'file:///foo'],
3499
'/foo/bar/baz', '''\
3505
def test_no_name_section_included_when_present(self):
3506
# Note that other tests will cover the case where the no-name section
3507
# is empty and as such, not included.
3508
sections = self.assertSectionIDs(['/foo/bar', '/foo', None],
3509
'/foo/bar/baz', '''\
3510
option = defined so the no-name section exists
3514
self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
3515
[s.locals['relpath'] for _, s in sections])
3517
def test_order_reversed(self):
3518
self.assertSectionIDs(['/foo/bar', '/foo'], '/foo/bar/baz', '''\
3523
def test_unrelated_section_excluded(self):
3524
self.assertSectionIDs(['/foo/bar', '/foo'], '/foo/bar/baz', '''\
3530
def test_glob_included(self):
3531
sections = self.assertSectionIDs(['/foo/*/baz', '/foo/b*', '/foo'],
3532
'/foo/bar/baz', '''\
3538
# Note that 'baz' as a relpath for /foo/b* is not fully correct, but
3539
# nothing really is... as far using {relpath} to append it to something
3540
# else, this seems good enough though.
3541
self.assertEquals(['', 'baz', 'bar/baz'],
3542
[s.locals['relpath'] for _, s in sections])
3544
def test_respect_order(self):
3545
self.assertSectionIDs(['/foo', '/foo/b*', '/foo/*/baz'],
3546
'/foo/bar/baz', '''\
3465
3554
class TestNameMatcher(TestStore):
3467
3556
def setUp(self):
4792
4881
self.overrideEnv('BZR_EMAIL', None)
4793
4882
self.overrideEnv('EMAIL', 'jelmer@samba.org')
4794
4883
self.assertEquals('jelmer@debian.org', conf.get('email'))
4886
class MailClientOptionTests(tests.TestCase):
4888
def test_default(self):
4889
conf = config.MemoryStack('')
4890
client = conf.get('mail_client')
4891
self.assertIs(client, mail_client.DefaultMail)
4893
def test_evolution(self):
4894
conf = config.MemoryStack('mail_client=evolution')
4895
client = conf.get('mail_client')
4896
self.assertIs(client, mail_client.Evolution)
4898
def test_kmail(self):
4899
conf = config.MemoryStack('mail_client=kmail')
4900
client = conf.get('mail_client')
4901
self.assertIs(client, mail_client.KMail)
4903
def test_mutt(self):
4904
conf = config.MemoryStack('mail_client=mutt')
4905
client = conf.get('mail_client')
4906
self.assertIs(client, mail_client.Mutt)
4908
def test_thunderbird(self):
4909
conf = config.MemoryStack('mail_client=thunderbird')
4910
client = conf.get('mail_client')
4911
self.assertIs(client, mail_client.Thunderbird)
4913
def test_explicit_default(self):
4914
conf = config.MemoryStack('mail_client=default')
4915
client = conf.get('mail_client')
4916
self.assertIs(client, mail_client.DefaultMail)
4918
def test_editor(self):
4919
conf = config.MemoryStack('mail_client=editor')
4920
client = conf.get('mail_client')
4921
self.assertIs(client, mail_client.Editor)
4923
def test_mapi(self):
4924
conf = config.MemoryStack('mail_client=mapi')
4925
client = conf.get('mail_client')
4926
self.assertIs(client, mail_client.MAPIClient)
4928
def test_xdg_email(self):
4929
conf = config.MemoryStack('mail_client=xdg-email')
4930
client = conf.get('mail_client')
4931
self.assertIs(client, mail_client.XDGEmail)
4933
def test_unknown(self):
4934
conf = config.MemoryStack('mail_client=firebird')
4935
self.assertRaises(errors.ConfigOptionValueError, conf.get,