1237
1247
def test_signatures_always(self):
1238
1248
my_config = config.GlobalConfig.from_string(sample_always_signatures)
1239
1249
self.assertEqual(config.CHECK_NEVER,
1240
my_config.signature_checking())
1250
self.applyDeprecated(deprecated_in((2, 5, 0)),
1251
my_config.signature_checking))
1241
1252
self.assertEqual(config.SIGN_ALWAYS,
1242
my_config.signing_policy())
1243
self.assertEqual(True, my_config.signature_needed())
1253
self.applyDeprecated(deprecated_in((2, 5, 0)),
1254
my_config.signing_policy))
1255
self.assertEqual(True,
1256
self.applyDeprecated(deprecated_in((2, 5, 0)),
1257
my_config.signature_needed))
1245
1259
def test_signatures_if_possible(self):
1246
1260
my_config = config.GlobalConfig.from_string(sample_maybe_signatures)
1247
1261
self.assertEqual(config.CHECK_NEVER,
1248
my_config.signature_checking())
1262
self.applyDeprecated(deprecated_in((2, 5, 0)),
1263
my_config.signature_checking))
1249
1264
self.assertEqual(config.SIGN_WHEN_REQUIRED,
1250
my_config.signing_policy())
1251
self.assertEqual(False, my_config.signature_needed())
1265
self.applyDeprecated(deprecated_in((2, 5, 0)),
1266
my_config.signing_policy))
1267
self.assertEqual(False, self.applyDeprecated(deprecated_in((2, 5, 0)),
1268
my_config.signature_needed))
1253
1270
def test_signatures_ignore(self):
1254
1271
my_config = config.GlobalConfig.from_string(sample_ignore_signatures)
1255
1272
self.assertEqual(config.CHECK_ALWAYS,
1256
my_config.signature_checking())
1273
self.applyDeprecated(deprecated_in((2, 5, 0)),
1274
my_config.signature_checking))
1257
1275
self.assertEqual(config.SIGN_NEVER,
1258
my_config.signing_policy())
1259
self.assertEqual(False, my_config.signature_needed())
1276
self.applyDeprecated(deprecated_in((2, 5, 0)),
1277
my_config.signing_policy))
1278
self.assertEqual(False, self.applyDeprecated(deprecated_in((2, 5, 0)),
1279
my_config.signature_needed))
1261
1281
def _get_sample_config(self):
1262
1282
my_config = config.GlobalConfig.from_string(sample_config_text)
1539
1573
self.get_branch_config('http://www.example.com',
1540
1574
global_config=sample_ignore_signatures)
1541
1575
self.assertEqual(config.CHECK_ALWAYS,
1542
self.my_config.signature_checking())
1576
self.applyDeprecated(deprecated_in((2, 5, 0)),
1577
self.my_config.signature_checking))
1543
1578
self.assertEqual(config.SIGN_NEVER,
1544
self.my_config.signing_policy())
1579
self.applyDeprecated(deprecated_in((2, 5, 0)),
1580
self.my_config.signing_policy))
1546
1582
def test_signatures_never(self):
1547
1583
self.get_branch_config('/a/c')
1548
1584
self.assertEqual(config.CHECK_NEVER,
1549
self.my_config.signature_checking())
1585
self.applyDeprecated(deprecated_in((2, 5, 0)),
1586
self.my_config.signature_checking))
1551
1588
def test_signatures_when_available(self):
1552
1589
self.get_branch_config('/a/', global_config=sample_ignore_signatures)
1553
1590
self.assertEqual(config.CHECK_IF_POSSIBLE,
1554
self.my_config.signature_checking())
1591
self.applyDeprecated(deprecated_in((2, 5, 0)),
1592
self.my_config.signature_checking))
1556
1594
def test_signatures_always(self):
1557
1595
self.get_branch_config('/b')
1558
1596
self.assertEqual(config.CHECK_ALWAYS,
1559
self.my_config.signature_checking())
1597
self.applyDeprecated(deprecated_in((2, 5, 0)),
1598
self.my_config.signature_checking))
1561
1600
def test_gpg_signing_command(self):
1562
1601
self.get_branch_config('/b')
1563
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
1602
self.assertEqual("gnome-gpg",
1603
self.applyDeprecated(deprecated_in((2, 5, 0)),
1604
self.my_config.gpg_signing_command))
1565
1606
def test_gpg_signing_command_missing(self):
1566
1607
self.get_branch_config('/a')
1567
self.assertEqual("false", self.my_config.gpg_signing_command())
1608
self.assertEqual("false",
1609
self.applyDeprecated(deprecated_in((2, 5, 0)),
1610
self.my_config.gpg_signing_command))
1569
1612
def test_gpg_signing_key(self):
1570
1613
self.get_branch_config('/b')
1571
self.assertEqual("DD4D5088", self.my_config.gpg_signing_key())
1614
self.assertEqual("DD4D5088", self.applyDeprecated(deprecated_in((2, 5, 0)),
1615
self.my_config.gpg_signing_key))
1573
1617
def test_gpg_signing_key_default(self):
1574
1618
self.get_branch_config('/a')
1575
self.assertEqual("erik@bagfors.nu", self.my_config.gpg_signing_key())
1619
self.assertEqual("erik@bagfors.nu",
1620
self.applyDeprecated(deprecated_in((2, 5, 0)),
1621
self.my_config.gpg_signing_key))
1577
1623
def test_get_user_option_global(self):
1578
1624
self.get_branch_config('/a')
2495
2609
self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2612
class TestCommandLineStore(tests.TestCase):
2615
super(TestCommandLineStore, self).setUp()
2616
self.store = config.CommandLineStore()
2617
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
2619
def get_section(self):
2620
"""Get the unique section for the command line overrides."""
2621
sections = list(self.store.get_sections())
2622
self.assertLength(1, sections)
2623
store, section = sections[0]
2624
self.assertEquals(self.store, store)
2627
def test_no_override(self):
2628
self.store._from_cmdline([])
2629
section = self.get_section()
2630
self.assertLength(0, list(section.iter_option_names()))
2632
def test_simple_override(self):
2633
self.store._from_cmdline(['a=b'])
2634
section = self.get_section()
2635
self.assertEqual('b', section.get('a'))
2637
def test_list_override(self):
2638
opt = config.ListOption('l')
2639
config.option_registry.register(opt)
2640
self.store._from_cmdline(['l=1,2,3'])
2641
val = self.get_section().get('l')
2642
self.assertEqual('1,2,3', val)
2643
# Reminder: lists should be registered as such explicitely, otherwise
2644
# the conversion needs to be done afterwards.
2645
self.assertEqual(['1', '2', '3'],
2646
opt.convert_from_unicode(self.store, val))
2648
def test_multiple_overrides(self):
2649
self.store._from_cmdline(['a=b', 'x=y'])
2650
section = self.get_section()
2651
self.assertEquals('b', section.get('a'))
2652
self.assertEquals('y', section.get('x'))
2654
def test_wrong_syntax(self):
2655
self.assertRaises(errors.BzrCommandError,
2656
self.store._from_cmdline, ['a=b', 'c'])
2658
class TestStoreMinimalAPI(tests.TestCaseWithTransport):
2660
scenarios = [(key, {'get_store': builder}) for key, builder
2661
in config.test_store_builder_registry.iteritems()] + [
2662
('cmdline', {'get_store': lambda test: config.CommandLineStore()})]
2665
store = self.get_store(self)
2666
if type(store) == config.TransportIniFileStore:
2667
raise tests.TestNotApplicable(
2668
"%s is not a concrete Store implementation"
2669
" so it doesn't need an id" % (store.__class__.__name__,))
2670
self.assertIsNot(None, store.id)
2498
2673
class TestStore(tests.TestCaseWithTransport):
2500
def assertSectionContent(self, expected, section):
2675
def assertSectionContent(self, expected, (store, section)):
2501
2676
"""Assert that some options have the proper values in a section."""
2502
2677
expected_name, expected_options = expected
2503
2678
self.assertEquals(expected_name, section.id)
2545
2717
self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
2720
class TestStoreQuoting(TestStore):
2722
scenarios = [(key, {'get_store': builder}) for key, builder
2723
in config.test_store_builder_registry.iteritems()]
2726
super(TestStoreQuoting, self).setUp()
2727
self.store = self.get_store(self)
2728
# We need a loaded store but any content will do
2729
self.store._load_from_string('')
2731
def assertIdempotent(self, s):
2732
"""Assert that quoting an unquoted string is a no-op and vice-versa.
2734
What matters here is that option values, as they appear in a store, can
2735
be safely round-tripped out of the store and back.
2737
:param s: A string, quoted if required.
2739
self.assertEquals(s, self.store.quote(self.store.unquote(s)))
2740
self.assertEquals(s, self.store.unquote(self.store.quote(s)))
2742
def test_empty_string(self):
2743
if isinstance(self.store, config.IniFileStore):
2744
# configobj._quote doesn't handle empty values
2745
self.assertRaises(AssertionError,
2746
self.assertIdempotent, '')
2748
self.assertIdempotent('')
2749
# But quoted empty strings are ok
2750
self.assertIdempotent('""')
2752
def test_embedded_spaces(self):
2753
self.assertIdempotent('" a b c "')
2755
def test_embedded_commas(self):
2756
self.assertIdempotent('" a , b c "')
2758
def test_simple_comma(self):
2759
if isinstance(self.store, config.IniFileStore):
2760
# configobj requires that lists are special-cased
2761
self.assertRaises(AssertionError,
2762
self.assertIdempotent, ',')
2764
self.assertIdempotent(',')
2765
# When a single comma is required, quoting is also required
2766
self.assertIdempotent('","')
2768
def test_list(self):
2769
if isinstance(self.store, config.IniFileStore):
2770
# configobj requires that lists are special-cased
2771
self.assertRaises(AssertionError,
2772
self.assertIdempotent, 'a,b')
2774
self.assertIdempotent('a,b')
2777
class TestDictFromStore(tests.TestCase):
2779
def test_unquote_not_string(self):
2780
conf = config.MemoryStack('x=2\n[a_section]\na=1\n')
2781
value = conf.get('a_section')
2782
# Urgh, despite 'conf' asking for the no-name section, we get the
2783
# content of another section as a dict o_O
2784
self.assertEquals({'a': '1'}, value)
2785
unquoted = conf.store.unquote(value)
2786
# Which cannot be unquoted but shouldn't crash either (the use cases
2787
# are getting the value or displaying it. In the later case, '%s' will
2789
self.assertEquals({'a': '1'}, unquoted)
2790
self.assertEquals("{u'a': u'1'}", '%s' % (unquoted,))
2548
2793
class TestIniFileStoreContent(tests.TestCaseWithTransport):
2549
"""Simulate loading a config store without content of various encodings.
2794
"""Simulate loading a config store with content of various encodings.
2551
2796
All files produced by bzr are in utf8 content.
3047
3338
self.assertEquals(expected_location, matcher.location)
3050
class TestStackGet(tests.TestCase):
3052
# FIXME: This should be parametrized for all known Stack or dedicated
3053
# paramerized tests created to avoid bloating -- vila 2011-03-31
3055
def overrideOptionRegistry(self):
3341
class TestNameMatcher(TestStore):
3344
super(TestNameMatcher, self).setUp()
3345
self.matcher = config.NameMatcher
3346
# Any simple store is good enough
3347
self.get_store = config.test_store_builder_registry.get('configobj')
3349
def get_matching_sections(self, name):
3350
store = self.get_store(self)
3351
store._load_from_string('''
3359
matcher = self.matcher(store, name)
3360
return list(matcher.get_sections())
3362
def test_matching(self):
3363
sections = self.get_matching_sections('foo')
3364
self.assertLength(1, sections)
3365
self.assertSectionContent(('foo', {'option': 'foo'}), sections[0])
3367
def test_not_matching(self):
3368
sections = self.get_matching_sections('baz')
3369
self.assertLength(0, sections)
3372
class TestBaseStackGet(tests.TestCase):
3375
super(TestBaseStackGet, self).setUp()
3056
3376
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3058
def test_single_config_get(self):
3059
conf = dict(foo='bar')
3060
conf_stack = config.Stack([conf])
3061
self.assertEquals('bar', conf_stack.get('foo'))
3378
def test_get_first_definition(self):
3379
store1 = config.IniFileStore()
3380
store1._load_from_string('foo=bar')
3381
store2 = config.IniFileStore()
3382
store2._load_from_string('foo=baz')
3383
conf = config.Stack([store1.get_sections, store2.get_sections])
3384
self.assertEquals('bar', conf.get('foo'))
3063
3386
def test_get_with_registered_default_value(self):
3064
conf_stack = config.Stack([dict()])
3065
opt = config.Option('foo', default='bar')
3066
self.overrideOptionRegistry()
3067
config.option_registry.register('foo', opt)
3387
config.option_registry.register(config.Option('foo', default='bar'))
3388
conf_stack = config.Stack([])
3068
3389
self.assertEquals('bar', conf_stack.get('foo'))
3070
3391
def test_get_without_registered_default_value(self):
3071
conf_stack = config.Stack([dict()])
3072
opt = config.Option('foo')
3073
self.overrideOptionRegistry()
3074
config.option_registry.register('foo', opt)
3392
config.option_registry.register(config.Option('foo'))
3393
conf_stack = config.Stack([])
3075
3394
self.assertEquals(None, conf_stack.get('foo'))
3077
3396
def test_get_without_default_value_for_not_registered(self):
3078
conf_stack = config.Stack([dict()])
3079
opt = config.Option('foo')
3080
self.overrideOptionRegistry()
3397
conf_stack = config.Stack([])
3081
3398
self.assertEquals(None, conf_stack.get('foo'))
3083
def test_get_first_definition(self):
3084
conf1 = dict(foo='bar')
3085
conf2 = dict(foo='baz')
3086
conf_stack = config.Stack([conf1, conf2])
3087
self.assertEquals('bar', conf_stack.get('foo'))
3089
def test_get_embedded_definition(self):
3090
conf1 = dict(yy='12')
3091
conf2 = config.Stack([dict(xx='42'), dict(foo='baz')])
3092
conf_stack = config.Stack([conf1, conf2])
3093
self.assertEquals('baz', conf_stack.get('foo'))
3095
3400
def test_get_for_empty_section_callable(self):
3096
3401
conf_stack = config.Stack([lambda : []])
3097
3402
self.assertEquals(None, conf_stack.get('foo'))
3099
3404
def test_get_for_broken_callable(self):
3100
3405
# Trying to use and invalid callable raises an exception on first use
3101
conf_stack = config.Stack([lambda : object()])
3406
conf_stack = config.Stack([object])
3102
3407
self.assertRaises(TypeError, conf_stack.get, 'foo')
3410
class TestStackWithSimpleStore(tests.TestCase):
3413
super(TestStackWithSimpleStore, self).setUp()
3414
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3415
self.registry = config.option_registry
3417
def get_conf(self, content=None):
3418
return config.MemoryStack(content)
3420
def test_override_value_from_env(self):
3421
self.registry.register(
3422
config.Option('foo', default='bar', override_from_env=['FOO']))
3423
self.overrideEnv('FOO', 'quux')
3424
# Env variable provides a default taking over the option one
3425
conf = self.get_conf('foo=store')
3426
self.assertEquals('quux', conf.get('foo'))
3428
def test_first_override_value_from_env_wins(self):
3429
self.registry.register(
3430
config.Option('foo', default='bar',
3431
override_from_env=['NO_VALUE', 'FOO', 'BAZ']))
3432
self.overrideEnv('FOO', 'foo')
3433
self.overrideEnv('BAZ', 'baz')
3434
# The first env var set wins
3435
conf = self.get_conf('foo=store')
3436
self.assertEquals('foo', conf.get('foo'))
3439
class TestMemoryStack(tests.TestCase):
3442
conf = config.MemoryStack('foo=bar')
3443
self.assertEquals('bar', conf.get('foo'))
3446
conf = config.MemoryStack('foo=bar')
3447
conf.set('foo', 'baz')
3448
self.assertEquals('baz', conf.get('foo'))
3450
def test_no_content(self):
3451
conf = config.MemoryStack()
3452
# No content means no loading
3453
self.assertFalse(conf.store.is_loaded())
3454
self.assertRaises(NotImplementedError, conf.get, 'foo')
3455
# But a content can still be provided
3456
conf.store._load_from_string('foo=bar')
3457
self.assertEquals('bar', conf.get('foo'))
3105
3460
class TestStackWithTransport(tests.TestCaseWithTransport):
3107
3462
scenarios = [(key, {'get_stack': builder}) for key, builder
3186
3549
def test_get_default_integer_None(self):
3187
3550
self.register_integer_option('foo')
3188
self.assertEquals(None, self.conf.get('foo'))
3551
conf = self.get_conf('')
3552
self.assertEquals(None, conf.get('foo'))
3190
3554
def test_get_default_integer(self):
3191
3555
self.register_integer_option('foo', 42)
3192
self.assertEquals(42, self.conf.get('foo'))
3556
conf = self.get_conf('')
3557
self.assertEquals(42, conf.get('foo'))
3194
3559
def test_get_default_integer_as_string(self):
3195
3560
self.register_integer_option('foo', u'42')
3196
self.assertEquals(42, self.conf.get('foo'))
3561
conf = self.get_conf('')
3562
self.assertEquals(42, conf.get('foo'))
3198
3564
def test_get_default_integer_from_env(self):
3199
3565
self.register_integer_option('foo', default_from_env=['FOO'])
3200
3566
self.overrideEnv('FOO', '18')
3201
self.assertEquals(18, self.conf.get('foo'))
3567
conf = self.get_conf('')
3568
self.assertEquals(18, conf.get('foo'))
3203
3570
def test_get_default_integer_when_conversion_fails(self):
3204
3571
self.register_integer_option('foo', default='12')
3205
self.conf.store._load_from_string('foo=invalid integer')
3206
self.assertEquals(12, self.conf.get('foo'))
3572
conf = self.get_conf('foo=invalid integer')
3573
self.assertEquals(12, conf.get('foo'))
3208
3575
def register_list_option(self, name, default=None, default_from_env=None):
3209
l = config.Option(name, help='A list.',
3210
default=default, default_from_env=default_from_env,
3211
from_unicode=config.list_from_store)
3576
l = config.ListOption(name, help='A list.', default=default,
3577
default_from_env=default_from_env)
3212
3578
self.registry.register(l)
3214
3580
def test_get_default_list_None(self):
3215
3581
self.register_list_option('foo')
3216
self.assertEquals(None, self.conf.get('foo'))
3582
conf = self.get_conf('')
3583
self.assertEquals(None, conf.get('foo'))
3218
3585
def test_get_default_list_empty(self):
3219
3586
self.register_list_option('foo', '')
3220
self.assertEquals([], self.conf.get('foo'))
3587
conf = self.get_conf('')
3588
self.assertEquals([], conf.get('foo'))
3222
3590
def test_get_default_list_from_env(self):
3223
3591
self.register_list_option('foo', default_from_env=['FOO'])
3224
3592
self.overrideEnv('FOO', '')
3225
self.assertEquals([], self.conf.get('foo'))
3593
conf = self.get_conf('')
3594
self.assertEquals([], conf.get('foo'))
3227
3596
def test_get_with_list_converter_no_item(self):
3228
3597
self.register_list_option('foo', None)
3229
self.conf.store._load_from_string('foo=,')
3230
self.assertEquals([], self.conf.get('foo'))
3598
conf = self.get_conf('foo=,')
3599
self.assertEquals([], conf.get('foo'))
3232
3601
def test_get_with_list_converter_many_items(self):
3233
3602
self.register_list_option('foo', None)
3234
self.conf.store._load_from_string('foo=m,o,r,e')
3235
self.assertEquals(['m', 'o', 'r', 'e'], self.conf.get('foo'))
3603
conf = self.get_conf('foo=m,o,r,e')
3604
self.assertEquals(['m', 'o', 'r', 'e'], conf.get('foo'))
3606
def test_get_with_list_converter_embedded_spaces_many_items(self):
3607
self.register_list_option('foo', None)
3608
conf = self.get_conf('foo=" bar", "baz "')
3609
self.assertEquals([' bar', 'baz '], conf.get('foo'))
3611
def test_get_with_list_converter_stripped_spaces_many_items(self):
3612
self.register_list_option('foo', None)
3613
conf = self.get_conf('foo= bar , baz ')
3614
self.assertEquals(['bar', 'baz'], conf.get('foo'))
3617
class TestIterOptionRefs(tests.TestCase):
3618
"""iter_option_refs is a bit unusual, document some cases."""
3620
def assertRefs(self, expected, string):
3621
self.assertEquals(expected, list(config.iter_option_refs(string)))
3623
def test_empty(self):
3624
self.assertRefs([(False, '')], '')
3626
def test_no_refs(self):
3627
self.assertRefs([(False, 'foo bar')], 'foo bar')
3629
def test_single_ref(self):
3630
self.assertRefs([(False, ''), (True, '{foo}'), (False, '')], '{foo}')
3632
def test_broken_ref(self):
3633
self.assertRefs([(False, '{foo')], '{foo')
3635
def test_embedded_ref(self):
3636
self.assertRefs([(False, '{'), (True, '{foo}'), (False, '}')],
3639
def test_two_refs(self):
3640
self.assertRefs([(False, ''), (True, '{foo}'),
3641
(False, ''), (True, '{bar}'),
3645
def test_newline_in_refs_are_not_matched(self):
3646
self.assertRefs([(False, '{\nxx}{xx\n}{{\n}}')], '{\nxx}{xx\n}{{\n}}')
3649
class TestStackExpandOptions(tests.TestCaseWithTransport):
3652
super(TestStackExpandOptions, self).setUp()
3653
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3654
self.registry = config.option_registry
3655
self.conf = build_branch_stack(self)
3657
def assertExpansion(self, expected, string, env=None):
3658
self.assertEquals(expected, self.conf.expand_options(string, env))
3660
def test_no_expansion(self):
3661
self.assertExpansion('foo', 'foo')
3663
def test_expand_default_value(self):
3664
self.conf.store._load_from_string('bar=baz')
3665
self.registry.register(config.Option('foo', default=u'{bar}'))
3666
self.assertEquals('baz', self.conf.get('foo', expand=True))
3668
def test_expand_default_from_env(self):
3669
self.conf.store._load_from_string('bar=baz')
3670
self.registry.register(config.Option('foo', default_from_env=['FOO']))
3671
self.overrideEnv('FOO', '{bar}')
3672
self.assertEquals('baz', self.conf.get('foo', expand=True))
3674
def test_expand_default_on_failed_conversion(self):
3675
self.conf.store._load_from_string('baz=bogus\nbar=42\nfoo={baz}')
3676
self.registry.register(
3677
config.Option('foo', default=u'{bar}',
3678
from_unicode=config.int_from_store))
3679
self.assertEquals(42, self.conf.get('foo', expand=True))
3681
def test_env_adding_options(self):
3682
self.assertExpansion('bar', '{foo}', {'foo': 'bar'})
3684
def test_env_overriding_options(self):
3685
self.conf.store._load_from_string('foo=baz')
3686
self.assertExpansion('bar', '{foo}', {'foo': 'bar'})
3688
def test_simple_ref(self):
3689
self.conf.store._load_from_string('foo=xxx')
3690
self.assertExpansion('xxx', '{foo}')
3692
def test_unknown_ref(self):
3693
self.assertRaises(errors.ExpandingUnknownOption,
3694
self.conf.expand_options, '{foo}')
3696
def test_indirect_ref(self):
3697
self.conf.store._load_from_string('''
3701
self.assertExpansion('xxx', '{bar}')
3703
def test_embedded_ref(self):
3704
self.conf.store._load_from_string('''
3708
self.assertExpansion('xxx', '{{bar}}')
3710
def test_simple_loop(self):
3711
self.conf.store._load_from_string('foo={foo}')
3712
self.assertRaises(errors.OptionExpansionLoop,
3713
self.conf.expand_options, '{foo}')
3715
def test_indirect_loop(self):
3716
self.conf.store._load_from_string('''
3720
e = self.assertRaises(errors.OptionExpansionLoop,
3721
self.conf.expand_options, '{foo}')
3722
self.assertEquals('foo->bar->baz', e.refs)
3723
self.assertEquals('{foo}', e.string)
3725
def test_list(self):
3726
self.conf.store._load_from_string('''
3730
list={foo},{bar},{baz}
3732
self.registry.register(
3733
config.ListOption('list'))
3734
self.assertEquals(['start', 'middle', 'end'],
3735
self.conf.get('list', expand=True))
3737
def test_cascading_list(self):
3738
self.conf.store._load_from_string('''
3744
self.registry.register(
3745
config.ListOption('list'))
3746
self.assertEquals(['start', 'middle', 'end'],
3747
self.conf.get('list', expand=True))
3749
def test_pathologically_hidden_list(self):
3750
self.conf.store._load_from_string('''
3756
hidden={start}{middle}{end}
3758
# What matters is what the registration says, the conversion happens
3759
# only after all expansions have been performed
3760
self.registry.register(config.ListOption('hidden'))
3761
self.assertEquals(['bin', 'go'],
3762
self.conf.get('hidden', expand=True))
3765
class TestStackCrossSectionsExpand(tests.TestCaseWithTransport):
3768
super(TestStackCrossSectionsExpand, self).setUp()
3770
def get_config(self, location, string):
3773
# Since we don't save the config we won't strictly require to inherit
3774
# from TestCaseInTempDir, but an error occurs so quickly...
3775
c = config.LocationStack(location)
3776
c.store._load_from_string(string)
3779
def test_dont_cross_unrelated_section(self):
3780
c = self.get_config('/another/branch/path','''
3785
[/another/branch/path]
3788
self.assertRaises(errors.ExpandingUnknownOption,
3789
c.get, 'bar', expand=True)
3791
def test_cross_related_sections(self):
3792
c = self.get_config('/project/branch/path','''
3796
[/project/branch/path]
3799
self.assertEquals('quux', c.get('bar', expand=True))
3802
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
3804
def test_cross_global_locations(self):
3805
l_store = config.LocationStore()
3806
l_store._load_from_string('''
3812
g_store = config.GlobalStore()
3813
g_store._load_from_string('''
3819
stack = config.LocationStack('/branch')
3820
self.assertEquals('glob-bar', stack.get('lbar', expand=True))
3821
self.assertEquals('loc-foo', stack.get('gfoo', expand=True))
3824
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
3826
def test_expand_locals_empty(self):
3827
l_store = config.LocationStore()
3828
l_store._load_from_string('''
3829
[/home/user/project]
3834
stack = config.LocationStack('/home/user/project/')
3835
self.assertEquals('', stack.get('base', expand=True))
3836
self.assertEquals('', stack.get('rel', expand=True))
3838
def test_expand_basename_locally(self):
3839
l_store = config.LocationStore()
3840
l_store._load_from_string('''
3841
[/home/user/project]
3845
stack = config.LocationStack('/home/user/project/branch')
3846
self.assertEquals('branch', stack.get('bfoo', expand=True))
3848
def test_expand_basename_locally_longer_path(self):
3849
l_store = config.LocationStore()
3850
l_store._load_from_string('''
3855
stack = config.LocationStack('/home/user/project/dir/branch')
3856
self.assertEquals('branch', stack.get('bfoo', expand=True))
3858
def test_expand_relpath_locally(self):
3859
l_store = config.LocationStore()
3860
l_store._load_from_string('''
3861
[/home/user/project]
3862
lfoo = loc-foo/{relpath}
3865
stack = config.LocationStack('/home/user/project/branch')
3866
self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
3868
def test_expand_relpath_unknonw_in_global(self):
3869
g_store = config.GlobalStore()
3870
g_store._load_from_string('''
3875
stack = config.LocationStack('/home/user/project/branch')
3876
self.assertRaises(errors.ExpandingUnknownOption,
3877
stack.get, 'gfoo', expand=True)
3879
def test_expand_local_option_locally(self):
3880
l_store = config.LocationStore()
3881
l_store._load_from_string('''
3882
[/home/user/project]
3883
lfoo = loc-foo/{relpath}
3887
g_store = config.GlobalStore()
3888
g_store._load_from_string('''
3894
stack = config.LocationStack('/home/user/project/branch')
3895
self.assertEquals('glob-bar', stack.get('lbar', expand=True))
3896
self.assertEquals('loc-foo/branch', stack.get('gfoo', expand=True))
3898
def test_locals_dont_leak(self):
3899
"""Make sure we chose the right local in presence of several sections.
3901
l_store = config.LocationStore()
3902
l_store._load_from_string('''
3904
lfoo = loc-foo/{relpath}
3905
[/home/user/project]
3906
lfoo = loc-foo/{relpath}
3909
stack = config.LocationStack('/home/user/project/branch')
3910
self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
3911
stack = config.LocationStack('/home/user/bar/baz')
3912
self.assertEquals('loc-foo/bar/baz', stack.get('lfoo', expand=True))
3238
3916
class TestStackSet(TestStackWithTransport):
3240
3918
def test_simple_set(self):
3241
3919
conf = self.get_stack(self)
3242
conf.store._load_from_string('foo=bar')
3243
self.assertEquals('bar', conf.get('foo'))
3920
self.assertEquals(None, conf.get('foo'))
3244
3921
conf.set('foo', 'baz')
3245
3922
# Did we get it back ?
3246
3923
self.assertEquals('baz', conf.get('foo'))