diff options
author | Julien Kauffmann <julien.kauffmann@freelan.org> | 2012-02-08 08:51:48 +0100 |
---|---|---|
committer | Julien Kauffmann <julien.kauffmann@freelan.org> | 2012-02-08 09:57:00 +0100 |
commit | d78a82dc7cde20bb1010a4a4dbd6a48f6c1e37bb (patch) | |
tree | 00c2c1a8d5c5da86e0fe1c431be46045d97f5c2c | |
parent | 6e86f8a8a0638abe2c18ae0bb36cc992b0ababe5 (diff) | |
download | gitpython-d78a82dc7cde20bb1010a4a4dbd6a48f6c1e37bb.tar.gz |
Added test for backslahed/quoted values
-rw-r--r-- | git/test/fixtures/git_config_values | 4 | ||||
-rw-r--r-- | git/test/test_config.py | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/git/test/fixtures/git_config_values b/git/test/fixtures/git_config_values new file mode 100644 index 00000000..5ba039ef --- /dev/null +++ b/git/test/fixtures/git_config_values @@ -0,0 +1,4 @@ +[values] + backslash = some\\data + quote = this is a \"quoted value\" + quoted = "all" "your \"quotes\" a"re bel"ong to """"us" diff --git a/git/test/test_config.py b/git/test/test_config.py index d2e199e3..b37db290 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -101,4 +101,28 @@ class TestConfig(TestBase): # it raises if there is no default though self.failUnlessRaises(NoSectionError, r_config.get_value, "doesnt", "exist") - + def test_values(self): + file_obj = self._to_memcache(fixture_path("git_config_values")) + w_config = GitConfigParser(file_obj, read_only = False) + w_config.write() # enforce writing + orig_value = file_obj.getvalue() + + # Reading must unescape backslashes + backslash = w_config.get('values', 'backslash') + assert backslash == r'some\data' + + # Reading must unescape quotes + quote = w_config.get('values', 'quote') + assert quote == 'this is a "quoted value"' + + # Reading must remove surrounding quotes + quoted = w_config.get('values', 'quoted') + assert quoted == 'all your "quotes" are belong to us' + + # Writing must escape backslashes and quotes + w_config.set('values', 'backslash', backslash) + w_config.set('values', 'quote', quote) + w_config.write() # enforce writing + + # Contents shouldn't differ + assert file_obj.getvalue() == orig_value |