Rev 5581: Kidding, here are the tests. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sun Feb 20 11:07:56 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5581
revision-id: v.ladeuil+lp at free.fr-20110220110756-hkmbkxj6hcc2s4go
parent: v.ladeuil+lp at free.fr-20110219213628-dhbyohwm5kz9uq66
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: expand-options
timestamp: Sun 2011-02-20 12:07:56 +0100
message:
  Kidding, here are the tests.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-02-19 21:36:28 +0000
+++ b/bzrlib/config.py	2011-02-20 11:07:56 +0000
@@ -160,6 +160,7 @@
 # -- vila 20110219
 _expand_default_value = None
 def _get_expand_default_value():
+    global _expand_default_value
     if _expand_default_value is not None:
         return _expand_default_value
     conf = GlobalConfig()
@@ -170,6 +171,7 @@
         # This is an opt-in feature, you *really* need to clearly say you want
         # to activate it !
         expand = False
+    _expand_default_value = expand
     return expand
 
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-02-11 17:12:35 +0000
+++ b/bzrlib/tests/__init__.py	2011-02-20 11:07:56 +0000
@@ -954,6 +954,10 @@
         # between tests.  We should get rid of this altogether: bug 656694. --
         # mbp 20101008
         self.overrideAttr(bzrlib.trace, '_verbosity_level', 0)
+        # Isolate config option expansion until its default value for bzrlib is
+        # settled on or a the FIXME associated with _get_expand_default_value
+        # is addressed -- vila 20110219
+        self.overrideAttr(config, '_expand_default_value', None)
 
     def debug(self):
         # debug a frame up.

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-02-19 20:59:00 +0000
+++ b/bzrlib/tests/test_config.py	2011-02-20 11:07:56 +0000
@@ -528,6 +528,63 @@
         self.assertFileEqual(content, 'test.conf')
 
 
+class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
+    """What is the default value of expand for config options.
+
+    This is an opt-in beta feature used to evaluate whether or not option
+    references can appear in dangerous place raising exceptions, disapearing
+    (and as such corrupting data) or if it's safe to activate the option by
+    default.
+
+    Note that these tests relies on config._expand_default_value being already
+    overwritten in the parent class setUp.
+    """
+
+    def setUp(self):
+        super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
+        self.config = None
+        self.warnings = []
+        def warning(*args):
+            self.warnings.append(args[0] % args[1:])
+        self.overrideAttr(trace, 'warning', warning)
+
+    def get_config(self, expand):
+        c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
+                                            save=True)
+        return c
+
+    def assertExpandIs(self, expected):
+        actual = config._get_expand_default_value()
+        #self.config.get_user_option_as_bool('bzr.config.expand')
+        self.assertEquals(expected, actual)
+
+    def test_default_is_None(self):
+        self.assertEquals(None, config._expand_default_value)
+
+    def test_default_is_False_even_if_None(self):
+        self.config = self.get_config(None)
+        self.assertExpandIs(False)
+
+    def test_default_is_False_even_if_invalid(self):
+        self.config = self.get_config('<your choice>')
+        self.assertExpandIs(False)
+        # ...
+        # Huh ? My choice is False ? Thanks, always happy to hear that :D
+        # Wait, you've been warned !
+        self.assertLength(1, self.warnings)
+        self.assertEquals(
+            'Value "<your choice>" is not a boolean for "bzr.config.expand"',
+            self.warnings[0])
+
+    def test_default_is_True(self):
+        self.config = self.get_config(True)
+        self.assertExpandIs(True)
+        
+    def test_default_is_False(self):
+        self.config = self.get_config(False)
+        self.assertExpandIs(False)
+        
+
 class TestIniConfigOptionExpansion(tests.TestCase):
     """Test option expansion from the IniConfig level.
 



More information about the bazaar-commits mailing list