Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_configparser.py @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | b41eef4b1804 |
| children | e63e2471f46f |
| rev | line source |
|---|---|
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
1 import collections |
|
47012
35a8899256c2
Renamed ConfigParser to configparser.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45446
diff
changeset
|
2 import configparser |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
42050
diff
changeset
|
3 import io |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
4 import os |
|
66707
f1be349234c3
support for checking test coverage added.
Łukasz Langa <lukasz@langa.pl>
parents:
66702
diff
changeset
|
5 import sys |
|
f1be349234c3
support for checking test coverage added.
Łukasz Langa <lukasz@langa.pl>
parents:
66702
diff
changeset
|
6 import textwrap |
| 25910 | 7 import unittest |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
8 import warnings |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
47012
diff
changeset
|
10 from test import support |
|
15480
3c33f2c357d3
Add test cases for ConfigParser.remove_option() behavior. This includes
Fred Drake <fdrake@acm.org>
parents:
15305
diff
changeset
|
11 |
|
45185
8ef3c7c00470
Migrate remaining tests from UserDict.UserDict to collections.UserDict.
Raymond Hettinger <python@rcn.com>
parents:
42501
diff
changeset
|
12 class SortedDict(collections.UserDict): |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
13 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
14 def items(self): |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40742
diff
changeset
|
15 return sorted(self.data.items()) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
16 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
17 def keys(self): |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40742
diff
changeset
|
18 return sorted(self.data.keys()) |
|
40742
f1701ba2452b
Merged revisions 53538-53622 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40587
diff
changeset
|
19 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
20 def values(self): |
|
40809
f340cb045bf9
- PEP 3106: dict.iterkeys(), .iteritems(), .itervalues() are now gone;
Guido van Rossum <guido@python.org>
parents:
40742
diff
changeset
|
21 return [i[1] for i in self.items()] |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
22 |
|
69657
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
23 def iteritems(self): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
24 return iter(self.items()) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
25 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
26 def iterkeys(self): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
27 return iter(self.keys()) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
28 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
29 def itervalues(self): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
30 return iter(self.values()) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
31 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
32 __iter__ = iterkeys |
|
22296
9a091d72136a
backport akuchling's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20321
diff
changeset
|
33 |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
34 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
35 class CfgParserTestCaseClass(unittest.TestCase): |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
36 allow_no_value = False |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
37 delimiters = ('=', ':') |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
38 comment_prefixes = (';', '#') |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
39 inline_comment_prefixes = (';', '#') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
40 empty_lines_in_values = True |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
41 dict_type = configparser._default_dict |
| 63875 | 42 strict = False |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
43 default_section = configparser.DEFAULTSECT |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
44 interpolation = configparser._UNSET |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
45 |
| 25910 | 46 def newconfig(self, defaults=None): |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
47 arguments = dict( |
| 63875 | 48 defaults=defaults, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
49 allow_no_value=self.allow_no_value, |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
50 delimiters=self.delimiters, |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
51 comment_prefixes=self.comment_prefixes, |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
52 inline_comment_prefixes=self.inline_comment_prefixes, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
53 empty_lines_in_values=self.empty_lines_in_values, |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
54 dict_type=self.dict_type, |
| 63875 | 55 strict=self.strict, |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
56 default_section=self.default_section, |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
57 interpolation=self.interpolation, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
58 ) |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
59 instance = self.config_class(**arguments) |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
60 return instance |
| 25910 | 61 |
| 62 def fromstring(self, string, defaults=None): | |
| 63 cf = self.newconfig(defaults) | |
| 63875 | 64 cf.read_string(string) |
| 25910 | 65 return cf |
|
16771
b235160f1346
Make sure ConfigParser uses .optionxform() consistently; this affects
Fred Drake <fdrake@acm.org>
parents:
16595
diff
changeset
|
66 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
67 class BasicTestCase(CfgParserTestCaseClass): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
68 |
| 63875 | 69 def basic_test(self, cf): |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
70 E = ['Commented Bar', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
71 'Foo Bar', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
72 'Internationalized Stuff', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
73 'Long Line', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
74 'Section\\with$weird%characters[\t', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
75 'Spaces', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
76 'Spacey Bar', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
77 'Spacey Bar From The Beginning', |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
78 'Types', |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
79 ] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
80 |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
81 if self.allow_no_value: |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
82 E.append('NoValue') |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
83 E.sort() |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
84 F = [('baz', 'qwe'), ('foo', 'bar3')] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
85 |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
86 # API access |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
87 L = cf.sections() |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
88 L.sort() |
| 25910 | 89 eq = self.assertEqual |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
90 eq(L, E) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
91 L = cf.items('Spacey Bar From The Beginning') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
92 L.sort() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
93 eq(L, F) |
|
16771
b235160f1346
Make sure ConfigParser uses .optionxform() consistently; this affects
Fred Drake <fdrake@acm.org>
parents:
16595
diff
changeset
|
94 |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
95 # mapping access |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
96 L = [section for section in cf] |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
97 L.sort() |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
98 E.append(self.default_section) |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
99 E.sort() |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
100 eq(L, E) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
101 L = cf['Spacey Bar From The Beginning'].items() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
102 L = sorted(list(L)) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
103 eq(L, F) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
104 L = cf.items() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
105 L = sorted(list(L)) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
106 self.assertEqual(len(L), len(E)) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
107 for name, section in L: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
108 eq(name, section.name) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
109 eq(cf.defaults(), cf[self.default_section]) |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
110 |
| 25910 | 111 # The use of spaces in the section names serves as a |
| 112 # regression test for SourceForge bug #583248: | |
| 113 # http://www.python.org/sf/583248 | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
114 |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
115 # API access |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
116 eq(cf.get('Foo Bar', 'foo'), 'bar1') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
117 eq(cf.get('Spacey Bar', 'foo'), 'bar2') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
118 eq(cf.get('Spacey Bar From The Beginning', 'foo'), 'bar3') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
119 eq(cf.get('Spacey Bar From The Beginning', 'baz'), 'qwe') |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
120 eq(cf.get('Commented Bar', 'foo'), 'bar4') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
121 eq(cf.get('Commented Bar', 'baz'), 'qwe') |
| 25910 | 122 eq(cf.get('Spaces', 'key with spaces'), 'value') |
| 123 eq(cf.get('Spaces', 'another with spaces'), 'splat!') | |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
124 eq(cf.getint('Types', 'int'), 42) |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
125 eq(cf.get('Types', 'int'), "42") |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
126 self.assertAlmostEqual(cf.getfloat('Types', 'float'), 0.44) |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
127 eq(cf.get('Types', 'float'), "0.44") |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
128 eq(cf.getboolean('Types', 'boolean'), False) |
|
66702
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
129 eq(cf.get('Types', '123'), 'strange but acceptable') |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
130 if self.allow_no_value: |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
131 eq(cf.get('NoValue', 'option-without-value'), None) |
| 25910 | 132 |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
133 # test vars= and fallback= |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
134 eq(cf.get('Foo Bar', 'foo', fallback='baz'), 'bar1') |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
135 eq(cf.get('Foo Bar', 'foo', vars={'foo': 'baz'}), 'baz') |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
136 with self.assertRaises(configparser.NoSectionError): |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
137 cf.get('No Such Foo Bar', 'foo') |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
138 with self.assertRaises(configparser.NoOptionError): |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
139 cf.get('Foo Bar', 'no-such-foo') |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
140 eq(cf.get('No Such Foo Bar', 'foo', fallback='baz'), 'baz') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
141 eq(cf.get('Foo Bar', 'no-such-foo', fallback='baz'), 'baz') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
142 eq(cf.get('Spacey Bar', 'foo', fallback=None), 'bar2') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
143 eq(cf.get('No Such Spacey Bar', 'foo', fallback=None), None) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
144 eq(cf.getint('Types', 'int', fallback=18), 42) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
145 eq(cf.getint('Types', 'no-such-int', fallback=18), 18) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
146 eq(cf.getint('Types', 'no-such-int', fallback="18"), "18") # sic! |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
147 with self.assertRaises(configparser.NoOptionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
148 cf.getint('Types', 'no-such-int') |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
149 self.assertAlmostEqual(cf.getfloat('Types', 'float', |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
150 fallback=0.0), 0.44) |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
151 self.assertAlmostEqual(cf.getfloat('Types', 'no-such-float', |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
152 fallback=0.0), 0.0) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
153 eq(cf.getfloat('Types', 'no-such-float', fallback="0.0"), "0.0") # sic! |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
154 with self.assertRaises(configparser.NoOptionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
155 cf.getfloat('Types', 'no-such-float') |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
156 eq(cf.getboolean('Types', 'boolean', fallback=True), False) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
157 eq(cf.getboolean('Types', 'no-such-boolean', fallback="yes"), |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
158 "yes") # sic! |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
159 eq(cf.getboolean('Types', 'no-such-boolean', fallback=True), True) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
160 with self.assertRaises(configparser.NoOptionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
161 cf.getboolean('Types', 'no-such-boolean') |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
162 eq(cf.getboolean('No Such Types', 'boolean', fallback=True), True) |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
163 if self.allow_no_value: |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
164 eq(cf.get('NoValue', 'option-without-value', fallback=False), None) |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
165 eq(cf.get('NoValue', 'no-such-option-without-value', |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
166 fallback=False), False) |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
167 |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
168 # mapping access |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
169 eq(cf['Foo Bar']['foo'], 'bar1') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
170 eq(cf['Spacey Bar']['foo'], 'bar2') |
|
66350
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
171 section = cf['Spacey Bar From The Beginning'] |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
172 eq(section.name, 'Spacey Bar From The Beginning') |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
173 self.assertIs(section.parser, cf) |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
174 with self.assertRaises(AttributeError): |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
175 section.name = 'Name is read-only' |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
176 with self.assertRaises(AttributeError): |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
177 section.parser = 'Parser is read-only' |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
178 eq(section['foo'], 'bar3') |
|
f8ceb6afd7a9
configparser: read-only attributes to get the section name and parser from a SectionProxy instance
Łukasz Langa <lukasz@langa.pl>
parents:
66349
diff
changeset
|
179 eq(section['baz'], 'qwe') |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
180 eq(cf['Commented Bar']['foo'], 'bar4') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
181 eq(cf['Commented Bar']['baz'], 'qwe') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
182 eq(cf['Spaces']['key with spaces'], 'value') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
183 eq(cf['Spaces']['another with spaces'], 'splat!') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
184 eq(cf['Long Line']['foo'], |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
185 'this line is much, much longer than my editor\nlikes it.') |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
186 if self.allow_no_value: |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
187 eq(cf['NoValue']['option-without-value'], None) |
|
66722
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
188 # test vars= and fallback= |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
189 eq(cf['Foo Bar'].get('foo', 'baz'), 'bar1') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
190 eq(cf['Foo Bar'].get('foo', fallback='baz'), 'bar1') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
191 eq(cf['Foo Bar'].get('foo', vars={'foo': 'baz'}), 'baz') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
192 with self.assertRaises(KeyError): |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
193 cf['No Such Foo Bar']['foo'] |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
194 with self.assertRaises(KeyError): |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
195 cf['Foo Bar']['no-such-foo'] |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
196 with self.assertRaises(KeyError): |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
197 cf['No Such Foo Bar'].get('foo', fallback='baz') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
198 eq(cf['Foo Bar'].get('no-such-foo', 'baz'), 'baz') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
199 eq(cf['Foo Bar'].get('no-such-foo', fallback='baz'), 'baz') |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
200 eq(cf['Foo Bar'].get('no-such-foo'), None) |
|
66722
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
201 eq(cf['Spacey Bar'].get('foo', None), 'bar2') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
202 eq(cf['Spacey Bar'].get('foo', fallback=None), 'bar2') |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
203 with self.assertRaises(KeyError): |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
204 cf['No Such Spacey Bar'].get('foo', None) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
205 eq(cf['Types'].getint('int', 18), 42) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
206 eq(cf['Types'].getint('int', fallback=18), 42) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
207 eq(cf['Types'].getint('no-such-int', 18), 18) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
208 eq(cf['Types'].getint('no-such-int', fallback=18), 18) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
209 eq(cf['Types'].getint('no-such-int', "18"), "18") # sic! |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
210 eq(cf['Types'].getint('no-such-int', fallback="18"), "18") # sic! |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
211 eq(cf['Types'].getint('no-such-int'), None) |
|
66722
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
212 self.assertAlmostEqual(cf['Types'].getfloat('float', 0.0), 0.44) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
213 self.assertAlmostEqual(cf['Types'].getfloat('float', |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
214 fallback=0.0), 0.44) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
215 self.assertAlmostEqual(cf['Types'].getfloat('no-such-float', 0.0), 0.0) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
216 self.assertAlmostEqual(cf['Types'].getfloat('no-such-float', |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
217 fallback=0.0), 0.0) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
218 eq(cf['Types'].getfloat('no-such-float', "0.0"), "0.0") # sic! |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
219 eq(cf['Types'].getfloat('no-such-float', fallback="0.0"), "0.0") # sic! |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
220 eq(cf['Types'].getfloat('no-such-float'), None) |
|
66722
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
221 eq(cf['Types'].getboolean('boolean', True), False) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
222 eq(cf['Types'].getboolean('boolean', fallback=True), False) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
223 eq(cf['Types'].getboolean('no-such-boolean', "yes"), "yes") # sic! |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
224 eq(cf['Types'].getboolean('no-such-boolean', fallback="yes"), |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
225 "yes") # sic! |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
226 eq(cf['Types'].getboolean('no-such-boolean', True), True) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
227 eq(cf['Types'].getboolean('no-such-boolean', fallback=True), True) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
228 eq(cf['Types'].getboolean('no-such-boolean'), None) |
|
66722
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
229 if self.allow_no_value: |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
230 eq(cf['NoValue'].get('option-without-value', False), None) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
231 eq(cf['NoValue'].get('option-without-value', fallback=False), None) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
232 eq(cf['NoValue'].get('no-such-option-without-value', False), False) |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
233 eq(cf['NoValue'].get('no-such-option-without-value', |
|
3fee88e6442a
configparser: mapping protocol access get() handles configparser-specific arguments as well
Łukasz Langa <lukasz@langa.pl>
parents:
66707
diff
changeset
|
234 fallback=False), False) |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
235 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
236 # Make sure the right things happen for remove_section() and |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
237 # remove_option(); added to include check for SourceForge bug #123324. |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
238 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
239 cf[self.default_section]['this_value'] = '1' |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
240 cf[self.default_section]['that_value'] = '2' |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
241 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
242 # API access |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
243 self.assertTrue(cf.remove_section('Spaces')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
244 self.assertFalse(cf.has_option('Spaces', 'key with spaces')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
245 self.assertFalse(cf.remove_section('Spaces')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
246 self.assertFalse(cf.remove_section(self.default_section)) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
247 self.assertTrue(cf.remove_option('Foo Bar', 'foo'), |
|
51776
d06a3ebf306f
Merged revisions 69846 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
248 "remove_option() failed to report existence of option") |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
249 self.assertFalse(cf.has_option('Foo Bar', 'foo'), |
| 25910 | 250 "remove_option() failed to remove option") |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
251 self.assertFalse(cf.remove_option('Foo Bar', 'foo'), |
|
51776
d06a3ebf306f
Merged revisions 69846 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
252 "remove_option() failed to report non-existence of option" |
| 25910 | 253 " that was removed") |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
254 self.assertTrue(cf.has_option('Foo Bar', 'this_value')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
255 self.assertFalse(cf.remove_option('Foo Bar', 'this_value')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
256 self.assertTrue(cf.remove_option(self.default_section, 'this_value')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
257 self.assertFalse(cf.has_option('Foo Bar', 'this_value')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
258 self.assertFalse(cf.remove_option(self.default_section, 'this_value')) |
| 25910 | 259 |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
260 with self.assertRaises(configparser.NoSectionError) as cm: |
|
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
261 cf.remove_option('No Such Section', 'foo') |
|
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
262 self.assertEqual(cm.exception.args, ('No Such Section',)) |
| 25910 | 263 |
| 264 eq(cf.get('Long Line', 'foo'), | |
| 265 'this line is much, much longer than my editor\nlikes it.') | |
|
20321
267c6fe0abc2
Added tests that check getboolean() with the newly allowed values from
Fred Drake <fdrake@acm.org>
parents:
18407
diff
changeset
|
266 |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
267 # mapping access |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
268 del cf['Types'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
269 self.assertFalse('Types' in cf) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
270 with self.assertRaises(KeyError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
271 del cf['Types'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
272 with self.assertRaises(ValueError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
273 del cf[self.default_section] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
274 del cf['Spacey Bar']['foo'] |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
275 self.assertFalse('foo' in cf['Spacey Bar']) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
276 with self.assertRaises(KeyError): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
277 del cf['Spacey Bar']['foo'] |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
278 self.assertTrue('that_value' in cf['Spacey Bar']) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
279 with self.assertRaises(KeyError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
280 del cf['Spacey Bar']['that_value'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
281 del cf[self.default_section]['that_value'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
282 self.assertFalse('that_value' in cf['Spacey Bar']) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
283 with self.assertRaises(KeyError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
284 del cf[self.default_section]['that_value'] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
285 with self.assertRaises(KeyError): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
286 del cf['No Such Section']['foo'] |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
287 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
288 # Don't add new asserts below in this method as most of the options |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
289 # and sections are now removed. |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
290 |
| 63875 | 291 def test_basic(self): |
| 292 config_string = """\ | |
| 293 [Foo Bar] | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
294 foo{0[0]}bar1 |
| 63875 | 295 [Spacey Bar] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
296 foo {0[0]} bar2 |
| 63875 | 297 [Spacey Bar From The Beginning] |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
298 foo {0[0]} bar3 |
| 63875 | 299 baz {0[0]} qwe |
| 300 [Commented Bar] | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
301 foo{0[1]} bar4 {1[1]} comment |
| 63875 | 302 baz{0[0]}qwe {1[0]}another one |
| 303 [Long Line] | |
| 304 foo{0[1]} this line is much, much longer than my editor | |
| 305 likes it. | |
| 306 [Section\\with$weird%characters[\t] | |
| 307 [Internationalized Stuff] | |
| 308 foo[bg]{0[1]} Bulgarian | |
| 309 foo{0[0]}Default | |
| 310 foo[en]{0[0]}English | |
| 311 foo[de]{0[0]}Deutsch | |
| 312 [Spaces] | |
| 313 key with spaces {0[1]} value | |
| 314 another with spaces {0[0]} splat! | |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
315 [Types] |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
316 int {0[1]} 42 |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
317 float {0[0]} 0.44 |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
318 boolean {0[0]} NO |
|
66702
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
319 123 {0[1]} strange but acceptable |
| 63875 | 320 """.format(self.delimiters, self.comment_prefixes) |
| 321 if self.allow_no_value: | |
| 322 config_string += ( | |
| 323 "[NoValue]\n" | |
| 324 "option-without-value\n" | |
| 325 ) | |
| 326 cf = self.fromstring(config_string) | |
| 327 self.basic_test(cf) | |
| 328 if self.strict: | |
| 329 with self.assertRaises(configparser.DuplicateOptionError): | |
| 330 cf.read_string(textwrap.dedent("""\ | |
| 331 [Duplicate Options Here] | |
| 332 option {0[0]} with a value | |
| 333 option {0[1]} with another value | |
| 334 """.format(self.delimiters))) | |
| 335 with self.assertRaises(configparser.DuplicateSectionError): | |
| 336 cf.read_string(textwrap.dedent("""\ | |
| 337 [And Now For Something] | |
| 338 completely different {0[0]} True | |
| 339 [And Now For Something] | |
| 340 the larch {0[1]} 1 | |
| 341 """.format(self.delimiters))) | |
| 342 else: | |
| 343 cf.read_string(textwrap.dedent("""\ | |
| 344 [Duplicate Options Here] | |
| 345 option {0[0]} with a value | |
| 346 option {0[1]} with another value | |
| 347 """.format(self.delimiters))) | |
| 348 | |
| 349 cf.read_string(textwrap.dedent("""\ | |
| 350 [And Now For Something] | |
| 351 completely different {0[0]} True | |
| 352 [And Now For Something] | |
| 353 the larch {0[1]} 1 | |
| 354 """.format(self.delimiters))) | |
| 355 | |
| 356 def test_basic_from_dict(self): | |
| 357 config = { | |
| 358 "Foo Bar": { | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
359 "foo": "bar1", |
| 63875 | 360 }, |
| 361 "Spacey Bar": { | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
362 "foo": "bar2", |
| 63875 | 363 }, |
| 364 "Spacey Bar From The Beginning": { | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
365 "foo": "bar3", |
| 63875 | 366 "baz": "qwe", |
| 367 }, | |
| 368 "Commented Bar": { | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
369 "foo": "bar4", |
| 63875 | 370 "baz": "qwe", |
| 371 }, | |
| 372 "Long Line": { | |
| 373 "foo": "this line is much, much longer than my editor\nlikes " | |
| 374 "it.", | |
| 375 }, | |
| 376 "Section\\with$weird%characters[\t": { | |
| 377 }, | |
| 378 "Internationalized Stuff": { | |
| 379 "foo[bg]": "Bulgarian", | |
| 380 "foo": "Default", | |
| 381 "foo[en]": "English", | |
| 382 "foo[de]": "Deutsch", | |
| 383 }, | |
| 384 "Spaces": { | |
| 385 "key with spaces": "value", | |
| 386 "another with spaces": "splat!", | |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
387 }, |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
388 "Types": { |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
389 "int": 42, |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
390 "float": 0.44, |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
391 "boolean": False, |
|
66702
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
392 123: "strange but acceptable", |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
393 }, |
| 63875 | 394 } |
| 395 if self.allow_no_value: | |
| 396 config.update({ | |
| 397 "NoValue": { | |
| 398 "option-without-value": None, | |
| 399 } | |
| 400 }) | |
| 401 cf = self.newconfig() | |
| 402 cf.read_dict(config) | |
| 403 self.basic_test(cf) | |
| 404 if self.strict: | |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
405 with self.assertRaises(configparser.DuplicateSectionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
406 cf.read_dict({ |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
407 '1': {'key': 'value'}, |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
408 1: {'key2': 'value2'}, |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
409 }) |
| 63875 | 410 with self.assertRaises(configparser.DuplicateOptionError): |
| 411 cf.read_dict({ | |
| 412 "Duplicate Options Here": { | |
| 413 'option': 'with a value', | |
| 414 'OPTION': 'with another value', | |
| 415 }, | |
| 416 }) | |
| 417 else: | |
| 418 cf.read_dict({ | |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
419 'section': {'key': 'value'}, |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
420 'SECTION': {'key2': 'value2'}, |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
421 }) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
422 cf.read_dict({ |
| 63875 | 423 "Duplicate Options Here": { |
| 424 'option': 'with a value', | |
| 425 'OPTION': 'with another value', | |
| 426 }, | |
| 427 }) | |
| 428 | |
| 25910 | 429 def test_case_sensitivity(self): |
| 430 cf = self.newconfig() | |
| 431 cf.add_section("A") | |
| 432 cf.add_section("a") | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
433 cf.add_section("B") |
| 25910 | 434 L = cf.sections() |
| 435 L.sort() | |
| 436 eq = self.assertEqual | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
437 eq(L, ["A", "B", "a"]) |
| 25910 | 438 cf.set("a", "B", "value") |
| 439 eq(cf.options("a"), ["b"]) | |
| 440 eq(cf.get("a", "b"), "value", | |
| 441 "could not locate option, expecting case-insensitive option names") | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
442 with self.assertRaises(configparser.NoSectionError): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
443 # section names are case-sensitive |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
444 cf.set("b", "A", "value") |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
445 self.assertTrue(cf.has_option("a", "b")) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
446 self.assertFalse(cf.has_option("b", "b")) |
| 25910 | 447 cf.set("A", "A-B", "A-B value") |
| 448 for opt in ("a-b", "A-b", "a-B", "A-B"): | |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
449 self.assertTrue( |
| 25910 | 450 cf.has_option("A", opt), |
| 451 "has_option() returned false for option which should exist") | |
| 452 eq(cf.options("A"), ["a-b"]) | |
| 453 eq(cf.options("a"), ["b"]) | |
| 454 cf.remove_option("a", "B") | |
| 455 eq(cf.options("a"), []) | |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
456 |
| 25910 | 457 # SF bug #432369: |
| 458 cf = self.fromstring( | |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
459 "[MySection]\nOption{} first line \n\tsecond line \n".format( |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
460 self.delimiters[0])) |
| 25910 | 461 eq(cf.options("MySection"), ["option"]) |
| 462 eq(cf.get("MySection", "Option"), "first line\nsecond line") | |
| 463 | |
| 464 # SF bug #561822: | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
465 cf = self.fromstring("[section]\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
466 "nekey{}nevalue\n".format(self.delimiters[0]), |
| 25910 | 467 defaults={"key":"value"}) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
468 self.assertTrue(cf.has_option("section", "Key")) |
|
25909
0bac66e1b356
Added (very) minimal tests of the RawConfigParser class.
Fred Drake <fdrake@acm.org>
parents:
25462
diff
changeset
|
469 |
|
16576
f654468b9ae8
Added options that use square brackets in their names; this ensures that
Fred Drake <fdrake@acm.org>
parents:
15480
diff
changeset
|
470 |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
471 def test_case_sensitivity_mapping_access(self): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
472 cf = self.newconfig() |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
473 cf["A"] = {} |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
474 cf["a"] = {"B": "value"} |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
475 cf["B"] = {} |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
476 L = [section for section in cf] |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
477 L.sort() |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
478 eq = self.assertEqual |
|
66530
93cd4de8ee0b
Use assertCountEqual instead of assertItemsEqual
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66350
diff
changeset
|
479 elem_eq = self.assertCountEqual |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
480 eq(L, sorted(["A", "B", self.default_section, "a"])) |
|
66143
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
481 eq(cf["a"].keys(), {"b"}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
482 eq(cf["a"]["b"], "value", |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
483 "could not locate option, expecting case-insensitive option names") |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
484 with self.assertRaises(KeyError): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
485 # section names are case-sensitive |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
486 cf["b"]["A"] = "value" |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
487 self.assertTrue("b" in cf["a"]) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
488 cf["A"]["A-B"] = "A-B value" |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
489 for opt in ("a-b", "A-b", "a-B", "A-B"): |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
490 self.assertTrue( |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
491 opt in cf["A"], |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
492 "has_option() returned false for option which should exist") |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
493 eq(cf["A"].keys(), {"a-b"}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
494 eq(cf["a"].keys(), {"b"}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
495 del cf["a"]["B"] |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
496 elem_eq(cf["a"].keys(), {}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
497 |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
498 # SF bug #432369: |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
499 cf = self.fromstring( |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
500 "[MySection]\nOption{} first line \n\tsecond line \n".format( |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
501 self.delimiters[0])) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
502 eq(cf["MySection"].keys(), {"option"}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
503 eq(cf["MySection"]["Option"], "first line\nsecond line") |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
504 |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
505 # SF bug #561822: |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
506 cf = self.fromstring("[section]\n" |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
507 "nekey{}nevalue\n".format(self.delimiters[0]), |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
508 defaults={"key":"value"}) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
509 self.assertTrue("Key" in cf["section"]) |
|
e546f7605cf1
Issue #5412: extend configparser to support mapping access
Łukasz Langa <lukasz@langa.pl>
parents:
64898
diff
changeset
|
510 |
|
33662
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
511 def test_default_case_sensitivity(self): |
|
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
512 cf = self.newconfig({"foo": "Bar"}) |
|
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
513 self.assertEqual( |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
514 cf.get(self.default_section, "Foo"), "Bar", |
|
33662
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
515 "could not locate option, expecting case-insensitive option names") |
|
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
516 cf = self.newconfig({"Foo": "Bar"}) |
|
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
517 self.assertEqual( |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
518 cf.get(self.default_section, "Foo"), "Bar", |
|
33662
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
519 "could not locate option, expecting case-insensitive defaults") |
|
cc4684051c46
SF bug #1017864: ConfigParser now correctly handles default keys, processing them with ``ConfigParser.optionxform`` when supplied, consistent with the handling of config file entries and runtime-set options.
David Goodger <goodger@python.org>
parents:
32117
diff
changeset
|
520 |
| 25910 | 521 def test_parse_errors(self): |
| 63875 | 522 cf = self.newconfig() |
| 523 self.parse_error(cf, configparser.ParsingError, | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
524 "[Foo]\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
525 "{}val-without-opt-name\n".format(self.delimiters[0])) |
| 63875 | 526 self.parse_error(cf, configparser.ParsingError, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
527 "[Foo]\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
528 "{}val-without-opt-name\n".format(self.delimiters[1])) |
| 63875 | 529 e = self.parse_error(cf, configparser.MissingSectionHeaderError, |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
530 "No Section!\n") |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
531 self.assertEqual(e.args, ('<???>', 1, "No Section!\n")) |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
532 if not self.allow_no_value: |
| 63875 | 533 e = self.parse_error(cf, configparser.ParsingError, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
534 "[Foo]\n wrong-indent\n") |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
535 self.assertEqual(e.args, ('<???>',)) |
|
64897
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
536 # read_file on a real file |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
537 tricky = support.findfile("cfgparser.3") |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
538 if self.delimiters[0] == '=': |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
539 error = configparser.ParsingError |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
540 expected = (tricky,) |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
541 else: |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
542 error = configparser.MissingSectionHeaderError |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
543 expected = (tricky, 1, |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
544 ' # INI with as many tricky parts as possible\n') |
|
64898
f703a643e6ce
Fix encoding for test case added in r84967.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64897
diff
changeset
|
545 with open(tricky, encoding='utf-8') as f: |
|
64897
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
546 e = self.parse_error(cf, error, f) |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
547 self.assertEqual(e.args, expected) |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
548 |
| 63875 | 549 def parse_error(self, cf, exc, src): |
|
64897
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
550 if hasattr(src, 'readline'): |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
551 sio = src |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
552 else: |
|
d5001d6c7736
Fix typo and add test case.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
64424
diff
changeset
|
553 sio = io.StringIO(src) |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
554 with self.assertRaises(exc) as cm: |
| 63875 | 555 cf.read_file(sio) |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
556 return cm.exception |
| 25910 | 557 |
| 558 def test_query_errors(self): | |
| 559 cf = self.newconfig() | |
| 560 self.assertEqual(cf.sections(), [], | |
| 561 "new ConfigParser should have no defined sections") | |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
562 self.assertFalse(cf.has_section("Foo"), |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
563 "new ConfigParser should have no acknowledged " |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
564 "sections") |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
565 with self.assertRaises(configparser.NoSectionError): |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
566 cf.options("Foo") |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
567 with self.assertRaises(configparser.NoSectionError): |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
568 cf.set("foo", "bar", "value") |
| 63875 | 569 e = self.get_error(cf, configparser.NoSectionError, "foo", "bar") |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
570 self.assertEqual(e.args, ("foo",)) |
| 25910 | 571 cf.add_section("foo") |
| 63875 | 572 e = self.get_error(cf, configparser.NoOptionError, "foo", "bar") |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
573 self.assertEqual(e.args, ("bar", "foo")) |
| 25910 | 574 |
| 63875 | 575 def get_error(self, cf, exc, section, option): |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
576 try: |
| 63875 | 577 cf.get(section, option) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
578 except exc as e: |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
579 return e |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
580 else: |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
581 self.fail("expected exception type %s.%s" |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
582 % (exc.__module__, exc.__name__)) |
|
16576
f654468b9ae8
Added options that use square brackets in their names; this ensures that
Fred Drake <fdrake@acm.org>
parents:
15480
diff
changeset
|
583 |
| 25910 | 584 def test_boolean(self): |
| 585 cf = self.fromstring( | |
| 586 "[BOOLTEST]\n" | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
587 "T1{equals}1\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
588 "T2{equals}TRUE\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
589 "T3{equals}True\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
590 "T4{equals}oN\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
591 "T5{equals}yes\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
592 "F1{equals}0\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
593 "F2{equals}FALSE\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
594 "F3{equals}False\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
595 "F4{equals}oFF\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
596 "F5{equals}nO\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
597 "E1{equals}2\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
598 "E2{equals}foo\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
599 "E3{equals}-1\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
600 "E4{equals}0.1\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
601 "E5{equals}FALSE AND MORE".format(equals=self.delimiters[0]) |
| 25910 | 602 ) |
| 603 for x in range(1, 5): | |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
604 self.assertTrue(cf.getboolean('BOOLTEST', 't%d' % x)) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53524
diff
changeset
|
605 self.assertFalse(cf.getboolean('BOOLTEST', 'f%d' % x)) |
| 25910 | 606 self.assertRaises(ValueError, |
| 607 cf.getboolean, 'BOOLTEST', 'e%d' % x) | |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
608 |
| 25910 | 609 def test_weird_errors(self): |
| 610 cf = self.newconfig() | |
| 611 cf.add_section("Foo") | |
|
63216
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
612 with self.assertRaises(configparser.DuplicateSectionError) as cm: |
|
9ecbdefc9849
Issue #4686 - add .args to exceptions in the configparsermodule
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
58949
diff
changeset
|
613 cf.add_section("Foo") |
| 63875 | 614 e = cm.exception |
| 615 self.assertEqual(str(e), "Section 'Foo' already exists") | |
| 616 self.assertEqual(e.args, ("Foo", None, None)) | |
| 617 | |
| 618 if self.strict: | |
| 619 with self.assertRaises(configparser.DuplicateSectionError) as cm: | |
| 620 cf.read_string(textwrap.dedent("""\ | |
| 621 [Foo] | |
| 622 will this be added{equals}True | |
| 623 [Bar] | |
| 624 what about this{equals}True | |
| 625 [Foo] | |
| 626 oops{equals}this won't | |
| 627 """.format(equals=self.delimiters[0])), source='<foo-bar>') | |
| 628 e = cm.exception | |
| 629 self.assertEqual(str(e), "While reading from <foo-bar> [line 5]: " | |
| 630 "section 'Foo' already exists") | |
| 631 self.assertEqual(e.args, ("Foo", '<foo-bar>', 5)) | |
| 632 | |
| 633 with self.assertRaises(configparser.DuplicateOptionError) as cm: | |
| 634 cf.read_dict({'Bar': {'opt': 'val', 'OPT': 'is really `opt`'}}) | |
| 635 e = cm.exception | |
| 636 self.assertEqual(str(e), "While reading from <dict>: option 'opt' " | |
| 637 "in section 'Bar' already exists") | |
| 638 self.assertEqual(e.args, ("Bar", "opt", "<dict>", None)) | |
|
16576
f654468b9ae8
Added options that use square brackets in their names; this ensures that
Fred Drake <fdrake@acm.org>
parents:
15480
diff
changeset
|
639 |
| 25910 | 640 def test_write(self): |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
641 config_string = ( |
| 25910 | 642 "[Long Line]\n" |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
643 "foo{0[0]} this line is much, much longer than my editor\n" |
| 25910 | 644 " likes it.\n" |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
645 "[{default_section}]\n" |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
646 "foo{0[1]} another very\n" |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
647 " long line\n" |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
648 "[Long Line - With Comments!]\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
649 "test {0[1]} we {comment} can\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
650 " also {comment} place\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
651 " comments {comment} in\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
652 " multiline {comment} values" |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
653 "\n".format(self.delimiters, comment=self.comment_prefixes[0], |
|
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
654 default_section=self.default_section) |
| 25910 | 655 ) |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
656 if self.allow_no_value: |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
657 config_string += ( |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
658 "[Valueless]\n" |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
659 "option-without-value\n" |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
660 ) |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
661 |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
662 cf = self.fromstring(config_string) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
663 for space_around_delimiters in (True, False): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
664 output = io.StringIO() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
665 cf.write(output, space_around_delimiters=space_around_delimiters) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
666 delimiter = self.delimiters[0] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
667 if space_around_delimiters: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
668 delimiter = " {} ".format(delimiter) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
669 expect_string = ( |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
670 "[{default_section}]\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
671 "foo{equals}another very\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
672 "\tlong line\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
673 "\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
674 "[Long Line]\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
675 "foo{equals}this line is much, much longer than my editor\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
676 "\tlikes it.\n" |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
677 "\n" |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
678 "[Long Line - With Comments!]\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
679 "test{equals}we\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
680 "\talso\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
681 "\tcomments\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
682 "\tmultiline\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
683 "\n".format(equals=delimiter, |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
684 default_section=self.default_section) |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
685 ) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
686 if self.allow_no_value: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
687 expect_string += ( |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
688 "[Valueless]\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
689 "option-without-value\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
690 "\n" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
691 ) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
692 self.assertEqual(output.getvalue(), expect_string) |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
693 |
| 32115 | 694 def test_set_string_types(self): |
| 695 cf = self.fromstring("[sect]\n" | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
696 "option1{eq}foo\n".format(eq=self.delimiters[0])) |
| 32115 | 697 # Check that we don't get an exception when setting values in |
| 698 # an existing section using strings: | |
| 699 class mystr(str): | |
| 700 pass | |
| 701 cf.set("sect", "option1", "splat") | |
| 702 cf.set("sect", "option1", mystr("splat")) | |
| 703 cf.set("sect", "option2", "splat") | |
| 704 cf.set("sect", "option2", mystr("splat")) | |
|
42050
ca693f4fd05d
Simplify various spots where: str() is called on something
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
705 cf.set("sect", "option1", "splat") |
|
ca693f4fd05d
Simplify various spots where: str() is called on something
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
706 cf.set("sect", "option2", "splat") |
| 32115 | 707 |
| 32117 | 708 def test_read_returns_file_list(self): |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
709 if self.delimiters[0] != '=': |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
710 # skip reading the file if we're using an incompatible format |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
711 return |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
47012
diff
changeset
|
712 file1 = support.findfile("cfgparser.1") |
| 32117 | 713 # check when we pass a mix of readable and non-readable files: |
| 714 cf = self.newconfig() | |
|
51776
d06a3ebf306f
Merged revisions 69846 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
715 parsed_files = cf.read([file1, "nonexistent-file"]) |
| 32117 | 716 self.assertEqual(parsed_files, [file1]) |
| 717 self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") | |
| 718 # check when we pass only a filename: | |
| 719 cf = self.newconfig() | |
| 720 parsed_files = cf.read(file1) | |
| 721 self.assertEqual(parsed_files, [file1]) | |
| 722 self.assertEqual(cf.get("Foo Bar", "foo"), "newbar") | |
| 723 # check when we pass only missing files: | |
| 724 cf = self.newconfig() | |
|
51776
d06a3ebf306f
Merged revisions 69846 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
725 parsed_files = cf.read(["nonexistent-file"]) |
| 32117 | 726 self.assertEqual(parsed_files, []) |
| 727 # check when we pass no files: | |
| 728 cf = self.newconfig() | |
| 729 parsed_files = cf.read([]) | |
| 730 self.assertEqual(parsed_files, []) | |
| 731 | |
| 25910 | 732 # shared by subclasses |
| 733 def get_interpolation_config(self): | |
| 734 return self.fromstring( | |
| 735 "[Foo]\n" | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
736 "bar{equals}something %(with1)s interpolation (1 step)\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
737 "bar9{equals}something %(with9)s lots of interpolation (9 steps)\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
738 "bar10{equals}something %(with10)s lots of interpolation (10 steps)\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
739 "bar11{equals}something %(with11)s lots of interpolation (11 steps)\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
740 "with11{equals}%(with10)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
741 "with10{equals}%(with9)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
742 "with9{equals}%(with8)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
743 "with8{equals}%(With7)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
744 "with7{equals}%(WITH6)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
745 "with6{equals}%(with5)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
746 "With5{equals}%(with4)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
747 "WITH4{equals}%(with3)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
748 "with3{equals}%(with2)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
749 "with2{equals}%(with1)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
750 "with1{equals}with\n" |
| 25910 | 751 "\n" |
| 752 "[Mutual Recursion]\n" | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
753 "foo{equals}%(bar)s\n" |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
754 "bar{equals}%(foo)s\n" |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
755 "\n" |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
756 "[Interpolation Error]\n" |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
757 # no definition for 'reference' |
|
66349
c13f8980ca7f
Issue #10489: removed broken `__name__` support from configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66310
diff
changeset
|
758 "name{equals}%(reference)s\n".format(equals=self.delimiters[0])) |
|
16576
f654468b9ae8
Added options that use square brackets in their names; this ensures that
Fred Drake <fdrake@acm.org>
parents:
15480
diff
changeset
|
759 |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
760 def check_items_config(self, expected): |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
761 cf = self.fromstring(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
762 [section] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
763 name {0[0]} %(value)s |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
764 key{0[1]} |%(name)s| |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
765 getdefault{0[1]} |%(default)s| |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
766 """.format(self.delimiters), defaults={"default": "<default>"}) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
767 L = list(cf.items("section", vars={'value': 'value'})) |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
768 L.sort() |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
769 self.assertEqual(L, expected) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
770 with self.assertRaises(configparser.NoSectionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
771 cf.items("no such section") |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
772 |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
773 |
| 63875 | 774 class StrictTestCase(BasicTestCase): |
| 775 config_class = configparser.RawConfigParser | |
| 776 strict = True | |
| 777 | |
| 778 | |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
779 class ConfigParserTestCase(BasicTestCase): |
|
47012
35a8899256c2
Renamed ConfigParser to configparser.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45446
diff
changeset
|
780 config_class = configparser.ConfigParser |
|
25909
0bac66e1b356
Added (very) minimal tests of the RawConfigParser class.
Fred Drake <fdrake@acm.org>
parents:
25462
diff
changeset
|
781 |
| 25910 | 782 def test_interpolation(self): |
| 783 cf = self.get_interpolation_config() | |
| 784 eq = self.assertEqual | |
| 785 eq(cf.get("Foo", "bar"), "something with interpolation (1 step)") | |
| 786 eq(cf.get("Foo", "bar9"), | |
| 787 "something with lots of interpolation (9 steps)") | |
| 788 eq(cf.get("Foo", "bar10"), | |
| 789 "something with lots of interpolation (10 steps)") | |
| 63875 | 790 e = self.get_error(cf, configparser.InterpolationDepthError, "Foo", "bar11") |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
791 if self.interpolation == configparser._UNSET: |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
792 self.assertEqual(e.args, ("bar11", "Foo", "%(with1)s")) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
793 elif isinstance(self.interpolation, configparser.LegacyInterpolation): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
794 self.assertEqual(e.args, ("bar11", "Foo", |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
795 "something %(with11)s lots of interpolation (11 steps)")) |
|
25909
0bac66e1b356
Added (very) minimal tests of the RawConfigParser class.
Fred Drake <fdrake@acm.org>
parents:
25462
diff
changeset
|
796 |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
797 def test_interpolation_missing_value(self): |
| 63875 | 798 cf = self.get_interpolation_config() |
| 799 e = self.get_error(cf, configparser.InterpolationMissingOptionError, | |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
800 "Interpolation Error", "name") |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
801 self.assertEqual(e.reference, "reference") |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
802 self.assertEqual(e.section, "Interpolation Error") |
|
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
803 self.assertEqual(e.option, "name") |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
804 if self.interpolation == configparser._UNSET: |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
805 self.assertEqual(e.args, ('name', 'Interpolation Error', |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
806 '', 'reference')) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
807 elif isinstance(self.interpolation, configparser.LegacyInterpolation): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
808 self.assertEqual(e.args, ('name', 'Interpolation Error', |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
809 '%(reference)s', 'reference')) |
|
26928
24cb62225040
Add a test that InterpolationError is constructed properly and raised
Fred Drake <fdrake@acm.org>
parents:
25918
diff
changeset
|
810 |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
811 def test_items(self): |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
812 self.check_items_config([('default', '<default>'), |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
813 ('getdefault', '|<default>|'), |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
814 ('key', '|value|'), |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
815 ('name', 'value'), |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
816 ('value', 'value')]) |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
817 |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
818 def test_safe_interpolation(self): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
819 # See http://www.python.org/sf/511737 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
820 cf = self.fromstring("[section]\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
821 "option1{eq}xxx\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
822 "option2{eq}%(option1)s/xxx\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
823 "ok{eq}%(option1)s/%%s\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
824 "not_ok{eq}%(option2)s/%%s".format( |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
825 eq=self.delimiters[0])) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
826 self.assertEqual(cf.get("section", "ok"), "xxx/%s") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
827 if self.interpolation == configparser._UNSET: |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
828 self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
829 elif isinstance(self.interpolation, configparser.LegacyInterpolation): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
830 with self.assertRaises(TypeError): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
831 cf.get("section", "not_ok") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
832 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
833 def test_set_malformatted_interpolation(self): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
834 cf = self.fromstring("[sect]\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
835 "option1{eq}foo\n".format(eq=self.delimiters[0])) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
836 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
837 self.assertEqual(cf.get('sect', "option1"), "foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
838 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
839 self.assertRaises(ValueError, cf.set, "sect", "option1", "%foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
840 self.assertRaises(ValueError, cf.set, "sect", "option1", "foo%") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
841 self.assertRaises(ValueError, cf.set, "sect", "option1", "f%oo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
842 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
843 self.assertEqual(cf.get('sect', "option1"), "foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
844 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
845 # bug #5741: double percents are *not* malformed |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
846 cf.set("sect", "option2", "foo%%bar") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
847 self.assertEqual(cf.get("sect", "option2"), "foo%bar") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
848 |
|
33663
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
849 def test_set_nonstring_types(self): |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
850 cf = self.fromstring("[sect]\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
851 "option1{eq}foo\n".format(eq=self.delimiters[0])) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
852 # Check that we get a TypeError when setting non-string values |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
853 # in an existing section: |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
854 self.assertRaises(TypeError, cf.set, "sect", "option1", 1) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
855 self.assertRaises(TypeError, cf.set, "sect", "option1", 1.0) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
856 self.assertRaises(TypeError, cf.set, "sect", "option1", object()) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
857 self.assertRaises(TypeError, cf.set, "sect", "option2", 1) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
858 self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
859 self.assertRaises(TypeError, cf.set, "sect", "option2", object()) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
860 self.assertRaises(TypeError, cf.set, "sect", 123, "invalid opt name!") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
861 self.assertRaises(TypeError, cf.add_section, 123) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
862 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
863 def test_add_section_default(self): |
|
33663
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
864 cf = self.newconfig() |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
865 self.assertRaises(ValueError, cf.add_section, self.default_section) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
866 |
|
69668
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
867 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
868 class ConfigParserTestCaseNoInterpolation(BasicTestCase): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
869 config_class = configparser.ConfigParser |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
870 interpolation = None |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
871 ini = textwrap.dedent(""" |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
872 [numbers] |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
873 one = 1 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
874 two = %(one)s * 2 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
875 three = ${common:one} * 3 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
876 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
877 [hexen] |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
878 sixteen = ${numbers:two} * 8 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
879 """).strip() |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
880 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
881 def assertMatchesIni(self, cf): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
882 self.assertEqual(cf['numbers']['one'], '1') |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
883 self.assertEqual(cf['numbers']['two'], '%(one)s * 2') |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
884 self.assertEqual(cf['numbers']['three'], '${common:one} * 3') |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
885 self.assertEqual(cf['hexen']['sixteen'], '${numbers:two} * 8') |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
886 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
887 def test_no_interpolation(self): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
888 cf = self.fromstring(self.ini) |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
889 self.assertMatchesIni(cf) |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
890 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
891 def test_empty_case(self): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
892 cf = self.newconfig() |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
893 self.assertIsNone(cf.read_string("")) |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
894 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
895 def test_none_as_default_interpolation(self): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
896 class CustomConfigParser(configparser.ConfigParser): |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
897 _DEFAULT_INTERPOLATION = None |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
898 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
899 cf = CustomConfigParser() |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
900 cf.read_string(self.ini) |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
901 self.assertMatchesIni(cf) |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
902 |
|
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
903 |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
904 class ConfigParserTestCaseLegacyInterpolation(ConfigParserTestCase): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
905 config_class = configparser.ConfigParser |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
906 interpolation = configparser.LegacyInterpolation() |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
907 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
908 def test_set_malformatted_interpolation(self): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
909 cf = self.fromstring("[sect]\n" |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
910 "option1{eq}foo\n".format(eq=self.delimiters[0])) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
911 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
912 self.assertEqual(cf.get('sect', "option1"), "foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
913 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
914 cf.set("sect", "option1", "%foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
915 self.assertEqual(cf.get('sect', "option1"), "%foo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
916 cf.set("sect", "option1", "foo%") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
917 self.assertEqual(cf.get('sect', "option1"), "foo%") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
918 cf.set("sect", "option1", "f%oo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
919 self.assertEqual(cf.get('sect', "option1"), "f%oo") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
920 |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
921 # bug #5741: double percents are *not* malformed |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
922 cf.set("sect", "option2", "foo%%bar") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
923 self.assertEqual(cf.get("sect", "option2"), "foo%%bar") |
|
33663
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
924 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
925 class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
926 delimiters = (':=', '$') |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
927 comment_prefixes = ('//', '"') |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
928 inline_comment_prefixes = ('//', '"') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
929 |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
930 class ConfigParserTestCaseNonStandardDefaultSection(ConfigParserTestCase): |
|
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
931 default_section = 'general' |
|
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
932 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
933 class MultilineValuesTestCase(BasicTestCase): |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
934 config_class = configparser.ConfigParser |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
935 wonderful_spam = ("I'm having spam spam spam spam " |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
936 "spam spam spam beaked beans spam " |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
937 "spam spam and spam!").replace(' ', '\t\n') |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
938 |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
939 def setUp(self): |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
940 cf = self.newconfig() |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
941 for i in range(100): |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
942 s = 'section{}'.format(i) |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
943 cf.add_section(s) |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
944 for j in range(10): |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
945 cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam) |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
946 with open(support.TESTFN, 'w') as f: |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
947 cf.write(f) |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
948 |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
949 def tearDown(self): |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
950 os.unlink(support.TESTFN) |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
951 |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
952 def test_dominating_multiline_values(self): |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
953 # We're reading from file because this is where the code changed |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
954 # during performance updates in Python 3.2 |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
955 cf_from_file = self.newconfig() |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
956 with open(support.TESTFN) as f: |
| 63875 | 957 cf_from_file.read_file(f) |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
958 self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'), |
|
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
959 self.wonderful_spam.replace('\t\n', '\n')) |
|
25909
0bac66e1b356
Added (very) minimal tests of the RawConfigParser class.
Fred Drake <fdrake@acm.org>
parents:
25462
diff
changeset
|
960 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
961 class RawConfigParserTestCase(BasicTestCase): |
|
47012
35a8899256c2
Renamed ConfigParser to configparser.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45446
diff
changeset
|
962 config_class = configparser.RawConfigParser |
|
14900
f932c128279b
Regression test for ConfigParser module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
963 |
| 25910 | 964 def test_interpolation(self): |
| 965 cf = self.get_interpolation_config() | |
| 966 eq = self.assertEqual | |
| 967 eq(cf.get("Foo", "bar"), | |
| 968 "something %(with1)s interpolation (1 step)") | |
| 969 eq(cf.get("Foo", "bar9"), | |
| 970 "something %(with9)s lots of interpolation (9 steps)") | |
| 971 eq(cf.get("Foo", "bar10"), | |
| 972 "something %(with10)s lots of interpolation (10 steps)") | |
| 973 eq(cf.get("Foo", "bar11"), | |
| 974 "something %(with11)s lots of interpolation (11 steps)") | |
| 975 | |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
976 def test_items(self): |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
977 self.check_items_config([('default', '<default>'), |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
978 ('getdefault', '|%(default)s|'), |
|
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
979 ('key', '|%(name)s|'), |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
980 ('name', '%(value)s'), |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
981 ('value', 'value')]) |
|
25917
5b6d55b45287
Add tests for both raw and non-raw versions of the items() methods.
Fred Drake <fdrake@acm.org>
parents:
25910
diff
changeset
|
982 |
|
33663
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
983 def test_set_nonstring_types(self): |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
984 cf = self.newconfig() |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
985 cf.add_section('non-string') |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
986 cf.set('non-string', 'int', 1) |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
987 cf.set('non-string', 'list', [0, 1, 1, 2, 3, 5, 8, 13]) |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
988 cf.set('non-string', 'dict', {'pi': 3.14159}) |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
989 self.assertEqual(cf.get('non-string', 'int'), 1) |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
990 self.assertEqual(cf.get('non-string', 'list'), |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
991 [0, 1, 1, 2, 3, 5, 8, 13]) |
|
5412096d0f95
SF bug #997050: Document, test, & check for non-string values in ConfigParser. Moved the new string-only restriction added in rev. 1.65 to the SafeConfigParser class, leaving existing ConfigParser & RawConfigParser behavior alone, and documented the conditions under which non-string values work.
David Goodger <goodger@python.org>
parents:
33662
diff
changeset
|
992 self.assertEqual(cf.get('non-string', 'dict'), {'pi': 3.14159}) |
|
66702
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
993 cf.add_section(123) |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
994 cf.set(123, 'this is sick', True) |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
995 self.assertEqual(cf.get(123, 'this is sick'), True) |
|
69686
b7309b24528d
__class__ of a __class__ check worked only by chance.
Łukasz Langa <lukasz@langa.pl>
parents:
69668
diff
changeset
|
996 if cf._dict is configparser._default_dict: |
|
66702
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
997 # would not work for SortedDict; only checking for the most common |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
998 # default dictionary (OrderedDict) |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
999 cf.optionxform = lambda x: x |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
1000 cf.set('non-string', 1, 1) |
|
ddc6c47bf825
configparser: fixed inconsistency where in SafeConfigParser option values
Łukasz Langa <lukasz@langa.pl>
parents:
66647
diff
changeset
|
1001 self.assertEqual(cf.get('non-string', 1), 1) |
|
33665
5def66f2c9ab
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
33663
diff
changeset
|
1002 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1003 class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1004 delimiters = (':=', '$') |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1005 comment_prefixes = ('//', '"') |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1006 inline_comment_prefixes = ('//', '"') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1007 |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1008 class RawConfigParserTestSambaConf(CfgParserTestCaseClass): |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1009 config_class = configparser.RawConfigParser |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1010 comment_prefixes = ('#', ';', '----') |
|
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1011 inline_comment_prefixes = ('//',) |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1012 empty_lines_in_values = False |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1013 |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1014 def test_reading(self): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1015 smbconf = support.findfile("cfgparser.2") |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1016 # check when we pass a mix of readable and non-readable files: |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1017 cf = self.newconfig() |
|
63281
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1018 parsed_files = cf.read([smbconf, "nonexistent-file"], encoding='utf-8') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1019 self.assertEqual(parsed_files, [smbconf]) |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1020 sections = ['global', 'homes', 'printers', |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1021 'print$', 'pdf-generator', 'tmp', 'Agustin'] |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1022 self.assertEqual(cf.sections(), sections) |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1023 self.assertEqual(cf.get("global", "workgroup"), "MDKGROUP") |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1024 self.assertEqual(cf.getint("global", "max log size"), 50) |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1025 self.assertEqual(cf.get("global", "hosts allow"), "127.") |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1026 self.assertEqual(cf.get("tmp", "echo command"), "cat %s; rm %s") |
| 25910 | 1027 |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1028 class ConfigParserTestCaseExtendedInterpolation(BasicTestCase): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1029 config_class = configparser.ConfigParser |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1030 interpolation = configparser.ExtendedInterpolation() |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1031 default_section = 'common' |
|
69657
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1032 strict = True |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1033 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1034 def fromstring(self, string, defaults=None, optionxform=None): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1035 cf = self.newconfig(defaults) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1036 if optionxform: |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1037 cf.optionxform = optionxform |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1038 cf.read_string(string) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1039 return cf |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1040 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1041 def test_extended_interpolation(self): |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1042 cf = self.fromstring(textwrap.dedent(""" |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1043 [common] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1044 favourite Beatle = Paul |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1045 favourite color = green |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1046 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1047 [tom] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1048 favourite band = ${favourite color} day |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1049 favourite pope = John ${favourite Beatle} II |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1050 sequel = ${favourite pope}I |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1051 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1052 [ambv] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1053 favourite Beatle = George |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1054 son of Edward VII = ${favourite Beatle} V |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1055 son of George V = ${son of Edward VII}I |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1056 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1057 [stanley] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1058 favourite Beatle = ${ambv:favourite Beatle} |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1059 favourite pope = ${tom:favourite pope} |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1060 favourite color = black |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1061 favourite state of mind = paranoid |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1062 favourite movie = soylent ${common:favourite color} |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1063 favourite song = ${favourite color} sabbath - ${favourite state of mind} |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1064 """).strip()) |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1065 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1066 eq = self.assertEqual |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1067 eq(cf['common']['favourite Beatle'], 'Paul') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1068 eq(cf['common']['favourite color'], 'green') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1069 eq(cf['tom']['favourite Beatle'], 'Paul') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1070 eq(cf['tom']['favourite color'], 'green') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1071 eq(cf['tom']['favourite band'], 'green day') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1072 eq(cf['tom']['favourite pope'], 'John Paul II') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1073 eq(cf['tom']['sequel'], 'John Paul III') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1074 eq(cf['ambv']['favourite Beatle'], 'George') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1075 eq(cf['ambv']['favourite color'], 'green') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1076 eq(cf['ambv']['son of Edward VII'], 'George V') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1077 eq(cf['ambv']['son of George V'], 'George VI') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1078 eq(cf['stanley']['favourite Beatle'], 'George') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1079 eq(cf['stanley']['favourite color'], 'black') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1080 eq(cf['stanley']['favourite state of mind'], 'paranoid') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1081 eq(cf['stanley']['favourite movie'], 'soylent green') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1082 eq(cf['stanley']['favourite pope'], 'John Paul II') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1083 eq(cf['stanley']['favourite song'], |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1084 'black sabbath - paranoid') |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1085 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1086 def test_endless_loop(self): |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1087 cf = self.fromstring(textwrap.dedent(""" |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1088 [one for you] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1089 ping = ${one for me:pong} |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1090 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1091 [one for me] |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1092 pong = ${one for you:ping} |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1093 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1094 [selfish] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1095 me = ${me} |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1096 """).strip()) |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1097 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1098 with self.assertRaises(configparser.InterpolationDepthError): |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1099 cf['one for you']['ping'] |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1100 with self.assertRaises(configparser.InterpolationDepthError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1101 cf['selfish']['me'] |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1102 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1103 def test_strange_options(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1104 cf = self.fromstring(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1105 [dollars] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1106 $var = $$value |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1107 $var2 = ${$var} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1108 ${sick} = cannot interpolate me |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1109 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1110 [interpolated] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1111 $other = ${dollars:$var} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1112 $trying = ${dollars:${sick}} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1113 """) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1114 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1115 self.assertEqual(cf['dollars']['$var'], '$value') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1116 self.assertEqual(cf['interpolated']['$other'], '$value') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1117 self.assertEqual(cf['dollars']['${sick}'], 'cannot interpolate me') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1118 exception_class = configparser.InterpolationMissingOptionError |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1119 with self.assertRaises(exception_class) as cm: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1120 cf['interpolated']['$trying'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1121 self.assertEqual(cm.exception.reference, 'dollars:${sick') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1122 self.assertEqual(cm.exception.args[2], '}') #rawval |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1123 |
|
69657
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1124 def test_case_sensitivity_basic(self): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1125 ini = textwrap.dedent(""" |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1126 [common] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1127 optionlower = value |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1128 OptionUpper = Value |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1129 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1130 [Common] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1131 optionlower = a better ${common:optionlower} |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1132 OptionUpper = A Better ${common:OptionUpper} |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1133 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1134 [random] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1135 foolower = ${common:optionlower} redefined |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1136 FooUpper = ${Common:OptionUpper} Redefined |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1137 """).strip() |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1138 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1139 cf = self.fromstring(ini) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1140 eq = self.assertEqual |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1141 eq(cf['common']['optionlower'], 'value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1142 eq(cf['common']['OptionUpper'], 'Value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1143 eq(cf['Common']['optionlower'], 'a better value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1144 eq(cf['Common']['OptionUpper'], 'A Better Value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1145 eq(cf['random']['foolower'], 'value redefined') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1146 eq(cf['random']['FooUpper'], 'A Better Value Redefined') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1147 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1148 def test_case_sensitivity_conflicts(self): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1149 ini = textwrap.dedent(""" |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1150 [common] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1151 option = value |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1152 Option = Value |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1153 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1154 [Common] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1155 option = a better ${common:option} |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1156 Option = A Better ${common:Option} |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1157 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1158 [random] |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1159 foo = ${common:option} redefined |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1160 Foo = ${Common:Option} Redefined |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1161 """).strip() |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1162 with self.assertRaises(configparser.DuplicateOptionError): |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1163 cf = self.fromstring(ini) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1164 |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1165 # raw options |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1166 cf = self.fromstring(ini, optionxform=lambda opt: opt) |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1167 eq = self.assertEqual |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1168 eq(cf['common']['option'], 'value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1169 eq(cf['common']['Option'], 'Value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1170 eq(cf['Common']['option'], 'a better value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1171 eq(cf['Common']['Option'], 'A Better Value') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1172 eq(cf['random']['foo'], 'value redefined') |
|
57c076ab4bbd
Closes #11858: configparser.ExtendedInterpolation and section case.
Łukasz Langa <lukasz@langa.pl>
parents:
69631
diff
changeset
|
1173 eq(cf['random']['Foo'], 'A Better Value Redefined') |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1174 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1175 def test_other_errors(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1176 cf = self.fromstring(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1177 [interpolation fail] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1178 case1 = ${where's the brace |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1179 case2 = ${does_not_exist} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1180 case3 = ${wrong_section:wrong_value} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1181 case4 = ${i:like:colon:characters} |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1182 case5 = $100 for Fail No 5! |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1183 """) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1184 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1185 with self.assertRaises(configparser.InterpolationSyntaxError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1186 cf['interpolation fail']['case1'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1187 with self.assertRaises(configparser.InterpolationMissingOptionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1188 cf['interpolation fail']['case2'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1189 with self.assertRaises(configparser.InterpolationMissingOptionError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1190 cf['interpolation fail']['case3'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1191 with self.assertRaises(configparser.InterpolationSyntaxError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1192 cf['interpolation fail']['case4'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1193 with self.assertRaises(configparser.InterpolationSyntaxError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1194 cf['interpolation fail']['case5'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1195 with self.assertRaises(ValueError): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1196 cf['interpolation fail']['case6'] = "BLACK $ABBATH" |
|
66647
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1197 |
|
5fda519834df
Issue 10499: Modular interpolation in configparser
Łukasz Langa <lukasz@langa.pl>
parents:
66530
diff
changeset
|
1198 |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1199 class ConfigParserTestCaseNoValue(ConfigParserTestCase): |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1200 allow_no_value = True |
|
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1201 |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1202 class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1203 config_class = configparser.ConfigParser |
|
63281
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1204 delimiters = {'='} |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1205 comment_prefixes = {'#'} |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1206 allow_no_value = True |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1207 |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1208 def test_cfgparser_dot_3(self): |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1209 tricky = support.findfile("cfgparser.3") |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1210 cf = self.newconfig() |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1211 self.assertEqual(len(cf.read(tricky, encoding='utf-8')), 1) |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1212 self.assertEqual(cf.sections(), ['strange', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1213 'corruption', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1214 'yeah, sections can be ' |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1215 'indented as well', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1216 'another one!', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1217 'no values here', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1218 'tricky interpolation', |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1219 'more interpolation']) |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
1220 self.assertEqual(cf.getint(self.default_section, 'go', |
|
64424
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
1221 vars={'interpolate': '-1'}), -1) |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
1222 with self.assertRaises(ValueError): |
|
b2b262c5daa8
add consistent support for the vars and default arguments on all
Fred Drake <fdrake@acm.org>
parents:
64386
diff
changeset
|
1223 # no interpolation will happen |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
1224 cf.getint(self.default_section, 'go', raw=True, |
|
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
1225 vars={'interpolate': '-1'}) |
|
63281
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1226 self.assertEqual(len(cf.get('strange', 'other').split('\n')), 4) |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1227 self.assertEqual(len(cf.get('corruption', 'value').split('\n')), 10) |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1228 longname = 'yeah, sections can be indented as well' |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1229 self.assertFalse(cf.getboolean(longname, 'are they subsections')) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1230 self.assertEqual(cf.get(longname, 'lets use some Unicode'), '片仮名') |
|
63281
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1231 self.assertEqual(len(cf.items('another one!')), 5) # 4 in section and |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1232 # `go` from DEFAULT |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1233 with self.assertRaises(configparser.InterpolationMissingOptionError): |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1234 cf.items('no values here') |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1235 self.assertEqual(cf.get('tricky interpolation', 'lets'), 'do this') |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1236 self.assertEqual(cf.get('tricky interpolation', 'lets'), |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1237 cf.get('tricky interpolation', 'go')) |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1238 self.assertEqual(cf.get('more interpolation', 'lets'), 'go shopping') |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1239 |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1240 def test_unicode_failure(self): |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1241 tricky = support.findfile("cfgparser.3") |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1242 cf = self.newconfig() |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1243 with self.assertRaises(UnicodeDecodeError): |
|
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1244 cf.read(tricky, encoding='ascii') |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1245 |
|
64386
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1246 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1247 class Issue7005TestCase(unittest.TestCase): |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1248 """Test output when None is set() as a value and allow_no_value == False. |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1249 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1250 http://bugs.python.org/issue7005 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1251 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1252 """ |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1253 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1254 expected_output = "[section]\noption = None\n\n" |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1255 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1256 def prepare(self, config_class): |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1257 # This is the default, but that's the point. |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1258 cp = config_class(allow_no_value=False) |
|
64386
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1259 cp.add_section("section") |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1260 cp.set("section", "option", None) |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1261 sio = io.StringIO() |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1262 cp.write(sio) |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1263 return sio.getvalue() |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1264 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1265 def test_none_as_value_stringified(self): |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1266 cp = configparser.ConfigParser(allow_no_value=False) |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1267 cp.add_section("section") |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1268 with self.assertRaises(TypeError): |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1269 cp.set("section", "option", None) |
|
64386
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1270 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1271 def test_none_as_value_stringified_raw(self): |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1272 output = self.prepare(configparser.RawConfigParser) |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1273 self.assertEqual(output, self.expected_output) |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1274 |
|
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1275 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
1276 class SortedTestCase(RawConfigParserTestCase): |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1277 dict_type = SortedDict |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
1278 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
33665
diff
changeset
|
1279 def test_sorted(self): |
| 63875 | 1280 cf = self.fromstring("[b]\n" |
| 1281 "o4=1\n" | |
| 1282 "o3=2\n" | |
| 1283 "o2=3\n" | |
| 1284 "o1=4\n" | |
| 1285 "[a]\n" | |
| 1286 "k=v\n") | |
|
42501
f6069f9dd52d
SF patch# 1770008 by Christian Heimes (plus some extras).
Guido van Rossum <guido@python.org>
parents:
42050
diff
changeset
|
1287 output = io.StringIO() |
| 63875 | 1288 cf.write(output) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1289 self.assertEqual(output.getvalue(), |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1290 "[a]\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1291 "k = v\n\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1292 "[b]\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1293 "o1 = 4\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1294 "o2 = 3\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1295 "o3 = 2\n" |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66287
diff
changeset
|
1296 "o4 = 1\n\n") |
|
25918
9901fda7c366
Implement a safer and more predictable interpolation approach.
Fred Drake <fdrake@acm.org>
parents:
25917
diff
changeset
|
1297 |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1298 |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1299 class CompatibleTestCase(CfgParserTestCaseClass): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1300 config_class = configparser.RawConfigParser |
|
66981
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1301 comment_prefixes = '#;' |
|
074c21714a02
configparser API cleanup: default values now sensible, slightly incompatible.
Łukasz Langa <lukasz@langa.pl>
parents:
66953
diff
changeset
|
1302 inline_comment_prefixes = ';' |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1303 |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1304 def test_comment_handling(self): |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1305 config_string = textwrap.dedent("""\ |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1306 [Commented Bar] |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1307 baz=qwe ; a comment |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1308 foo: bar # not a comment! |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1309 # but this is a comment |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1310 ; another comment |
|
63281
e5a2f50fee64
#9411: allow selecting an encoding for configparser files. Also adds a new test config file to test special cases.
Georg Brandl <georg@python.org>
parents:
63264
diff
changeset
|
1311 quirk: this;is not a comment |
|
63380
9eb4ba45a6b2
Clarify comment in comments test case explaining comment semantics.
Georg Brandl <georg@python.org>
parents:
63281
diff
changeset
|
1312 ; a space must precede an inline comment |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1313 """) |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1314 cf = self.fromstring(config_string) |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1315 self.assertEqual(cf.get('Commented Bar', 'foo'), |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1316 'bar # not a comment!') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1317 self.assertEqual(cf.get('Commented Bar', 'baz'), 'qwe') |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1318 self.assertEqual(cf.get('Commented Bar', 'quirk'), |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1319 'this;is not a comment') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1320 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1321 class CopyTestCase(BasicTestCase): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1322 config_class = configparser.ConfigParser |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1323 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1324 def fromstring(self, string, defaults=None): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1325 cf = self.newconfig(defaults) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1326 cf.read_string(string) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1327 cf_copy = self.newconfig() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1328 cf_copy.read_dict(cf) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1329 # we have to clean up option duplicates that appeared because of |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1330 # the magic DEFAULTSECT behaviour. |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1331 for section in cf_copy.values(): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1332 if section.name == self.default_section: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1333 continue |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1334 for default, value in cf[self.default_section].items(): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1335 if section[default] == value: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1336 del section[default] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1337 return cf_copy |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1338 |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1339 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1340 class FakeFile: |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1341 def __init__(self): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1342 file_path = support.findfile("cfgparser.1") |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1343 with open(file_path) as f: |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1344 self.lines = f.readlines() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1345 self.lines.reverse() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1346 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1347 def readline(self): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1348 if len(self.lines): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1349 return self.lines.pop() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1350 return '' |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1351 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1352 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1353 def readline_generator(f): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1354 """As advised in Doc/library/configparser.rst.""" |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1355 line = f.readline() |
|
69663
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1356 while line: |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1357 yield line |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1358 line = f.readline() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1359 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1360 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1361 class ReadFileTestCase(unittest.TestCase): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1362 def test_file(self): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1363 file_path = support.findfile("cfgparser.1") |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1364 parser = configparser.ConfigParser() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1365 with open(file_path) as f: |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1366 parser.read_file(f) |
|
69663
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1367 self.assertIn("Foo Bar", parser) |
|
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1368 self.assertIn("foo", parser["Foo Bar"]) |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1369 self.assertEqual(parser["Foo Bar"]["foo"], "newbar") |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1370 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1371 def test_iterable(self): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1372 lines = textwrap.dedent(""" |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1373 [Foo Bar] |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1374 foo=newbar""").strip().split('\n') |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1375 parser = configparser.ConfigParser() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1376 parser.read_file(lines) |
|
69663
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1377 self.assertIn("Foo Bar", parser) |
|
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1378 self.assertIn("foo", parser["Foo Bar"]) |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1379 self.assertEqual(parser["Foo Bar"]["foo"], "newbar") |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1380 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1381 def test_readline_generator(self): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1382 """Issue #11670.""" |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1383 parser = configparser.ConfigParser() |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1384 with self.assertRaises(TypeError): |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1385 parser.read_file(FakeFile()) |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1386 parser.read_file(readline_generator(FakeFile())) |
|
69663
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1387 self.assertIn("Foo Bar", parser) |
|
1bbda00bbe78
Style updates for the #11670 solution after post-commit review by Ezio Melotti:
Łukasz Langa <lukasz@langa.pl>
parents:
69657
diff
changeset
|
1388 self.assertIn("foo", parser["Foo Bar"]) |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1389 self.assertEqual(parser["Foo Bar"]["foo"], "newbar") |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1390 |
|
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1391 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1392 class CoverageOneHundredTestCase(unittest.TestCase): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1393 """Covers edge cases in the codebase.""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1394 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1395 def test_duplicate_option_error(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1396 error = configparser.DuplicateOptionError('section', 'option') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1397 self.assertEqual(error.section, 'section') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1398 self.assertEqual(error.option, 'option') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1399 self.assertEqual(error.source, None) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1400 self.assertEqual(error.lineno, None) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1401 self.assertEqual(error.args, ('section', 'option', None, None)) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1402 self.assertEqual(str(error), "Option 'option' in section 'section' " |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1403 "already exists") |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1404 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1405 def test_interpolation_depth_error(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1406 error = configparser.InterpolationDepthError('option', 'section', |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1407 'rawval') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1408 self.assertEqual(error.args, ('option', 'section', 'rawval')) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1409 self.assertEqual(error.option, 'option') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1410 self.assertEqual(error.section, 'section') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1411 |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1412 def test_parsing_error(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1413 with self.assertRaises(ValueError) as cm: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1414 configparser.ParsingError() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1415 self.assertEqual(str(cm.exception), "Required argument `source' not " |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1416 "given.") |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1417 with self.assertRaises(ValueError) as cm: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1418 configparser.ParsingError(source='source', filename='filename') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1419 self.assertEqual(str(cm.exception), "Cannot specify both `filename' " |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1420 "and `source'. Use `source'.") |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1421 error = configparser.ParsingError(filename='source') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1422 self.assertEqual(error.source, 'source') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1423 with warnings.catch_warnings(record=True) as w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1424 warnings.simplefilter("always", DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1425 self.assertEqual(error.filename, 'source') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1426 error.filename = 'filename' |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1427 self.assertEqual(error.source, 'filename') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1428 for warning in w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1429 self.assertTrue(warning.category is DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1430 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1431 def test_interpolation_validation(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1432 parser = configparser.ConfigParser() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1433 parser.read_string(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1434 [section] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1435 invalid_percent = % |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1436 invalid_reference = %(() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1437 invalid_variable = %(does_not_exist)s |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1438 """) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1439 with self.assertRaises(configparser.InterpolationSyntaxError) as cm: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1440 parser['section']['invalid_percent'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1441 self.assertEqual(str(cm.exception), "'%' must be followed by '%' or " |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1442 "'(', found: '%'") |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1443 with self.assertRaises(configparser.InterpolationSyntaxError) as cm: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1444 parser['section']['invalid_reference'] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1445 self.assertEqual(str(cm.exception), "bad interpolation variable " |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1446 "reference '%(()'") |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1447 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1448 def test_readfp_deprecation(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1449 sio = io.StringIO(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1450 [section] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1451 option = value |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1452 """) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1453 parser = configparser.ConfigParser() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1454 with warnings.catch_warnings(record=True) as w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1455 warnings.simplefilter("always", DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1456 parser.readfp(sio, filename='StringIO') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1457 for warning in w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1458 self.assertTrue(warning.category is DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1459 self.assertEqual(len(parser), 2) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1460 self.assertEqual(parser['section']['option'], 'value') |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1461 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1462 def test_safeconfigparser_deprecation(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1463 with warnings.catch_warnings(record=True) as w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1464 warnings.simplefilter("always", DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1465 parser = configparser.SafeConfigParser() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1466 for warning in w: |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1467 self.assertTrue(warning.category is DeprecationWarning) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1468 |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1469 def test_sectionproxy_repr(self): |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1470 parser = configparser.ConfigParser() |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1471 parser.read_string(""" |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1472 [section] |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1473 key = value |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1474 """) |
|
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1475 self.assertEqual(repr(parser['section']), '<Section: section>') |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1476 |
| 25910 | 1477 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
47012
diff
changeset
|
1478 support.run_unittest( |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
26928
diff
changeset
|
1479 ConfigParserTestCase, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1480 ConfigParserTestCaseNonStandardDelimiters, |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1481 ConfigParserTestCaseNoValue, |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1482 ConfigParserTestCaseExtendedInterpolation, |
|
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1483 ConfigParserTestCaseLegacyInterpolation, |
|
69668
32031e33d793
Closes #11324: ConfigParser(interpolation=None) doesn't work.
Łukasz Langa <lukasz@langa.pl>
parents:
69663
diff
changeset
|
1484 ConfigParserTestCaseNoInterpolation, |
|
66953
3de6cd902624
Broken ConfigParser removed, SafeConfigParser renamed to ConfigParser.
Łukasz Langa <lukasz@langa.pl>
parents:
66722
diff
changeset
|
1485 ConfigParserTestCaseTrickyFile, |
|
63220
fdb71d6c1822
Fix #7113. Patch by Łukasz Langa.
Brian Curtin <brian.curtin@gmail.com>
parents:
63216
diff
changeset
|
1486 MultilineValuesTestCase, |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
26928
diff
changeset
|
1487 RawConfigParserTestCase, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1488 RawConfigParserTestCaseNonStandardDelimiters, |
|
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1489 RawConfigParserTestSambaConf, |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1490 SortedTestCase, |
|
64386
16d8a4e94dd0
fix output from RawConfigParser.write and ConfigParser.write for None
Fred Drake <fdrake@acm.org>
parents:
63875
diff
changeset
|
1491 Issue7005TestCase, |
| 63875 | 1492 StrictTestCase, |
|
63264
bb9eef8d1ac6
#1682942: add some ConfigParser features: alternate delimiters, alternate comments, empty lines in values. Also enhance the docs with more examples and mention SafeConfigParser before ConfigParser. Patch by Lukas Langa, review by myself, Eric and Ezio.
Georg Brandl <georg@python.org>
parents:
63220
diff
changeset
|
1493 CompatibleTestCase, |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1494 CopyTestCase, |
|
66287
51e1cbdd8fd2
configparser: the name of the DEFAULT section is now customizable
Łukasz Langa <lukasz@langa.pl>
parents:
66143
diff
changeset
|
1495 ConfigParserTestCaseNonStandardDefaultSection, |
|
69631
6f937d6369b6
Closes #11670: configparser read_file now iterates over f.
Łukasz Langa <lukasz@langa.pl>
parents:
68257
diff
changeset
|
1496 ReadFileTestCase, |
|
66997
892236137db9
100% test coverage, better mapping protocol compatibility, some minor bugfixes
Łukasz Langa <lukasz@langa.pl>
parents:
66981
diff
changeset
|
1497 CoverageOneHundredTestCase, |
|
58949
4fc8b6fe4af8
Merged revisions 78232 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
58456
diff
changeset
|
1498 ) |
