diff options
author | Mike Frysinger <vapier@google.com> | 2021-02-09 23:14:41 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2021-02-11 01:48:12 +0000 |
commit | 38867fb6d38d45a11271d6ef492e4d40066b078f (patch) | |
tree | 99778a43a5007322414ecd8b7c290842a4bc3fc6 /tests | |
parent | ce64e3d47b97e54cc7fac3d7577cd53f1857de26 (diff) | |
download | git-repo-38867fb6d38d45a11271d6ef492e4d40066b078f.tar.gz |
git_config: add SetBoolean helper
A little sugar simplifies the code a bit.
Change-Id: Ie2b8a965faa9f9ca05c7be479d03e8e073cd816d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296522
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_git_config.py | 70 |
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 | ||
17 | import os | 17 | import os |
18 | import tempfile | ||
18 | import unittest | 19 | import unittest |
19 | 20 | ||
20 | import git_config | 21 | import 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 | ||
29 | class GitConfigUnitTest(unittest.TestCase): | 30 | class 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 | ||
108 | class 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 | |||
108 | if __name__ == '__main__': | 172 | if __name__ == '__main__': |
109 | unittest.main() | 173 | unittest.main() |