summaryrefslogtreecommitdiffstats
path: root/tests/test_git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_git_config.py')
-rw-r--r--tests/test_git_config.py70
1 files changed, 67 insertions, 3 deletions
diff --git a/tests/test_git_config.py b/tests/test_git_config.py
index 964bc324..3300c12f 100644
--- a/tests/test_git_config.py
+++ b/tests/test_git_config.py
@@ -15,6 +15,7 @@
15"""Unittests for the git_config.py module.""" 15"""Unittests for the git_config.py module."""
16 16
17import os 17import os
18import tempfile
18import unittest 19import unittest
19 20
20import git_config 21import git_config
@@ -26,9 +27,8 @@ def fixture(*paths):
26 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) 27 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
27 28
28 29
29class GitConfigUnitTest(unittest.TestCase): 30class GitConfigReadOnlyTests(unittest.TestCase):
30 """Tests the GitConfig class. 31 """Read-only tests of the GitConfig class."""
31 """
32 32
33 def setUp(self): 33 def setUp(self):
34 """Create a GitConfig object using the test.gitconfig fixture. 34 """Create a GitConfig object using the test.gitconfig fixture.
@@ -105,5 +105,69 @@ class GitConfigUnitTest(unittest.TestCase):
105 self.assertEqual(value, self.config.GetInt('section.%s' % (key,))) 105 self.assertEqual(value, self.config.GetInt('section.%s' % (key,)))
106 106
107 107
108class GitConfigReadWriteTests(unittest.TestCase):
109 """Read/write tests of the GitConfig class."""
110
111 def setUp(self):
112 self.tmpfile = tempfile.NamedTemporaryFile()
113 self.config = self.get_config()
114
115 def get_config(self):
116 """Get a new GitConfig instance."""
117 return git_config.GitConfig(self.tmpfile.name)
118
119 def test_SetString(self):
120 """Test SetString behavior."""
121 # Set a value.
122 self.assertIsNone(self.config.GetString('foo.bar'))
123 self.config.SetString('foo.bar', 'val')
124 self.assertEqual('val', self.config.GetString('foo.bar'))
125
126 # Make sure the value was actually written out.
127 config = self.get_config()
128 self.assertEqual('val', config.GetString('foo.bar'))
129
130 # Update the value.
131 self.config.SetString('foo.bar', 'valll')
132 self.assertEqual('valll', self.config.GetString('foo.bar'))
133 config = self.get_config()
134 self.assertEqual('valll', config.GetString('foo.bar'))
135
136 # Delete the value.
137 self.config.SetString('foo.bar', None)
138 self.assertIsNone(self.config.GetString('foo.bar'))
139 config = self.get_config()
140 self.assertIsNone(config.GetString('foo.bar'))
141
142 def test_SetBoolean(self):
143 """Test SetBoolean behavior."""
144 # Set a true value.
145 self.assertIsNone(self.config.GetBoolean('foo.bar'))
146 for val in (True, 1):
147 self.config.SetBoolean('foo.bar', val)
148 self.assertTrue(self.config.GetBoolean('foo.bar'))
149
150 # Make sure the value was actually written out.
151 config = self.get_config()
152 self.assertTrue(config.GetBoolean('foo.bar'))
153 self.assertEqual('true', config.GetString('foo.bar'))
154
155 # Set a false value.
156 for val in (False, 0):
157 self.config.SetBoolean('foo.bar', val)
158 self.assertFalse(self.config.GetBoolean('foo.bar'))
159
160 # Make sure the value was actually written out.
161 config = self.get_config()
162 self.assertFalse(config.GetBoolean('foo.bar'))
163 self.assertEqual('false', config.GetString('foo.bar'))
164
165 # Delete the value.
166 self.config.SetBoolean('foo.bar', None)
167 self.assertIsNone(self.config.GetBoolean('foo.bar'))
168 config = self.get_config()
169 self.assertIsNone(config.GetBoolean('foo.bar'))
170
171
108if __name__ == '__main__': 172if __name__ == '__main__':
109 unittest.main() 173 unittest.main()