Merge lp:~ricardokirkner/configglue/refactor-options-pep8 into lp:configglue
- refactor-options-pep8
- Merge into trunk
Proposed by
Ricardo Kirkner
Status: | Merged |
---|---|
Approved by: | Ricardo Kirkner |
Approved revision: | 45 |
Merged at revision: | 45 |
Proposed branch: | lp:~ricardokirkner/configglue/refactor-options-pep8 |
Merge into: | lp:configglue |
Diff against target: |
1426 lines (+276/-176) 22 files modified
configglue/__init__.py (+6/-6) configglue/inischema/__init__.py (+13/-6) configglue/inischema/attributed.py (+11/-7) configglue/inischema/glue.py (+6/-6) configglue/inischema/parsers.py (+9/-6) configglue/inischema/typed.py (+8/-7) configglue/pyschema/__init__.py (+6/-6) configglue/pyschema/glue.py (+7/-7) configglue/pyschema/parser.py (+8/-9) configglue/pyschema/schema.py (+12/-10) setup.py (+6/-6) tests/__init__.py (+6/-7) tests/inischema/__init__.py (+6/-6) tests/inischema/test_attributed.py (+9/-6) tests/inischema/test_glue.py (+18/-7) tests/inischema/test_glue2glue.py (+13/-7) tests/inischema/test_parsers.py (+7/-7) tests/inischema/test_typed.py (+20/-6) tests/pyschema/__init__.py (+6/-6) tests/pyschema/test_parser.py (+52/-25) tests/pyschema/test_schema.py (+31/-10) tests/pyschema/test_schemaconfig.py (+16/-13) |
To merge this branch: | bzr merge lp:~ricardokirkner/configglue/refactor-options-pep8 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Kirkner | Approve | ||
Review via email: mp+64405@code.launchpad.net |
Commit message
Applied suggestions from running pep8 as a baseline for the refactoring.
Description of the change
Applied suggestions from running pep8 as a baseline for the refactoring.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configglue/__init__.py' |
2 | --- configglue/__init__.py 2011-04-29 19:47:41 +0000 |
3 | +++ configglue/__init__.py 2011-06-13 13:44:12 +0000 |
4 | @@ -1,18 +1,18 @@ |
5 | ############################################################################### |
6 | -# |
7 | +# |
8 | # configglue -- glue for your apps' configuration |
9 | -# |
10 | +# |
11 | # A library for simple, DRY configuration of applications |
12 | -# |
13 | +# |
14 | # (C) 2009--2010 by Canonical Ltd. |
15 | # originally by John R. Lenton <john.lenton@canonical.com> |
16 | # incorporating schemaconfig as configglue.pyschema |
17 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
18 | -# |
19 | +# |
20 | # Released under the BSD License (see the file LICENSE) |
21 | -# |
22 | +# |
23 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
24 | -# |
25 | +# |
26 | ############################################################################### |
27 | |
28 | __version__ = '0.10' |
29 | |
30 | === modified file 'configglue/inischema/__init__.py' |
31 | --- configglue/inischema/__init__.py 2010-07-31 01:15:59 +0000 |
32 | +++ configglue/inischema/__init__.py 2011-06-13 13:44:12 +0000 |
33 | @@ -1,18 +1,18 @@ |
34 | ############################################################################### |
35 | -# |
36 | +# |
37 | # configglue -- glue for your apps' configuration |
38 | -# |
39 | +# |
40 | # A library for simple, DRY configuration of applications |
41 | -# |
42 | +# |
43 | # (C) 2009--2010 by Canonical Ltd. |
44 | # originally by John R. Lenton <john.lenton@canonical.com> |
45 | # incorporating schemaconfig as configglue.pyschema |
46 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
47 | -# |
48 | +# |
49 | # Released under the BSD License (see the file LICENSE) |
50 | -# |
51 | +# |
52 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
53 | -# |
54 | +# |
55 | ############################################################################### |
56 | |
57 | """configglue -- glue for your apps' configuration |
58 | @@ -69,3 +69,10 @@ |
59 | from .typed import TypedConfigParser |
60 | from .attributed import AttributedConfigParser |
61 | from .glue import configglue |
62 | + |
63 | + |
64 | +__all__ = [ |
65 | + 'TypedConfigParser', |
66 | + 'AttributedConfigParser', |
67 | + 'configglue', |
68 | +] |
69 | |
70 | === modified file 'configglue/inischema/attributed.py' |
71 | --- configglue/inischema/attributed.py 2010-07-31 01:15:59 +0000 |
72 | +++ configglue/inischema/attributed.py 2011-06-13 13:44:12 +0000 |
73 | @@ -1,18 +1,18 @@ |
74 | ############################################################################### |
75 | -# |
76 | +# |
77 | # configglue -- glue for your apps' configuration |
78 | -# |
79 | +# |
80 | # A library for simple, DRY configuration of applications |
81 | -# |
82 | +# |
83 | # (C) 2009--2010 by Canonical Ltd. |
84 | # originally by John R. Lenton <john.lenton@canonical.com> |
85 | # incorporating schemaconfig as configglue.pyschema |
86 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
87 | -# |
88 | +# |
89 | # Released under the BSD License (see the file LICENSE) |
90 | -# |
91 | +# |
92 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
93 | -# |
94 | +# |
95 | ############################################################################### |
96 | |
97 | """ |
98 | @@ -21,7 +21,10 @@ |
99 | import re |
100 | from ConfigParser import RawConfigParser |
101 | |
102 | + |
103 | marker = object() |
104 | + |
105 | + |
106 | class ValueWithAttrs(object): |
107 | """The values returned by AttributtedConfigParser are instances of this. |
108 | """ |
109 | @@ -38,6 +41,7 @@ |
110 | """ |
111 | return self.value is marker |
112 | |
113 | + |
114 | class AttributedConfigParser(RawConfigParser, object): |
115 | """Handle attributed ini-style configuration files |
116 | """ |
117 | @@ -74,5 +78,5 @@ |
118 | self.set(section, option, value) |
119 | for opt, val in self.items(section)[:]: |
120 | if opt.startswith(option + '.'): |
121 | - value.attrs[opt[len(option)+1:]] = val |
122 | + value.attrs[opt[len(option) + 1:]] = val |
123 | self.remove_option(section, opt) |
124 | |
125 | === modified file 'configglue/inischema/glue.py' |
126 | --- configglue/inischema/glue.py 2011-03-06 17:28:14 +0000 |
127 | +++ configglue/inischema/glue.py 2011-06-13 13:44:12 +0000 |
128 | @@ -1,18 +1,18 @@ |
129 | ############################################################################### |
130 | -# |
131 | +# |
132 | # configglue -- glue for your apps' configuration |
133 | -# |
134 | +# |
135 | # A library for simple, DRY configuration of applications |
136 | -# |
137 | +# |
138 | # (C) 2009--2010 by Canonical Ltd. |
139 | # originally by John R. Lenton <john.lenton@canonical.com> |
140 | # incorporating schemaconfig as configglue.pyschema |
141 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
142 | -# |
143 | +# |
144 | # Released under the BSD License (see the file LICENSE) |
145 | -# |
146 | +# |
147 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
148 | -# |
149 | +# |
150 | ############################################################################### |
151 | |
152 | """configglue lives here |
153 | |
154 | === modified file 'configglue/inischema/parsers.py' |
155 | --- configglue/inischema/parsers.py 2010-07-31 01:15:59 +0000 |
156 | +++ configglue/inischema/parsers.py 2011-06-13 13:44:12 +0000 |
157 | @@ -1,23 +1,24 @@ |
158 | ############################################################################### |
159 | -# |
160 | +# |
161 | # configglue -- glue for your apps' configuration |
162 | -# |
163 | +# |
164 | # A library for simple, DRY configuration of applications |
165 | -# |
166 | +# |
167 | # (C) 2009--2010 by Canonical Ltd. |
168 | # originally by John R. Lenton <john.lenton@canonical.com> |
169 | # incorporating schemaconfig as configglue.pyschema |
170 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
171 | -# |
172 | +# |
173 | # Released under the BSD License (see the file LICENSE) |
174 | -# |
175 | +# |
176 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
177 | -# |
178 | +# |
179 | ############################################################################### |
180 | |
181 | """Parsers used by TypedConfigParser live here |
182 | """ |
183 | |
184 | + |
185 | def lines(value): |
186 | """ Split a string on its newlines |
187 | |
188 | @@ -33,6 +34,8 @@ |
189 | |
190 | _true_values = frozenset(('true', '1', 'on', 'yes')) |
191 | _false_values = frozenset(('false', '0', 'off', 'no')) |
192 | + |
193 | + |
194 | def bool_parser(value): |
195 | """Take a string representation of a boolean and return its boolosity |
196 | |
197 | |
198 | === modified file 'configglue/inischema/typed.py' |
199 | --- configglue/inischema/typed.py 2010-07-31 01:15:59 +0000 |
200 | +++ configglue/inischema/typed.py 2011-06-13 13:44:12 +0000 |
201 | @@ -1,18 +1,18 @@ |
202 | ############################################################################### |
203 | -# |
204 | +# |
205 | # configglue -- glue for your apps' configuration |
206 | -# |
207 | +# |
208 | # A library for simple, DRY configuration of applications |
209 | -# |
210 | +# |
211 | # (C) 2009--2010 by Canonical Ltd. |
212 | # originally by John R. Lenton <john.lenton@canonical.com> |
213 | # incorporating schemaconfig as configglue.pyschema |
214 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
215 | -# |
216 | +# |
217 | # Released under the BSD License (see the file LICENSE) |
218 | -# |
219 | +# |
220 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
221 | -# |
222 | +# |
223 | ############################################################################### |
224 | |
225 | """ TypedConfigParser lives here """ |
226 | @@ -23,6 +23,7 @@ |
227 | from . import parsers |
228 | from .attributed import AttributedConfigParser |
229 | |
230 | + |
231 | class TypedConfigParser(AttributedConfigParser): |
232 | """Building on AttributedConfigParser, handle the idea of having a |
233 | configuration file that knows what type its options are. |
234 | @@ -78,7 +79,7 @@ |
235 | |
236 | if value.is_empty: |
237 | if 'default' in value.attrs: |
238 | - value.value = value.attrs['default'] |
239 | + value.value = value.attrs['default'] |
240 | else: |
241 | value.value = None |
242 | |
243 | |
244 | === modified file 'configglue/pyschema/__init__.py' |
245 | --- configglue/pyschema/__init__.py 2011-04-29 19:43:12 +0000 |
246 | +++ configglue/pyschema/__init__.py 2011-06-13 13:44:12 +0000 |
247 | @@ -1,18 +1,18 @@ |
248 | ############################################################################### |
249 | -# |
250 | +# |
251 | # configglue -- glue for your apps' configuration |
252 | -# |
253 | +# |
254 | # A library for simple, DRY configuration of applications |
255 | -# |
256 | +# |
257 | # (C) 2009--2010 by Canonical Ltd. |
258 | # originally by John R. Lenton <john.lenton@canonical.com> |
259 | # incorporating schemaconfig as configglue.pyschema |
260 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
261 | -# |
262 | +# |
263 | # Released under the BSD License (see the file LICENSE) |
264 | -# |
265 | +# |
266 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
267 | -# |
268 | +# |
269 | ############################################################################### |
270 | |
271 | from .glue import * |
272 | |
273 | === modified file 'configglue/pyschema/glue.py' |
274 | --- configglue/pyschema/glue.py 2011-06-07 21:16:16 +0000 |
275 | +++ configglue/pyschema/glue.py 2011-06-13 13:44:12 +0000 |
276 | @@ -1,18 +1,18 @@ |
277 | ############################################################################### |
278 | -# |
279 | +# |
280 | # configglue -- glue for your apps' configuration |
281 | -# |
282 | +# |
283 | # A library for simple, DRY configuration of applications |
284 | -# |
285 | +# |
286 | # (C) 2009--2010 by Canonical Ltd. |
287 | # originally by John R. Lenton <john.lenton@canonical.com> |
288 | # incorporating schemaconfig as configglue.pyschema |
289 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
290 | -# |
291 | +# |
292 | # Released under the BSD License (see the file LICENSE) |
293 | -# |
294 | +# |
295 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
296 | -# |
297 | +# |
298 | ############################################################################### |
299 | |
300 | import sys |
301 | @@ -34,7 +34,7 @@ |
302 | |
303 | def schemaconfigglue(parser, op=None, argv=None): |
304 | """Glue an OptionParser with a SchemaConfigParser. |
305 | - |
306 | + |
307 | The OptionParser is populated with options and defaults taken from the |
308 | SchemaConfigParser. |
309 | |
310 | |
311 | === modified file 'configglue/pyschema/parser.py' |
312 | --- configglue/pyschema/parser.py 2011-06-07 21:16:16 +0000 |
313 | +++ configglue/pyschema/parser.py 2011-06-13 13:44:12 +0000 |
314 | @@ -1,18 +1,18 @@ |
315 | ############################################################################### |
316 | -# |
317 | +# |
318 | # configglue -- glue for your apps' configuration |
319 | -# |
320 | +# |
321 | # A library for simple, DRY configuration of applications |
322 | -# |
323 | +# |
324 | # (C) 2009--2010 by Canonical Ltd. |
325 | # originally by John R. Lenton <john.lenton@canonical.com> |
326 | # incorporating schemaconfig as configglue.pyschema |
327 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
328 | -# |
329 | +# |
330 | # Released under the BSD License (see the file LICENSE) |
331 | -# |
332 | +# |
333 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
334 | -# |
335 | +# |
336 | ############################################################################### |
337 | |
338 | import codecs |
339 | @@ -365,8 +365,8 @@ |
340 | If any options are omitted from the config file, provide the |
341 | default value from the schema. |
342 | |
343 | - In the case of an NoSectionError or NoOptionError, raise it if the option |
344 | - has *fatal* set to *True*. |
345 | + In the case of an NoSectionError or NoOptionError, raise it if the |
346 | + option has *fatal* set to *True*. |
347 | |
348 | """ |
349 | for section in self.schema.sections(): |
350 | @@ -578,4 +578,3 @@ |
351 | os.rename(filename, "%s.old" % filename) |
352 | # rename new file |
353 | os.rename("%s.new" % filename, filename) |
354 | - |
355 | |
356 | === modified file 'configglue/pyschema/schema.py' |
357 | --- configglue/pyschema/schema.py 2011-06-07 21:16:16 +0000 |
358 | +++ configglue/pyschema/schema.py 2011-06-13 13:44:12 +0000 |
359 | @@ -1,18 +1,18 @@ |
360 | ############################################################################### |
361 | -# |
362 | +# |
363 | # configglue -- glue for your apps' configuration |
364 | -# |
365 | +# |
366 | # A library for simple, DRY configuration of applications |
367 | -# |
368 | +# |
369 | # (C) 2009--2010 by Canonical Ltd. |
370 | # originally by John R. Lenton <john.lenton@canonical.com> |
371 | # incorporating schemaconfig as configglue.pyschema |
372 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
373 | -# |
374 | +# |
375 | # Released under the BSD License (see the file LICENSE) |
376 | -# |
377 | +# |
378 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
379 | -# |
380 | +# |
381 | ############################################################################### |
382 | |
383 | from copy import deepcopy |
384 | @@ -95,7 +95,8 @@ |
385 | |
386 | def _add_option(self, name, option): |
387 | """Add a top-level option to the schema.""" |
388 | - section = self._sections.setdefault('__main__', ConfigSection(name='__main__')) |
389 | + section = self._sections.setdefault('__main__', |
390 | + ConfigSection(name='__main__')) |
391 | option.section = section |
392 | setattr(section, name, option) |
393 | |
394 | @@ -225,8 +226,8 @@ |
395 | |
396 | require_parser = False |
397 | |
398 | - def __init__(self, name='', raw=False, default=NO_DEFAULT, fatal=False, help='', |
399 | - section=None, action='store'): |
400 | + def __init__(self, name='', raw=False, default=NO_DEFAULT, fatal=False, |
401 | + help='', section=None, action='store'): |
402 | self.name = name |
403 | self.raw = raw |
404 | self.fatal = fatal |
405 | @@ -457,7 +458,8 @@ |
406 | if len(parts) == self.length: |
407 | result = tuple(parts) |
408 | else: |
409 | - raise ValueError("Tuples need to be %d items long" % self.length) |
410 | + raise ValueError( |
411 | + "Tuples need to be %d items long" % self.length) |
412 | else: |
413 | result = tuple(parts) |
414 | # length is 0, so no length validation |
415 | |
416 | === modified file 'setup.py' |
417 | --- setup.py 2011-02-20 21:52:07 +0000 |
418 | +++ setup.py 2011-06-13 13:44:12 +0000 |
419 | @@ -1,18 +1,18 @@ |
420 | ############################################################################### |
421 | -# |
422 | +# |
423 | # configglue -- glue for your apps' configuration |
424 | -# |
425 | +# |
426 | # A library for simple, DRY configuration of applications |
427 | -# |
428 | +# |
429 | # (C) 2009--2010 by Canonical Ltd. |
430 | # originally by John R. Lenton <john.lenton@canonical.com> |
431 | # incorporating schemaconfig as configglue.pyschema |
432 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
433 | -# |
434 | +# |
435 | # Released under the BSD License (see the file LICENSE) |
436 | -# |
437 | +# |
438 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
439 | -# |
440 | +# |
441 | ############################################################################### |
442 | |
443 | |
444 | |
445 | === modified file 'tests/__init__.py' |
446 | --- tests/__init__.py 2010-07-31 01:15:59 +0000 |
447 | +++ tests/__init__.py 2011-06-13 13:44:12 +0000 |
448 | @@ -1,17 +1,16 @@ |
449 | ############################################################################### |
450 | -# |
451 | +# |
452 | # configglue -- glue for your apps' configuration |
453 | -# |
454 | +# |
455 | # A library for simple, DRY configuration of applications |
456 | -# |
457 | +# |
458 | # (C) 2009--2010 by Canonical Ltd. |
459 | # originally by John R. Lenton <john.lenton@canonical.com> |
460 | # incorporating schemaconfig as configglue.pyschema |
461 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
462 | -# |
463 | +# |
464 | # Released under the BSD License (see the file LICENSE) |
465 | -# |
466 | +# |
467 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
468 | -# |
469 | +# |
470 | ############################################################################### |
471 | - |
472 | |
473 | === modified file 'tests/inischema/__init__.py' |
474 | --- tests/inischema/__init__.py 2011-01-10 12:50:01 +0000 |
475 | +++ tests/inischema/__init__.py 2011-06-13 13:44:12 +0000 |
476 | @@ -1,18 +1,18 @@ |
477 | ############################################################################### |
478 | -# |
479 | +# |
480 | # configglue -- glue for your apps' configuration |
481 | -# |
482 | +# |
483 | # A library for simple, DRY configuration of applications |
484 | -# |
485 | +# |
486 | # (C) 2009--2010 by Canonical Ltd. |
487 | # originally by John R. Lenton <john.lenton@canonical.com> |
488 | # incorporating schemaconfig as configglue.pyschema |
489 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
490 | -# |
491 | +# |
492 | # Released under the BSD License (see the file LICENSE) |
493 | -# |
494 | +# |
495 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
496 | -# |
497 | +# |
498 | ############################################################################### |
499 | |
500 | """Tests! Who woulda said""" |
501 | |
502 | === modified file 'tests/inischema/test_attributed.py' |
503 | --- tests/inischema/test_attributed.py 2010-07-31 01:15:59 +0000 |
504 | +++ tests/inischema/test_attributed.py 2011-06-13 13:44:12 +0000 |
505 | @@ -1,18 +1,18 @@ |
506 | ############################################################################### |
507 | -# |
508 | +# |
509 | # configglue -- glue for your apps' configuration |
510 | -# |
511 | +# |
512 | # A library for simple, DRY configuration of applications |
513 | -# |
514 | +# |
515 | # (C) 2009--2010 by Canonical Ltd. |
516 | # originally by John R. Lenton <john.lenton@canonical.com> |
517 | # incorporating schemaconfig as configglue.pyschema |
518 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
519 | -# |
520 | +# |
521 | # Released under the BSD License (see the file LICENSE) |
522 | -# |
523 | +# |
524 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
525 | -# |
526 | +# |
527 | ############################################################################### |
528 | |
529 | # in testfiles, putting docstrings on methods messes up with the |
530 | @@ -24,6 +24,7 @@ |
531 | |
532 | from configglue.inischema.attributed import AttributedConfigParser |
533 | |
534 | + |
535 | class BaseTest(unittest.TestCase): |
536 | """ Base class to keep common set-up """ |
537 | def setUp(self): |
538 | @@ -39,6 +40,7 @@ |
539 | self.config = AttributedConfigParser() |
540 | self.config.readfp(StringIO(self.config_string)) |
541 | |
542 | + |
543 | class TestAttributed(BaseTest): |
544 | """ pretty basic tests of AttributedConfigParser """ |
545 | def test_config_before_parsing_is_plain(self): |
546 | @@ -48,6 +50,7 @@ |
547 | for section in self.config.sections()], |
548 | [(section, sorted(rawConfig.items(section))) |
549 | for section in rawConfig.sections()]) |
550 | + |
551 | def test_config_after_parsing_is_attributed(self): |
552 | self.config.parse_all() |
553 | self.assertEqual(self.config.get('xyzzy', |
554 | |
555 | === modified file 'tests/inischema/test_glue.py' |
556 | --- tests/inischema/test_glue.py 2010-08-04 21:00:09 +0000 |
557 | +++ tests/inischema/test_glue.py 2011-06-13 13:44:12 +0000 |
558 | @@ -1,18 +1,18 @@ |
559 | ############################################################################### |
560 | -# |
561 | +# |
562 | # configglue -- glue for your apps' configuration |
563 | -# |
564 | +# |
565 | # A library for simple, DRY configuration of applications |
566 | -# |
567 | +# |
568 | # (C) 2009--2010 by Canonical Ltd. |
569 | # originally by John R. Lenton <john.lenton@canonical.com> |
570 | # incorporating schemaconfig as configglue.pyschema |
571 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
572 | -# |
573 | +# |
574 | # Released under the BSD License (see the file LICENSE) |
575 | -# |
576 | +# |
577 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
578 | -# |
579 | +# |
580 | ############################################################################### |
581 | |
582 | # in testfiles, putting docstrings on methods messes up with the |
583 | @@ -24,6 +24,7 @@ |
584 | |
585 | from configglue.inischema.glue import configglue |
586 | |
587 | + |
588 | class TestBase(unittest.TestCase): |
589 | """ Base class to keep common set-up """ |
590 | def setUp(self): |
591 | @@ -34,6 +35,7 @@ |
592 | def tearDown(self): |
593 | sys.argv = self.old_sys_argv |
594 | |
595 | + |
596 | class TestGlue(TestBase): |
597 | ini = ''' |
598 | [blah] |
599 | @@ -57,6 +59,7 @@ |
600 | args=['', self.arg + '=5']) |
601 | self.assertEqual(vars(options), |
602 | {self.opt: '5'}) |
603 | + |
604 | def test_help_is_displayed(self): |
605 | sys.stdout = StringIO() |
606 | try: |
607 | @@ -66,6 +69,7 @@ |
608 | sys.stdout = sys.__stdout__ |
609 | self.assertTrue('yadda yadda yadda yadda' in output) |
610 | |
611 | + |
612 | class TestCrazyGlue(TestGlue): |
613 | ini = ''' |
614 | [bl-ah] |
615 | @@ -79,6 +83,7 @@ |
616 | arg = '--bl-ah_foo' |
617 | opt = 'bl_ah_foo' |
618 | |
619 | + |
620 | class TestNoValue(TestGlue): |
621 | ini = ''' |
622 | [blah] |
623 | @@ -90,14 +95,18 @@ |
624 | ''' |
625 | val = 3 |
626 | |
627 | + |
628 | class TestGlue2(TestBase): |
629 | ini = '[__main__]\na=1\n' |
630 | + |
631 | def test_main(self): |
632 | parser, options, args = configglue(self.file) |
633 | self.assertEqual(options.a, '1') |
634 | |
635 | + |
636 | class TestGlue3(TestBase): |
637 | ini = '[x]\na.help=hi\n' |
638 | + |
639 | def test_empty(self): |
640 | parser, options, args = configglue(self.file) |
641 | self.assertEqual(options.x_a, '') |
642 | @@ -107,6 +116,7 @@ |
643 | args=['', '--x_a=1']) |
644 | self.assertEqual(options.x_a, '1') |
645 | |
646 | + |
647 | class TestGlueBool(TestBase): |
648 | ini = '''[__main__] |
649 | foo.parser=bool |
650 | @@ -116,6 +126,7 @@ |
651 | bar.parser = bool |
652 | bar.action = store_false |
653 | ''' |
654 | + |
655 | def test_store_true(self): |
656 | parser, options, args = configglue(self.file, args=['', '--foo']) |
657 | self.assertEqual(options.foo, True) |
658 | @@ -135,6 +146,7 @@ |
659 | bar.parser = lines |
660 | bar.action = append |
661 | ''' |
662 | + |
663 | def test_nothing(self): |
664 | parser, options, args = configglue(self.file) |
665 | self.assertEqual(options.foo, []) |
666 | @@ -150,4 +162,3 @@ |
667 | def test_append(self): |
668 | parser, options, args = configglue(self.file, args=['', '--bar=x']) |
669 | self.assertEqual(options.bar, ['a', 'b', 'x']) |
670 | - |
671 | |
672 | === modified file 'tests/inischema/test_glue2glue.py' |
673 | --- tests/inischema/test_glue2glue.py 2011-01-10 12:45:09 +0000 |
674 | +++ tests/inischema/test_glue2glue.py 2011-06-13 13:44:12 +0000 |
675 | @@ -1,22 +1,23 @@ |
676 | # -*- coding: utf-8 -*- |
677 | ############################################################################### |
678 | -# |
679 | +# |
680 | # configglue -- glue for your apps' configuration |
681 | -# |
682 | +# |
683 | # A library for simple, DRY configuration of applications |
684 | -# |
685 | +# |
686 | # (C) 2009--2010 by Canonical Ltd. |
687 | # originally by John R. Lenton <john.lenton@canonical.com> |
688 | # incorporating schemaconfig as configglue.pyschema |
689 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
690 | -# |
691 | +# |
692 | # Released under the BSD License (see the file LICENSE) |
693 | -# |
694 | +# |
695 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
696 | -# |
697 | +# |
698 | ############################################################################### |
699 | |
700 | import sys |
701 | +import textwrap |
702 | import unittest |
703 | from StringIO import StringIO |
704 | |
705 | @@ -64,7 +65,12 @@ |
706 | self.assertEqual(vars(cg), vars(sg)) |
707 | |
708 | def test_parser_unicode(self): |
709 | - s = "[__main__]\nbar = zátrapa\nbar.parser = unicode\nbar.parser.args = utf-8" |
710 | + s = textwrap.dedent(""" |
711 | + [__main__] |
712 | + bar = zátrapa |
713 | + bar.parser = unicode |
714 | + bar.parser.args = utf-8 |
715 | + """) |
716 | _, cg, _ = configglue(StringIO(s)) |
717 | _, sg, _ = schemaconfigglue(ini2schema(StringIO(s))) |
718 | self.assertEqual(vars(cg), vars(sg)) |
719 | |
720 | === modified file 'tests/inischema/test_parsers.py' |
721 | --- tests/inischema/test_parsers.py 2010-08-05 02:59:16 +0000 |
722 | +++ tests/inischema/test_parsers.py 2011-06-13 13:44:12 +0000 |
723 | @@ -1,18 +1,18 @@ |
724 | ############################################################################### |
725 | -# |
726 | +# |
727 | # configglue -- glue for your apps' configuration |
728 | -# |
729 | +# |
730 | # A library for simple, DRY configuration of applications |
731 | -# |
732 | +# |
733 | # (C) 2009--2010 by Canonical Ltd. |
734 | # originally by John R. Lenton <john.lenton@canonical.com> |
735 | # incorporating schemaconfig as configglue.pyschema |
736 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
737 | -# |
738 | +# |
739 | # Released under the BSD License (see the file LICENSE) |
740 | -# |
741 | +# |
742 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
743 | -# |
744 | +# |
745 | ############################################################################### |
746 | |
747 | # in testfiles, putting docstrings on methods messes up with the |
748 | @@ -22,6 +22,7 @@ |
749 | |
750 | from configglue.inischema import parsers |
751 | |
752 | + |
753 | class TestParsers(unittest.TestCase): |
754 | def test_bool(self): |
755 | for value in ('true', '1', 'on', 'yes', |
756 | @@ -44,4 +45,3 @@ |
757 | |
758 | def test_lines_not_string(self): |
759 | self.assertEqual(parsers.lines(42), 42) |
760 | - |
761 | |
762 | === modified file 'tests/inischema/test_typed.py' |
763 | --- tests/inischema/test_typed.py 2010-08-05 12:59:11 +0000 |
764 | +++ tests/inischema/test_typed.py 2011-06-13 13:44:12 +0000 |
765 | @@ -1,18 +1,18 @@ |
766 | ############################################################################### |
767 | -# |
768 | +# |
769 | # configglue -- glue for your apps' configuration |
770 | -# |
771 | +# |
772 | # A library for simple, DRY configuration of applications |
773 | -# |
774 | +# |
775 | # (C) 2009--2010 by Canonical Ltd. |
776 | # originally by John R. Lenton <john.lenton@canonical.com> |
777 | # incorporating schemaconfig as configglue.pyschema |
778 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
779 | -# |
780 | +# |
781 | # Released under the BSD License (see the file LICENSE) |
782 | -# |
783 | +# |
784 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
785 | -# |
786 | +# |
787 | ############################################################################### |
788 | |
789 | # in testfiles, putting docstrings on methods messes up with the |
790 | @@ -24,13 +24,17 @@ |
791 | |
792 | from configglue.inischema.typed import TypedConfigParser |
793 | |
794 | + |
795 | marker = object() |
796 | + |
797 | + |
798 | def some_parser(value): |
799 | if value == 'marker': |
800 | return marker |
801 | else: |
802 | return None |
803 | |
804 | + |
805 | class BaseTest(unittest.TestCase): |
806 | """ Base class to keep common set-up """ |
807 | def setUp(self): |
808 | @@ -67,6 +71,7 @@ |
809 | self.config = TypedConfigParser() |
810 | self.config.readfp(StringIO(self.config_string)) |
811 | |
812 | + |
813 | class TestBackwardsCompat(BaseTest): |
814 | """ rather basic backwards compatibility checker |
815 | """ |
816 | @@ -78,26 +83,32 @@ |
817 | [(section, sorted(rawConfig.items(section))) |
818 | for section in rawConfig.sections()]) |
819 | |
820 | + |
821 | class TestParserd(BaseTest): |
822 | """Test the different parsing situations""" |
823 | def test_some_builtin_parser(self): |
824 | self.config.parse('xyzzy', 'bar') |
825 | self.assertEqual(self.config.get('xyzzy', 'bar').value, 2) |
826 | + |
827 | def test_add_second_custom_parser_fails(self): |
828 | self.config.add_parser('some.parser', some_parser) |
829 | self.assertRaises(ValueError, self.config.add_parser, |
830 | 'some.parser', some_parser) |
831 | + |
832 | def test_custom_parser(self): |
833 | self.config.add_parser('some.parser', some_parser) |
834 | self.config.parse('xyzzy', 'baz') |
835 | self.assertEqual(self.config.get('xyzzy', 'baz').value, marker) |
836 | + |
837 | def test_value_is_default_if_empty(self): |
838 | self.config.parse('xyzzy', 'foo') |
839 | self.assertEqual(self.config.get('xyzzy', 'foo').value, 1j) |
840 | + |
841 | def test_parse_default_parser(self): |
842 | self.config.add_parser('some.parser', some_parser) |
843 | self.config.parse('xyzzy', 'woof') |
844 | self.assertTrue(self.config.get('xyzzy', 'woof').value) |
845 | + |
846 | def test_parse_all_parses_all(self): |
847 | self.config.add_parser('some.parser', some_parser) |
848 | self.config.add_parser('more.parser', some_parser) |
849 | @@ -115,6 +126,7 @@ |
850 | ('thud', None), |
851 | ('woof', True), |
852 | ])]) |
853 | + |
854 | def test_add_multiple_parsers(self): |
855 | self.config.add_parsers(('some.parser', some_parser), |
856 | ('more.parser', some_parser)) |
857 | @@ -122,11 +134,13 @@ |
858 | self.config.parse('xyzzy', 'baz2') |
859 | self.assertEqual(self.config.get('xyzzy', 'baz').value, marker) |
860 | self.assertEqual(self.config.get('xyzzy', 'baz2').value, None) |
861 | + |
862 | def test_add_mutliple_with_repeat_without_clobber(self): |
863 | self.assertRaises(ValueError, |
864 | self.config.add_parsers, |
865 | ('some.parser', some_parser), |
866 | ('some.parser', some_parser)) |
867 | + |
868 | def test_add_multiple_with_repeat_with_clobber(self): |
869 | self.config.add_parsers(('some.parser', some_parser), |
870 | ('some.parser', bool, True)) |
871 | |
872 | === modified file 'tests/pyschema/__init__.py' |
873 | --- tests/pyschema/__init__.py 2010-08-04 12:42:29 +0000 |
874 | +++ tests/pyschema/__init__.py 2011-06-13 13:44:12 +0000 |
875 | @@ -1,16 +1,16 @@ |
876 | ############################################################################### |
877 | -# |
878 | +# |
879 | # configglue -- glue for your apps' configuration |
880 | -# |
881 | +# |
882 | # A library for simple, DRY configuration of applications |
883 | -# |
884 | +# |
885 | # (C) 2009--2010 by Canonical Ltd. |
886 | # originally by John R. Lenton <john.lenton@canonical.com> |
887 | # incorporating schemaconfig as configglue.pyschema |
888 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
889 | -# |
890 | +# |
891 | # Released under the BSD License (see the file LICENSE) |
892 | -# |
893 | +# |
894 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
895 | -# |
896 | +# |
897 | ############################################################################### |
898 | |
899 | === modified file 'tests/pyschema/test_parser.py' |
900 | --- tests/pyschema/test_parser.py 2011-06-07 21:16:16 +0000 |
901 | +++ tests/pyschema/test_parser.py 2011-06-13 13:44:12 +0000 |
902 | @@ -1,24 +1,25 @@ |
903 | # -*- coding: utf-8 -*- |
904 | ############################################################################### |
905 | -# |
906 | +# |
907 | # configglue -- glue for your apps' configuration |
908 | -# |
909 | +# |
910 | # A library for simple, DRY configuration of applications |
911 | -# |
912 | +# |
913 | # (C) 2009--2010 by Canonical Ltd. |
914 | # originally by John R. Lenton <john.lenton@canonical.com> |
915 | # incorporating schemaconfig as configglue.pyschema |
916 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
917 | -# |
918 | +# |
919 | # Released under the BSD License (see the file LICENSE) |
920 | -# |
921 | +# |
922 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
923 | -# |
924 | +# |
925 | ############################################################################### |
926 | |
927 | import os |
928 | import shutil |
929 | import tempfile |
930 | +import textwrap |
931 | import unittest |
932 | from ConfigParser import ( |
933 | DEFAULTSECT, |
934 | @@ -148,7 +149,8 @@ |
935 | f.write("[__main__]\nbaz=3") |
936 | f.close() |
937 | |
938 | - config = StringIO("[__main__]\nfoo=4\nincludes=%s/first.cfg" % folder) |
939 | + config = StringIO( |
940 | + "[__main__]\nfoo=4\nincludes=%s/first.cfg" % folder) |
941 | return config, folder |
942 | |
943 | class MySchema(Schema): |
944 | @@ -220,8 +222,8 @@ |
945 | rawval = '%(bar)' |
946 | vars = {'foo': '%(bar)s', 'bar': 'pepe'} |
947 | parser = SchemaConfigParser(MySchema()) |
948 | - self.assertRaises(InterpolationSyntaxError, parser._interpolate, section, option, |
949 | - rawval, vars) |
950 | + self.assertRaises(InterpolationSyntaxError, parser._interpolate, |
951 | + section, option, rawval, vars) |
952 | |
953 | def test_interpolate_across_sections(self): |
954 | class MySchema(Schema): |
955 | @@ -309,7 +311,8 @@ |
956 | def test_get_interpolation_keys_tuple_lines(self): |
957 | class MySchema(Schema): |
958 | foo = LinesConfigOption(item=TupleConfigOption(2)) |
959 | - config = StringIO("[__main__]\nfoo=%(bar)s,%(bar)s\n %(baz)s,%(baz)s") |
960 | + config = StringIO( |
961 | + "[__main__]\nfoo=%(bar)s,%(bar)s\n %(baz)s,%(baz)s") |
962 | expected = ('%(bar)s,%(bar)s\n%(baz)s,%(baz)s', |
963 | set(['bar', 'baz'])) |
964 | |
965 | @@ -321,7 +324,14 @@ |
966 | def test_get_interpolation_keys_dict(self): |
967 | class MySchema(Schema): |
968 | foo = DictConfigOption(spec={'a': IntConfigOption()}) |
969 | - config = StringIO("[__noschema__]\nbar=4\n[__main__]\nfoo=mydict\n[mydict]\na=%(bar)s") |
970 | + config = StringIO(textwrap.dedent(""" |
971 | + [__noschema__] |
972 | + bar=4 |
973 | + [__main__] |
974 | + foo=mydict |
975 | + [mydict] |
976 | + a=%(bar)s |
977 | + """)) |
978 | expected = ('mydict', set([])) |
979 | |
980 | parser = SchemaConfigParser(MySchema()) |
981 | @@ -332,7 +342,8 @@ |
982 | def test_interpolate_value_duplicate_key(self): |
983 | class MySchema(Schema): |
984 | foo = TupleConfigOption(2) |
985 | - config = StringIO("[__noschema__]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s") |
986 | + config = StringIO( |
987 | + "[__noschema__]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s") |
988 | expected_value = '4,4' |
989 | |
990 | parser = SchemaConfigParser(MySchema()) |
991 | @@ -366,7 +377,6 @@ |
992 | value = parser._interpolate_value('__main__', 'foo') |
993 | self.assertEqual(value, None) |
994 | |
995 | - |
996 | def test_get_with_raw_value(self): |
997 | class MySchema(Schema): |
998 | foo = StringConfigOption(raw=True) |
999 | @@ -381,7 +391,14 @@ |
1000 | def test_interpolate_parse_dict(self): |
1001 | class MySchema(Schema): |
1002 | foo = DictConfigOption(spec={'a': IntConfigOption()}) |
1003 | - config = StringIO("[__noschema__]\nbar=4\n[__main__]\nfoo=mydict\n[mydict]\na=%(bar)s") |
1004 | + config = StringIO(textwrap.dedent(""" |
1005 | + [__noschema__] |
1006 | + bar=4 |
1007 | + [__main__] |
1008 | + foo=mydict |
1009 | + [mydict] |
1010 | + a=%(bar)s |
1011 | + """)) |
1012 | expected = {'__main__': {'foo': {'a': 4}}} |
1013 | |
1014 | parser = SchemaConfigParser(MySchema()) |
1015 | @@ -512,14 +529,17 @@ |
1016 | self.assertEqual(value, expected_value) |
1017 | |
1018 | def test_parse_invalid_section(self): |
1019 | - self.assertRaises(NoSectionError, self.parser.parse, 'bar', 'baz', '1') |
1020 | + self.assertRaises(NoSectionError, self.parser.parse, |
1021 | + 'bar', 'baz', '1') |
1022 | |
1023 | def test_default_values(self): |
1024 | class MySchema(Schema): |
1025 | foo = BoolConfigOption(default=True) |
1026 | + |
1027 | class bar(ConfigSection): |
1028 | baz = IntConfigOption() |
1029 | bla = StringConfigOption(default='hello') |
1030 | + |
1031 | schema = MySchema() |
1032 | config = StringIO("[bar]\nbaz=123") |
1033 | expected_values = {'__main__': {'foo': True}, |
1034 | @@ -529,7 +549,9 @@ |
1035 | self.assertEquals(expected_values, parser.values()) |
1036 | |
1037 | config = StringIO("[bar]\nbla=123") |
1038 | - expected = {'__main__': {'foo': True}, 'bar': {'baz': 0, 'bla': '123'}} |
1039 | + expected = { |
1040 | + '__main__': {'foo': True}, |
1041 | + 'bar': {'baz': 0, 'bla': '123'}} |
1042 | parser = SchemaConfigParser(schema) |
1043 | parser.readfp(config) |
1044 | self.assertEquals(expected, parser.values()) |
1045 | @@ -698,7 +720,8 @@ |
1046 | f.close() |
1047 | |
1048 | self.parser.read(filename) |
1049 | - self.assertEqual(self.parser.values(), {'__main__': {'foo': u'€'}}) |
1050 | + self.assertEqual(self.parser.values(), |
1051 | + {'__main__': {'foo': u'€'}}) |
1052 | finally: |
1053 | # destroy config file |
1054 | os.remove(filename) |
1055 | @@ -742,10 +765,13 @@ |
1056 | def test_write(self): |
1057 | class MySchema(Schema): |
1058 | foo = StringConfigOption() |
1059 | + |
1060 | class DEFAULTSECT(ConfigSection): |
1061 | pass |
1062 | + |
1063 | parser = SchemaConfigParser(MySchema()) |
1064 | - expected = u"[{0}]\nbaz = 2\n\n[__main__]\nfoo = bar".format(DEFAULTSECT) |
1065 | + expected = u"[{0}]\nbaz = 2\n\n[__main__]\nfoo = bar".format( |
1066 | + DEFAULTSECT) |
1067 | config = StringIO(expected) |
1068 | parser.readfp(config) |
1069 | |
1070 | @@ -873,7 +899,8 @@ |
1071 | foo = IntConfigOption() |
1072 | |
1073 | config = StringIO("[__main__]\nfoo=5\nbar=6") |
1074 | - errors = ["Configuration includes invalid options for section '__main__': bar"] |
1075 | + errors = ["Configuration includes invalid options for " |
1076 | + "section '__main__': bar"] |
1077 | expected = (False, errors) |
1078 | |
1079 | parser = SchemaConfigParser(MySchema()) |
1080 | @@ -972,7 +999,8 @@ |
1081 | |
1082 | def test_extra_sections_with_nested_dicts_strict(self): |
1083 | class MySchema(Schema): |
1084 | - foo = DictConfigOption(spec={'bar': DictConfigOption()}, strict=True) |
1085 | + foo = DictConfigOption(spec={'bar': DictConfigOption()}, |
1086 | + strict=True) |
1087 | |
1088 | config = StringIO(""" |
1089 | [__main__] |
1090 | @@ -1015,8 +1043,7 @@ |
1091 | self.assertEqual(parser.values(), |
1092 | {'__main__': {'foo': [ |
1093 | {'bar': {'wham': '1'}}, |
1094 | - {'baz': {'whaz': '2'}} |
1095 | - ]}}) |
1096 | + {'baz': {'whaz': '2'}}]}}) |
1097 | self.assertTrue(parser.is_valid()) |
1098 | |
1099 | def test_extra_sections_when_dict_with_nested_lines_dicts(self): |
1100 | @@ -1075,8 +1102,7 @@ |
1101 | self.assertEqual(parser.values(), |
1102 | {'__main__': {'foo': [ |
1103 | {'bar': [{'wham': '1'}, {'whaz': '2'}]}, |
1104 | - {'baz': [{'whoosh': '3'}, {'swoosh': '4'}]} |
1105 | - ]}}) |
1106 | + {'baz': [{'whoosh': '3'}, {'swoosh': '4'}]}]}}) |
1107 | self.assertTrue(parser.is_valid()) |
1108 | |
1109 | def test_multiple_extra_sections(self): |
1110 | @@ -1093,7 +1119,8 @@ |
1111 | self.assertTrue(parser.is_valid()) |
1112 | |
1113 | def test_noschema_section(self): |
1114 | - config = StringIO("[__main__]\nfoo=%(bar)s\n[__noschema__]\nbar=hello") |
1115 | + config = StringIO( |
1116 | + "[__main__]\nfoo=%(bar)s\n[__noschema__]\nbar=hello") |
1117 | parser = SchemaConfigParser(self.schema) |
1118 | parser.readfp(config) |
1119 | parser.parse_all() |
1120 | |
1121 | === modified file 'tests/pyschema/test_schema.py' |
1122 | --- tests/pyschema/test_schema.py 2011-06-07 21:16:16 +0000 |
1123 | +++ tests/pyschema/test_schema.py 2011-06-13 13:44:12 +0000 |
1124 | @@ -1,19 +1,19 @@ |
1125 | # -*- coding: utf-8 -*- |
1126 | ############################################################################### |
1127 | -# |
1128 | +# |
1129 | # configglue -- glue for your apps' configuration |
1130 | -# |
1131 | +# |
1132 | # A library for simple, DRY configuration of applications |
1133 | -# |
1134 | +# |
1135 | # (C) 2009--2010 by Canonical Ltd. |
1136 | # originally by John R. Lenton <john.lenton@canonical.com> |
1137 | # incorporating schemaconfig as configglue.pyschema |
1138 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
1139 | -# |
1140 | +# |
1141 | # Released under the BSD License (see the file LICENSE) |
1142 | -# |
1143 | +# |
1144 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
1145 | -# |
1146 | +# |
1147 | ############################################################################### |
1148 | |
1149 | import unittest |
1150 | @@ -42,11 +42,13 @@ |
1151 | class MyOtherSchema(Schema): |
1152 | class web(ConfigSection): |
1153 | bar = IntConfigOption() |
1154 | + |
1155 | class froo(ConfigSection): |
1156 | twaddle = LinesConfigOption(item=BoolConfigOption()) |
1157 | |
1158 | class MyThirdSchema(Schema): |
1159 | bar = IntConfigOption() |
1160 | + |
1161 | class froo(ConfigSection): |
1162 | twaddle = LinesConfigOption(item=BoolConfigOption()) |
1163 | |
1164 | @@ -80,6 +82,7 @@ |
1165 | def test_names(self): |
1166 | class MySchema(Schema): |
1167 | foo = BoolConfigOption() |
1168 | + |
1169 | class bar(ConfigSection): |
1170 | baz = IntConfigOption() |
1171 | |
1172 | @@ -93,6 +96,7 @@ |
1173 | def test_options(self): |
1174 | class MySchema(Schema): |
1175 | foo = BoolConfigOption() |
1176 | + |
1177 | class bar(ConfigSection): |
1178 | baz = IntConfigOption() |
1179 | |
1180 | @@ -111,6 +115,7 @@ |
1181 | def test_equal(self): |
1182 | class MySchema(Schema): |
1183 | foo = IntConfigOption() |
1184 | + |
1185 | class OtherSchema(Schema): |
1186 | bar = IntConfigOption() |
1187 | |
1188 | @@ -122,8 +127,10 @@ |
1189 | def test_get_config_objects(self): |
1190 | class MySchema(Schema): |
1191 | foo = IntConfigOption() |
1192 | + |
1193 | class one(ConfigSection): |
1194 | bar = IntConfigOption() |
1195 | + |
1196 | two = ConfigSection() |
1197 | two.bam = IntConfigOption() |
1198 | |
1199 | @@ -179,9 +186,11 @@ |
1200 | class SchemaA(Schema): |
1201 | class foo(ConfigSection): |
1202 | bar = IntConfigOption() |
1203 | + |
1204 | class SchemaB(SchemaA): |
1205 | class baz(ConfigSection): |
1206 | wham = IntConfigOption() |
1207 | + |
1208 | class SchemaC(SchemaA): |
1209 | class bar(ConfigSection): |
1210 | woof = IntConfigOption() |
1211 | @@ -217,6 +226,7 @@ |
1212 | class SchemaA(Schema): |
1213 | class foo(ConfigSection): |
1214 | bar = IntConfigOption() |
1215 | + |
1216 | bar = IntConfigOption() |
1217 | |
1218 | class SchemaB(SchemaA): |
1219 | @@ -305,6 +315,7 @@ |
1220 | def test_parse_int(self): |
1221 | class MySchema(Schema): |
1222 | foo = IntConfigOption() |
1223 | + |
1224 | config = StringIO("[__main__]\nfoo = 42") |
1225 | expected_values = {'__main__': {'foo': 42}} |
1226 | schema = MySchema() |
1227 | @@ -339,6 +350,7 @@ |
1228 | def test_parse_bool(self): |
1229 | class MySchema(Schema): |
1230 | foo = BoolConfigOption() |
1231 | + |
1232 | config = StringIO("[__main__]\nfoo = Yes") |
1233 | expected_values = {'__main__': {'foo': True}} |
1234 | schema = MySchema() |
1235 | @@ -389,6 +401,7 @@ |
1236 | def test_parse_bool_lines(self): |
1237 | class MySchema(Schema): |
1238 | foo = LinesConfigOption(item=BoolConfigOption()) |
1239 | + |
1240 | schema = MySchema() |
1241 | config = StringIO("[__main__]\nfoo = tRuE\n No\n 0\n 1") |
1242 | expected_values = {'__main__': {'foo': [True, False, False, True]}} |
1243 | @@ -399,6 +412,7 @@ |
1244 | def test_parse_bool_empty_lines(self): |
1245 | class MySchema(Schema): |
1246 | foo = LinesConfigOption(item=BoolConfigOption()) |
1247 | + |
1248 | schema = MySchema() |
1249 | config = StringIO("[__main__]\nfoo =") |
1250 | parser = SchemaConfigParser(schema) |
1251 | @@ -409,6 +423,7 @@ |
1252 | def test_parse_bool_invalid_lines(self): |
1253 | class MySchema(Schema): |
1254 | foo = LinesConfigOption(item=BoolConfigOption()) |
1255 | + |
1256 | schema = MySchema() |
1257 | config = StringIO("[__main__]\nfoo = bla") |
1258 | parser = SchemaConfigParser(schema) |
1259 | @@ -428,6 +443,7 @@ |
1260 | class MySchema(Schema): |
1261 | foo = LinesConfigOption(item=StringConfigOption(), |
1262 | remove_duplicates=True) |
1263 | + |
1264 | schema = MySchema() |
1265 | config = StringIO("[__main__]\nfoo = bla\n blah\n bla") |
1266 | parser = SchemaConfigParser(schema) |
1267 | @@ -439,6 +455,7 @@ |
1268 | class MyOtherSchema(Schema): |
1269 | foo = LinesConfigOption(item=DictConfigOption(), |
1270 | remove_duplicates=True) |
1271 | + |
1272 | schema = MyOtherSchema() |
1273 | config = StringIO("[__main__]\nfoo = bla\n bla\n[bla]\nbar = baz") |
1274 | parser = SchemaConfigParser(schema) |
1275 | @@ -478,6 +495,7 @@ |
1276 | def test_parse_tuple(self): |
1277 | class MySchema(Schema): |
1278 | foo = TupleConfigOption(length=4) |
1279 | + |
1280 | config = StringIO('[__main__]\nfoo = 1, 2, 3, 4') |
1281 | expected_values = {'__main__': {'foo': ('1', '2', '3', '4')}} |
1282 | schema = MySchema() |
1283 | @@ -550,6 +568,7 @@ |
1284 | 'baz': IntConfigOption(), |
1285 | 'bla': BoolConfigOption(), |
1286 | }) |
1287 | + |
1288 | config = StringIO("""[__main__] |
1289 | foo = mydict |
1290 | [mydict] |
1291 | @@ -559,9 +578,7 @@ |
1292 | """) |
1293 | expected_values = { |
1294 | '__main__': { |
1295 | - 'foo': {'bar': 'baz', 'baz': 42, 'bla': True} |
1296 | - } |
1297 | - } |
1298 | + 'foo': {'bar': 'baz', 'baz': 42, 'bla': True}}} |
1299 | |
1300 | schema = MySchema() |
1301 | parser = SchemaConfigParser(schema) |
1302 | @@ -575,6 +592,7 @@ |
1303 | 'baz': IntConfigOption(), |
1304 | 'bla': BoolConfigOption(), |
1305 | }) |
1306 | + |
1307 | config = StringIO("""[__main__] |
1308 | foo = mydict |
1309 | [mydict] |
1310 | @@ -702,6 +720,7 @@ |
1311 | 'baz': IntConfigOption(), |
1312 | 'bla': BoolConfigOption(), |
1313 | })) |
1314 | + |
1315 | config = StringIO("""[__main__] |
1316 | foo = mylist0 |
1317 | mylist1 |
1318 | @@ -734,8 +753,10 @@ |
1319 | spec = {'name': StringConfigOption(), |
1320 | 'size': IntConfigOption(), |
1321 | 'options': DictConfigOption(spec=innerspec)} |
1322 | + |
1323 | class MySchema(Schema): |
1324 | foo = DictConfigOption(spec=spec) |
1325 | + |
1326 | config = StringIO("""[__main__] |
1327 | foo = outerdict |
1328 | [outerdict] |
1329 | @@ -758,6 +779,7 @@ |
1330 | def setUp(self): |
1331 | class MySchema(Schema): |
1332 | foo = LinesConfigOption(item=TupleConfigOption(length=3)) |
1333 | + |
1334 | schema = MySchema() |
1335 | self.parser = SchemaConfigParser(schema) |
1336 | |
1337 | @@ -778,4 +800,3 @@ |
1338 | expected_values = {'__main__': {'foo': [()]}} |
1339 | self.parser.readfp(config) |
1340 | self.assertEqual(self.parser.values(), expected_values) |
1341 | - |
1342 | |
1343 | === modified file 'tests/pyschema/test_schemaconfig.py' |
1344 | --- tests/pyschema/test_schemaconfig.py 2011-05-19 08:44:58 +0000 |
1345 | +++ tests/pyschema/test_schemaconfig.py 2011-06-13 13:44:12 +0000 |
1346 | @@ -1,19 +1,19 @@ |
1347 | # -*- coding: utf-8 -*- |
1348 | ############################################################################### |
1349 | -# |
1350 | +# |
1351 | # configglue -- glue for your apps' configuration |
1352 | -# |
1353 | +# |
1354 | # A library for simple, DRY configuration of applications |
1355 | -# |
1356 | +# |
1357 | # (C) 2009--2010 by Canonical Ltd. |
1358 | # originally by John R. Lenton <john.lenton@canonical.com> |
1359 | # incorporating schemaconfig as configglue.pyschema |
1360 | # schemaconfig originally by Ricardo Kirkner <ricardo.kirkner@canonical.com> |
1361 | -# |
1362 | +# |
1363 | # Released under the BSD License (see the file LICENSE) |
1364 | -# |
1365 | +# |
1366 | # For bug reports, support, and new releases: http://launchpad.net/configglue |
1367 | -# |
1368 | +# |
1369 | ############################################################################### |
1370 | |
1371 | import unittest |
1372 | @@ -206,7 +206,8 @@ |
1373 | class ConfigglueTestCase(unittest.TestCase): |
1374 | @patch('configglue.pyschema.glue.SchemaConfigParser') |
1375 | @patch('configglue.pyschema.glue.schemaconfigglue') |
1376 | - def test_configglue_no_errors(self, mock_schemaconfigglue, mock_schema_parser): |
1377 | + def test_configglue_no_errors(self, mock_schemaconfigglue, |
1378 | + mock_schema_parser): |
1379 | # prepare mocks |
1380 | expected_schema_parser = Mock() |
1381 | expected_schema_parser.is_valid.return_value = (True, None) |
1382 | @@ -232,14 +233,16 @@ |
1383 | mock_schema_parser.assert_called_with(MySchema()) |
1384 | mock_schema_parser.return_value.read.assert_called_with(configs) |
1385 | # the other attributes are the result of calling schemaconfigglue |
1386 | - mock_schemaconfigglue.assert_called_with(expected_schema_parser, op=None) |
1387 | + mock_schemaconfigglue.assert_called_with(expected_schema_parser, |
1388 | + op=None) |
1389 | self.assertEqual(glue.option_parser, expected_option_parser) |
1390 | self.assertEqual(glue.options, expected_options) |
1391 | self.assertEqual(glue.args, expected_args) |
1392 | |
1393 | @patch('configglue.pyschema.glue.SchemaConfigParser') |
1394 | @patch('configglue.pyschema.glue.schemaconfigglue') |
1395 | - def test_configglue_with_errors(self, mock_schemaconfigglue, mock_schema_parser): |
1396 | + def test_configglue_with_errors(self, mock_schemaconfigglue, |
1397 | + mock_schema_parser): |
1398 | # prepare mocks |
1399 | expected_schema_parser = Mock() |
1400 | expected_schema_parser.is_valid.return_value = (False, ['some error']) |
1401 | @@ -265,7 +268,8 @@ |
1402 | mock_schema_parser.assert_called_with(MySchema()) |
1403 | mock_schema_parser.return_value.read.assert_called_with(configs) |
1404 | # the other attributes are the result of calling schemaconfigglue |
1405 | - mock_schemaconfigglue.assert_called_with(expected_schema_parser, op=None) |
1406 | + mock_schemaconfigglue.assert_called_with(expected_schema_parser, |
1407 | + op=None) |
1408 | self.assertEqual(glue.option_parser, expected_option_parser) |
1409 | expected_option_parser.error.assert_called_with('some error') |
1410 | self.assertEqual(glue.options, expected_options) |
1411 | @@ -282,8 +286,8 @@ |
1412 | expected_option_parser = mock_option_parser.return_value |
1413 | expected_options = Mock() |
1414 | expected_args = Mock() |
1415 | - mock_schemaconfigglue.return_value = (expected_option_parser, expected_options, |
1416 | - expected_args) |
1417 | + mock_schemaconfigglue.return_value = (expected_option_parser, |
1418 | + expected_options, expected_args) |
1419 | mock_schema_parser.return_value = expected_schema_parser |
1420 | |
1421 | # define the inputs |
1422 | @@ -307,4 +311,3 @@ |
1423 | self.assertEqual(glue.option_parser, expected_option_parser) |
1424 | self.assertEqual(glue.options, expected_options) |
1425 | self.assertEqual(glue.args, expected_args) |
1426 | - |
Approve the change myself, as it's a trivial change.