Fix unescaping values.
[jelmer/dulwich.git] / dulwich / tests / test_config.py
1 # test_config.py -- Tests for reading and writing configuration files
2 # Copyright (C) 2011 Jelmer Vernooij <jelmer@samba.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # or (at your option) a later version of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA  02110-1301, USA.
18
19 """Tests for reading and writing configuraiton files."""
20
21 from cStringIO import StringIO
22 from dulwich.config import (
23     ConfigDict,
24     ConfigFile,
25     StackedConfig,
26     _unescape_value,
27     )
28 from dulwich.tests import TestCase
29
30
31 class ConfigFileTests(TestCase):
32
33     def from_file(self, text):
34         return ConfigFile.from_file(StringIO(text))
35
36     def test_empty(self):
37         ConfigFile()
38
39     def test_eq(self):
40         self.assertEquals(ConfigFile(), ConfigFile())
41
42     def test_from_file_empty(self):
43         cf = self.from_file("")
44         self.assertEquals(ConfigFile(), cf)
45
46
47 class ConfigDictTests(TestCase):
48
49     def test_get_set(self):
50         cd = ConfigDict()
51         self.assertRaises(KeyError, cd.get, "core.foo")
52         cd.set("core.foo", "bla")
53         self.assertEquals("bla", cd.get("core.foo"))
54         cd.set("core.foo", "bloe")
55         self.assertEquals("bloe", cd.get("core.foo"))
56
57
58 class StackedConfigTests(TestCase):
59
60     def test_default_backends(self):
61         StackedConfig.default_backends()
62
63
64 class UnescapeTests(TestCase):
65
66     def test_nothing(self):
67         self.assertEquals("", _unescape_value(""))
68
69     def test_tab(self):
70         self.assertEquals("\tbar\t", _unescape_value("\\tbar\\t"))
71
72     def test_newline(self):
73         self.assertEquals("\nbar\t", _unescape_value("\\nbar\\t"))
74
75     def test_quote(self):
76         self.assertEquals("\"foo\"", _unescape_value("\\\"foo\\\""))
77