Rev 6387: Add tests for Store quoting/unquoting in file:///home/vila/src/bzr/bugs/906897-quoting-stores/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Dec 21 10:01:13 UTC 2011


At file:///home/vila/src/bzr/bugs/906897-quoting-stores/

------------------------------------------------------------
revno: 6387
revision-id: v.ladeuil+lp at free.fr-20111221100112-rdirmrc13yn3fnl7
parent: v.ladeuil+lp at free.fr-20111221085241-d6971vcz327saju1
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 906897-quoting-stores
timestamp: Wed 2011-12-21 11:01:12 +0100
message:
  Add tests for Store quoting/unquoting
-------------- next part --------------
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-12-21 08:52:41 +0000
+++ b/bzrlib/tests/test_config.py	2011-12-21 10:01:12 +0000
@@ -21,7 +21,7 @@
 import sys
 import threading
 
-
+import testtools
 from testtools import matchers
 
 #import bzrlib specific imports here
@@ -2670,6 +2670,63 @@
         self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
 
 
+class TestStoreQuoting(TestStore):
+
+    scenarios = [(key, {'get_store': builder}) for key, builder
+                 in config.test_store_builder_registry.iteritems()]
+
+    def setUp(self):
+        super(TestStoreQuoting, self).setUp()
+        self.store = self.get_store(self)
+        # We need a loaded store but any content will do
+        self.store._load_from_string('')
+
+    def assertIdempotent(self, s):
+        """Assert that quoting an unquoted string is a no-op and vice-versa.
+
+        What matters here is that option values, as they appear in a store, can
+        be safely round-tripped out of the store and back.
+
+        :param s: A string, quoted if required.
+        """
+        self.assertEquals(s, self.store.quote(self.store.unquote(s)))
+        self.assertEquals(s, self.store.unquote(self.store.quote(s)))
+
+    def test_empty_string(self):
+        if isinstance(self.store, config.IniFileStore):
+            # configobj._quote doesn't handle empty values
+            with testtools.ExpectedException(AssertionError):
+                self.assertIdempotent('')
+        else:
+            self.assertIdempotent('')
+        # But quoted empty strings are ok
+        self.assertIdempotent('""')
+
+    def test_embedded_spaces(self):
+        self.assertIdempotent('" a b c "')
+
+    def test_embedded_commas(self):
+        self.assertIdempotent('" a , b c "')
+
+    def test_simple_comma(self):
+        if isinstance(self.store, config.IniFileStore):
+            # configobj requires that lists are special-cased
+            with testtools.ExpectedException(AssertionError):
+                self.assertIdempotent(',')
+        else:
+            self.assertIdempotent(',')
+        # When a single comma is required, quoting is also required
+        self.assertIdempotent('","')
+
+    def test_list(self):
+        if isinstance(self.store, config.IniFileStore):
+            # configobj requires that lists are special-cased
+            with testtools.ExpectedException(AssertionError):
+                self.assertIdempotent('a,b')
+        else:
+            self.assertIdempotent('a,b')
+
+
 class TestIniFileStoreContent(tests.TestCaseWithTransport):
     """Simulate loading a config store with content of various encodings.
 

=== modified file 'doc/developers/configuration.txt'
--- a/doc/developers/configuration.txt	2011-12-21 08:52:41 +0000
+++ b/doc/developers/configuration.txt	2011-12-21 10:01:12 +0000
@@ -205,7 +205,10 @@
 
 The value of an option is a unicode string or ``None`` if it's not
 defined. By using ``from_unicode`` you can turn this string into a more
-appropriate representation (a list of unicode strings for example).
+appropriate representation.
+
+If you need a list value, you should use ``ListOption`` instead.
+
 
 Sections
 --------



More information about the bazaar-commits mailing list