comparison commons/core/checker/test/Test_ConfigValue.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
1 import unittest
2 from commons.core.checker.ConfigValue import ConfigValue
3
4 class Test_ConfigValue(unittest.TestCase):
5
6 def setUp(self):
7 self._iConfigValue = ConfigValue()
8
9 def test__eq__True(self):
10 self._iConfigValue.dOptionsValues4Sections = {
11 "dir_name" : {"work_dir":"toto"},
12 "organism" : {"abbreviation":"T.aestivum",
13 "genus":"triticum",
14 "species":"aestivum",
15 "common_name":"wheat",
16 "comment":""}
17 }
18 iConfigValue1 = ConfigValue()
19 iConfigValue1.dOptionsValues4Sections = {
20 "dir_name" : {"work_dir":"toto"},
21 "organism" : {"abbreviation":"T.aestivum",
22 "genus":"triticum",
23 "species":"aestivum",
24 "common_name":"wheat",
25 "comment":""}
26 }
27
28 self.assertEqual(self._iConfigValue, iConfigValue1)
29
30 def test__eq__False_not_same_section(self):
31 self._iConfigValue.dOptionsValues4Sections = {
32 "dir_name" : {"work_dir":"toto"},
33 "organisms" : {"abbreviation":"T.aestivum",
34 "genus":"triticum",
35 "species":"aestivum",
36 "common_name":"wheat",
37 "comment":""}
38 }
39 iConfigValue1 = ConfigValue()
40 iConfigValue1.dOptionsValues4Sections = {
41 "dir_name" : {"work_dir":"toto"},
42 "organism" : {"abbreviation":"T.aestivum",
43 "genus":"triticum",
44 "species":"aestivum",
45 "common_name":"wheat",
46 "comment":""}
47 }
48
49 self.assertNotEqual(self._iConfigValue, iConfigValue1)
50
51
52 def test__eq__False_not_same_option(self):
53 self._iConfigValue.dOptionsValues4Sections = {
54 "dir_name" : {"work_dir":"toto"},
55 "organism" : {"abbreviation":"T.aestivum",
56 "family":"triticum",
57 "species":"aestivum",
58 "common_name":"wheat",
59 "comment":""}
60 }
61 iConfigValue1 = ConfigValue()
62 iConfigValue1.dOptionsValues4Sections = {
63 "dir_name" : {"work_dir":"toto"},
64 "organism" : {"abbreviation":"T.aestivum",
65 "genus":"triticum",
66 "species":"aestivum",
67 "common_name":"wheat",
68 "comment":""}
69 }
70
71 self.assertNotEqual(self._iConfigValue, iConfigValue1)
72
73 def test__eq__False_not_same_value(self):
74 self._iConfigValue.dOptionsValues4Sections = {
75 "dir_name" : {"work_dir":"toto"},
76 "organism" : {"abbreviation":"T.aestivum",
77 "genus":"vitis",
78 "species":"aestivum",
79 "common_name":"wheat",
80 "comment":""}
81 }
82 iConfigValue1 = ConfigValue()
83 iConfigValue1.dOptionsValues4Sections = {
84 "dir_name" : {"work_dir":"toto"},
85 "organism" : {"abbreviation":"T.aestivum",
86 "genus":"triticum",
87 "species":"aestivum",
88 "common_name":"wheat",
89 "comment":""}
90 }
91
92 self.assertNotEqual(self._iConfigValue, iConfigValue1)
93
94 def test_has_section_true(self):
95 self._iConfigValue.dOptionsValues4Sections = {
96 "dir_name" : {"work_dir":"toto"},
97 "organism" : {"abbreviation":"T.aestivum",
98 "genus":"triticum",
99 "species":"aestivum",
100 "common_name":"wheat",
101 "comment":""}
102 }
103
104 obsSectionExist = self._iConfigValue.has_section("organism")
105 self.assertTrue(obsSectionExist)
106
107 def test_has_section_false(self):
108 self._iConfigValue.dOptionsValues4Sections = {
109 "dir_name" : {"work_dir":"toto"},
110 "organism" : {"abbreviation":"T.aestivum",
111 "genus":"triticum",
112 "species":"aestivum",
113 "common_name":"wheat",
114 "comment":""}
115 }
116
117 obsSectionExist = self._iConfigValue.has_section("toto")
118 self.assertFalse(obsSectionExist)
119
120 def test_has_option_true(self):
121 self._iConfigValue.dOptionsValues4Sections = {
122 "dir_name" : {"work_dir":"toto"},
123 "organism" : {"abbreviation":"T.aestivum",
124 "genus":"triticum",
125 "species":"aestivum",
126 "common_name":"wheat",
127 "comment":""}
128 }
129
130 obsOptionExist = self._iConfigValue.has_option("organism","genus")
131 self.assertTrue(obsOptionExist)
132
133 def test_has_option_false(self):
134 self._iConfigValue.dOptionsValues4Sections = {
135 "dir_name" : {"work_dir":"toto"},
136 "organism" : {"abbreviation":"T.aestivum",
137 "genus":"triticum",
138 "species":"aestivum",
139 "common_name":"wheat",
140 "comment":""}
141 }
142
143 obsOptionExist = self._iConfigValue.has_option("organism","toto")
144 self.assertFalse(obsOptionExist)
145 obsOptionExist = self._iConfigValue.has_option("toto","genus")
146 self.assertFalse(obsOptionExist)
147
148 def test_sections(self):
149 self._iConfigValue.dOptionsValues4Sections = {
150 "dir_name" : {"work_dir":"toto"},
151 "organism" : {"abbreviation":"T.aestivum",
152 "genus":"triticum",
153 "species":"aestivum",
154 "common_name":"wheat",
155 "comment":""}
156 }
157 expListSections = ["dir_name", "organism"]
158 obsListSections = self._iConfigValue.sections()
159 self.assertEquals(expListSections, obsListSections)
160
161 def test_sections_empty_config(self):
162 self._iConfigValue.dOptionsValues4Sections = {}
163 expListSections = []
164 obsListSections = self._iConfigValue.sections()
165 self.assertEquals(expListSections, obsListSections)
166
167 def test_options(self):
168 self._iConfigValue.dOptionsValues4Sections = {
169 "dir_name" : {"work_dir":"toto"},
170 "organism" : {"abbreviation":"T.aestivum",
171 "genus":"triticum",
172 "species":"aestivum",
173 "common_name":"wheat",
174 "comment":""}
175 }
176 expListOptions = ['abbreviation', 'common_name', 'genus', 'species', 'comment']
177 obsListOptions = self._iConfigValue.options("organism")
178 self.assertEquals(expListOptions, obsListOptions)
179
180 expListOptions = ["work_dir"]
181 obsListOptions = self._iConfigValue.options("dir_name")
182 self.assertEquals(expListOptions, obsListOptions)
183
184 def test_options_empty_config(self):
185 self._iConfigValue.dOptionsValues4Sections = {}
186 expListOptions = []
187 obsListOptions = self._iConfigValue.options("toto")
188 self.assertEquals(expListOptions, obsListOptions)
189
190 def test_set(self):
191 self._iConfigValue.dOptionsValues4Sections = {}
192 expDictOptionsValue = {"dir_name" : {"work_dir":"toto"}}
193 self._iConfigValue.set("dir_name", "work_dir", "toto")
194 obsDictOptionsValue = self._iConfigValue.dOptionsValues4Sections
195 self.assertEquals(expDictOptionsValue, obsDictOptionsValue)
196
197 def test_get(self):
198 self._iConfigValue.dOptionsValues4Sections = {
199 "dir_name" : {"work_dir":"toto"},
200 "organism" : {"abbreviation":"T.aestivum",
201 "genus":"triticum",
202 "species":"aestivum",
203 "common_name":"wheat",
204 "comment":""}
205 }
206 expValue = "aestivum"
207 obsValue = self._iConfigValue.get("organism", "species")
208 self.assertEquals(expValue, obsValue)
209 expValue = None
210 obsValue = self._iConfigValue.get("toto", "species")
211 self.assertEquals(expValue, obsValue)
212 expValue = None
213 obsValue = self._iConfigValue.get("organism", "dummyopt")
214 self.assertEquals(expValue, obsValue)
215
216 if __name__ == "__main__":
217 unittest.main()