553
554
self.assertFileEqual(content, 'test.conf')
557
class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
558
"""What is the default value of expand for config options.
560
This is an opt-in beta feature used to evaluate whether or not option
561
references can appear in dangerous place raising exceptions, disapearing
562
(and as such corrupting data) or if it's safe to activate the option by
565
Note that these tests relies on config._expand_default_value being already
566
overwritten in the parent class setUp.
570
super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
574
self.warnings.append(args[0] % args[1:])
575
self.overrideAttr(trace, 'warning', warning)
577
def get_config(self, expand):
578
c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
582
def assertExpandIs(self, expected):
583
actual = config._get_expand_default_value()
584
#self.config.get_user_option_as_bool('bzr.config.expand')
585
self.assertEquals(expected, actual)
587
def test_default_is_None(self):
588
self.assertEquals(None, config._expand_default_value)
590
def test_default_is_False_even_if_None(self):
591
self.config = self.get_config(None)
592
self.assertExpandIs(False)
594
def test_default_is_False_even_if_invalid(self):
595
self.config = self.get_config('<your choice>')
596
self.assertExpandIs(False)
598
# Huh ? My choice is False ? Thanks, always happy to hear that :D
599
# Wait, you've been warned !
600
self.assertLength(1, self.warnings)
602
'Value "<your choice>" is not a boolean for "bzr.config.expand"',
605
def test_default_is_True(self):
606
self.config = self.get_config(True)
607
self.assertExpandIs(True)
609
def test_default_is_False(self):
610
self.config = self.get_config(False)
611
self.assertExpandIs(False)
614
class TestIniConfigOptionExpansion(tests.TestCase):
615
"""Test option expansion from the IniConfig level.
617
What we really want here is to test the Config level, but the class being
618
abstract as far as storing values is concerned, this can't be done
621
# FIXME: This should be rewritten when all configs share a storage
622
# implementation -- vila 2011-02-18
624
def get_config(self, string=None):
627
c = config.IniBasedConfig.from_string(string)
630
def assertExpansion(self, expected, conf, string, env=None):
631
self.assertEquals(expected, conf.expand_options(string, env))
633
def test_no_expansion(self):
634
c = self.get_config('')
635
self.assertExpansion('foo', c, 'foo')
637
def test_env_adding_options(self):
638
c = self.get_config('')
639
self.assertExpansion('bar', c, '{foo}', {'foo': 'bar'})
641
def test_env_overriding_options(self):
642
c = self.get_config('foo=baz')
643
self.assertExpansion('bar', c, '{foo}', {'foo': 'bar'})
645
def test_simple_ref(self):
646
c = self.get_config('foo=xxx')
647
self.assertExpansion('xxx', c, '{foo}')
649
def test_unknown_ref(self):
650
c = self.get_config('')
651
self.assertRaises(errors.ExpandingUnknownOption,
652
c.expand_options, '{foo}')
654
def test_indirect_ref(self):
655
c = self.get_config('''
659
self.assertExpansion('xxx', c, '{bar}')
661
def test_embedded_ref(self):
662
c = self.get_config('''
666
self.assertExpansion('xxx', c, '{{bar}}')
668
def test_simple_loop(self):
669
c = self.get_config('foo={foo}')
670
self.assertRaises(errors.OptionExpansionLoop, c.expand_options, '{foo}')
672
def test_indirect_loop(self):
673
c = self.get_config('''
677
e = self.assertRaises(errors.OptionExpansionLoop,
678
c.expand_options, '{foo}')
679
self.assertEquals('foo->bar->baz', e.refs)
680
self.assertEquals('{foo}', e.string)
683
conf = self.get_config('''
687
list={foo},{bar},{baz}
689
self.assertEquals(['start', 'middle', 'end'],
690
conf.get_user_option('list', expand=True))
692
def test_cascading_list(self):
693
conf = self.get_config('''
699
self.assertEquals(['start', 'middle', 'end'],
700
conf.get_user_option('list', expand=True))
702
def test_pathological_hidden_list(self):
703
conf = self.get_config('''
709
hidden={start}{middle}{end}
711
# Nope, it's either a string or a list, and the list wins as soon as a
712
# ',' appears, so the string concatenation never occur.
713
self.assertEquals(['{foo', '}', '{', 'bar}'],
714
conf.get_user_option('hidden', expand=True))
716
class TestLocationConfigOptionExpansion(tests.TestCaseInTempDir):
718
def get_config(self, location, string=None):
721
# Since we don't save the config we won't strictly require to inherit
722
# from TestCaseInTempDir, but an error occurs so quickly...
723
c = config.LocationConfig.from_string(string, location)
726
def test_dont_cross_unrelated_section(self):
727
c = self.get_config('/another/branch/path','''
732
[/another/branch/path]
735
self.assertRaises(errors.ExpandingUnknownOption,
736
c.get_user_option, 'bar', expand=True)
738
def test_cross_related_sections(self):
739
c = self.get_config('/project/branch/path','''
743
[/project/branch/path]
746
self.assertEquals('quux', c.get_user_option('bar', expand=True))
556
749
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
558
751
def test_cannot_reload_without_name(self):