except ImportError:
import ConfigParser as configparser
import contextlib
+import sys
from ceph_deploy import exc
return iter(self.readline, '')
class CephConf(configparser.RawConfigParser):
+ def __init__(self, *args, **kwargs):
+ if sys.version_info >= (3, 2):
+ kwargs.setdefault('strict', False)
+ # super() cannot be used with an old-style class
+ configparser.RawConfigParser.__init__(self, *args, **kwargs)
+
def optionxform(self, s):
s = s.replace('_', ' ')
s = '_'.join(s.split())
assert cfg.get('foo', 'bar_thud_quux') == 'baz'
assert cfg.get('foo', 'bar thud quux') == 'baz'
+
def test_write_words_underscore():
cfg = conf.ceph.CephConf()
cfg.add_section('foo')
cfg.write(f)
f.seek(0)
assert f.readlines() == ['[foo]\n', 'bar_thud_quux = baz\n','\n']
+
+
+def test_section_repeat():
+ f = StringIO("""\
+[foo]
+bar = bez
+thud = quux
+
+[foo]
+bar = baz
+""")
+ cfg = conf.ceph.parse(f)
+ assert cfg.get('foo', 'bar') == 'baz'
+ assert cfg.get('foo', 'thud') == 'quux'