Rev 5555: Add a failing test for InterpolationLoop, we need some refactoring first. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Dec 22 16:01:16 GMT 2010


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

------------------------------------------------------------
revno: 5555
revision-id: v.ladeuil+lp at free.fr-20101222160116-kd3nifr8ypb1zro0
parent: v.ladeuil+lp at free.fr-20101222142028-vh6df9cnna7keuaq
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: interpolate
timestamp: Wed 2010-12-22 17:01:16 +0100
message:
  Add a failing test for InterpolationLoop, we need some refactoring first.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-12-22 14:20:28 +0000
+++ b/bzrlib/config.py	2010-12-22 16:01:16 +0000
@@ -159,12 +159,14 @@
             ref = found.group()
             name = ref[1:-1]
             if env is not None and name in env:
+                # Special case, values provided in env takes precedence over
+                # anything else
                 value = env[name]
-            elif name in self:
-                # Search for an option
+            else:
+                # FIXME: This is a limited implementation, what we really need
+                # is a way to query the bzr config for the value of an option,
+                # respecting the scope rules.
                 value = self[name]
-            else:
-                raise UnkownOption(name)
             string = string.replace(ref, value)
         return string
 

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2010-12-16 20:41:47 +0000
+++ b/bzrlib/errors.py	2010-12-22 16:01:16 +0000
@@ -3218,3 +3218,12 @@
     def __init__(self, branch_url):
         self.branch_url = branch_url
 
+# FIXME: I would prefer to define the config related exception classes in
+# config.py but the lazy import mechanism proscribe this.
+class InterpolationLoop(BzrError):
+
+    _fmt = 'Loop involving %(refs)s while evaluating %(string)s.'
+
+    def __init__(self, string, refs):
+        self.string = string
+        self.refs = '->'.join(refs)

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2010-12-22 14:20:28 +0000
+++ b/bzrlib/tests/test_config.py	2010-12-22 16:01:16 +0000
@@ -351,20 +351,30 @@
         c = self.get_config('')
         self.assertInterpolate('foo', c, 'foo')
 
-    def test_interpolate_in_env(self):
+    def test_in_env(self):
         c = self.get_config('')
         self.assertInterpolate('bar', c, '{foo}', {'foo': 'bar'})
 
-    def test_interpolate_simple_ref(self):
+    def test_simple_ref(self):
         c = self.get_config('foo=xxx')
         self.assertInterpolate('xxx', c, '{foo}')
 
-    def test_interpolate_indirect_ref(self):
+    def test_indirect_ref(self):
         c = self.get_config("""foo=xxx
 bar={foo}
 """)
         self.assertInterpolate('xxx', c, '{bar}')
 
+    def test_embedded_ref(self):
+        c = self.get_config("""foo=xxx
+bar=foo
+""")
+        self.assertInterpolate('xxx', c, '{{bar}}')
+
+    def test_simple_loop(self):
+        c = self.get_config('foo=food')
+        self.assertRaises(errors.InterpolationLoop, c.interpolate, '{foo}')
+
 
 class TestConfig(tests.TestCase):
 



More information about the bazaar-commits mailing list