6 from git_stats
import config
14 TestGetDefaultConfigPaths
,
18 class TestRead(unittest
.TestCase
):
19 """Tests the read function of the config module
26 " camelCaseCoreSetting = eggs",
29 " camelCaseSetting = camelCaseValue"
39 self
.multiple_empty_configs
= [
48 self
.multiple_configs
= [
56 " core_setting = foo",
60 " color_setting = bar",
65 def testNoConvert(self
):
66 """Test the readConfig method with no converting
69 result
= config
.read(self
.lines
, convert_camel_case
=False)
74 "Regular setting not properly parsed")
78 result
["camelCaseSetting"],
79 "Camel case setting not properly parsed")
83 "Non GitStats setting was parsed")
86 "camelCaseCoreSetting" in result
,
87 "Camel case non GitStats setting was parsed")
89 def testWithConvert(self
):
90 """Test the readConfig method with converting enabled
93 result
= config
.read(self
.lines
, convert_camel_case
=True)
98 "Regular setting not properly parsed")
100 self
.failUnlessEqual(
102 result
["camel_case_setting"],
103 "Camel case setting not properly parsed")
107 "Non GitStats setting was parsed")
110 "camelCaseCoreSetting" in result
,
111 "Camel case non GitStats setting was parsed")
114 """Test the readConfig method with no contents
117 result
= config
.read(self
.empty
)
121 "Empty config did not yield an empty result")
123 def testEmptyConfig(self
):
124 """Test the readConfig method with an empty config
127 result
= config
.read(self
.empty_config
)
131 "Empty config did not yield an empty result")
133 def testMultipleEmptyConfigs(self
):
134 """Test the readConfig method with multiple empty configs
137 result
= config
.read(self
.multiple_empty_configs
)
141 "Multiple empty configs did not yield an empty result")
143 def testMultipleConfigs(self
):
144 """Test the readConfig method with multiple verses
147 result
= config
.read(self
.multiple_configs
)
149 self
.failUnlessEqual(
152 "Parsed result did not contain 5 values")
155 self
.failUnlessEqual(
157 result
["setting%d" % i
],
158 "Config value for setting%d did not match value%d." % (i
,i
))
160 class TestGetDefaultConfigPaths(unittest
.TestCase
):
161 """Tests the getDefaultConfigPaths method of the config module
165 self
.result
= config
._getDefaultConfigPaths
()
167 def testContainsConfig(self
):
168 """Tests that the plain "config" file is included
172 "config" in self
.result
,
173 "The plain 'config' file is not in the default paths")
175 def testContainsGitConfig(self
):
176 """Test that the .git/config file is included
180 any(s
.endswith('.git/config') for s
in self
.result
),
181 "The ./git/config file is not in the default paths")
183 def testContainsGitconfig(self
):
184 """Test that the .gitconfig file is included
188 any(s
.endswith('.gitconfig') for s
in self
.result
),
189 "The .gitconfig file is not in the default paths")
191 class TestReadConfigPaths(unittest
.TestCase
):
192 """Test the readConfigPaths method of the config module
198 " option1 = value1\n",
199 " option2 = value2\n",
202 file = open("config1", "w")
203 file.writelines(lines
)
207 " option2 = anothervalue2\n",
208 " option3 = anothervalue3\n",
211 file = open("config2", "w")
212 file.writelines(lines
)
218 def testReadMultipleValues(self
):
219 """Tests if all values were read in
222 paths
= ["config1", "config2"]
224 result
= config
._readConfigPaths
(paths
, False)
226 self
.failUnlessEqual(
229 "Value of 'option1', present in only one file, not read in properly")
234 "Value of 'option2' not properly overriden by second file")
236 self
.failUnlessEqual(
239 "Value of 'option2' not retreived properly")
241 self
.failUnlessEqual(
244 "Value of 'option3', present in only one file, not read in properly")