Hello community,
here is the log from the commit of package python-iniparse for openSUSE:Factory
checked in at Fri Aug 7 23:51:10 CEST 2009.
--------
--- python-iniparse/python-iniparse.changes 2009-01-07 15:19:12.000000000 +0100
+++ python-iniparse/python-iniparse.changes 2009-08-05 18:14:07.000000000 +0200
@@ -1,0 +2,7 @@
+Wed Aug 5 18:13:14 CEST 2009 - matejcik@suse.cz
+
+- update to 0.3.1
+ * minor bugfixes
+ * better multi-line handling
+
+-------------------------------------------------------------------
calling whatdependson for head-i586
Old:
----
iniparse-0.2.4.tar.gz
New:
----
iniparse-0.3.1.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-iniparse.spec ++++++
--- /var/tmp/diff_new_pack.yMrxpd/_old 2009-08-07 23:50:06.000000000 +0200
+++ /var/tmp/diff_new_pack.yMrxpd/_new 2009-08-07 23:50:06.000000000 +0200
@@ -1,5 +1,5 @@
#
-# spec file for package python-iniparse (Version 0.2.4)
+# spec file for package python-iniparse (Version 0.3.1)
#
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
@@ -20,11 +20,11 @@
Name: python-iniparse
BuildRequires: python-setuptools
-Version: 0.2.4
-Release: 3
+Version: 0.3.1
+Release: 1
Summary: Python Module for Accessing and Modifying Configuration Data in INI files
Group: Development/Libraries/Python
-License: X11/MIT
+License: MIT License (or similar)
Url: http://code.google.com/p/iniparse/
Source0: http://iniparse.googlecode.com/files/iniparse-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
@@ -51,16 +51,16 @@
chmod 644 html/index.html
%install
-%{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT --prefix=%{_prefix}
+%{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT --prefix=%{_prefix} --record-rpm=INSTALLED_FILES
# fixes
rm -rf $RPM_BUILD_ROOT/usr/share/doc/iniparse-%{version}
+grep -v "share/doc/iniparse-%{version}" INSTALLED_FILES > INSTALLED_FILES-nodoc
%clean
rm -rf $RPM_BUILD_ROOT
-%files
+%files -f INSTALLED_FILES-nodoc
%defattr(-,root,root,-)
%doc Changelog LICENSE LICENSE-PSF README html/index.html html/style.css
-%{py_sitedir}/*
%changelog
++++++ iniparse-0.2.4.tar.gz -> iniparse-0.3.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/Changelog new/iniparse-0.3.1/Changelog
--- old/iniparse-0.2.4/Changelog 2008-12-06 22:17:09.000000000 +0100
+++ new/iniparse-0.3.1/Changelog 2009-03-02 16:10:56.000000000 +0100
@@ -1,3 +1,27 @@
+2009-03-02
+* released 0.3.1
+
+2009-03-01
+* Fix empty line bugs introduced by the compatibility hack
+
+2009-02-27
+* released 0.3.0
+
+2009-02-22
+* Make INIConfig objects pickle-able
+* Fix the defaults() method
+* Replicate ConfigParser behavior regarding empty lines in
+ multi-line values - empty lines are stripped on parsing,
+ but preserved when the value is explicitly set.
+
+2009-02-10
+* Skip DEFAULT section when listing sections (issue 8)
+
+2009-02-03
+* Bugfixes for continuation line behavior, based on patch by
+ sidnei.da.silva - (1) preserve empty lines in multi-line
+ values, and (2) fix assignment to multi-line values
+
2008-12-06
* released 0.2.4
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/PKG-INFO new/iniparse-0.3.1/PKG-INFO
--- old/iniparse-0.2.4/PKG-INFO 2008-12-06 23:12:45.000000000 +0100
+++ new/iniparse-0.3.1/PKG-INFO 2009-03-02 16:13:59.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: iniparse
-Version: 0.2.4
+Version: 0.3.1
Summary: Accessing and Modifying INI files
Home-page: http://code.google.com/p/iniparse/
Author: Paramjit Oberoi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/README new/iniparse-0.3.1/README
--- old/iniparse-0.2.4/README 2008-12-06 23:02:36.000000000 +0100
+++ new/iniparse-0.3.1/README 2009-02-27 17:30:37.000000000 +0100
@@ -22,7 +22,7 @@
Website: http://code.google.com/p/iniparse/
Mailing List: iniparse-discuss@googlegroups.com
-Copyright (c) 2001, 2002, 2003 Python Software Foundation
-Copyright (c) 2004-2008 Paramjit Oberoi
+Copyright (c) 2001-2008 Python Software Foundation
+Copyright (c) 2004-2009 Paramjit Oberoi
Copyright (c) 2007 Tim Lauridsen
All Rights Reserved. See LICENSE-PSF & LICENSE for details.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/iniparse/compat.py new/iniparse-0.3.1/iniparse/compat.py
--- old/iniparse-0.2.4/iniparse/compat.py 2008-12-06 22:41:36.000000000 +0100
+++ new/iniparse-0.3.1/iniparse/compat.py 2009-02-22 22:18:07.000000000 +0100
@@ -37,8 +37,9 @@
def defaults(self):
d = {}
- for name, lineobj in self.data._defaults._options:
- d[name] = lineobj.value
+ secobj = self.data._defaults
+ for name in secobj._options:
+ d[name] = secobj._compat_get(name)
return d
def sections(self):
@@ -119,7 +120,8 @@
if vars is not None and option in vars:
value = vars[option]
try:
- return self.data[section][option]
+ sec = self.data[section]
+ return sec._compat_get(option)
except KeyError:
raise NoOptionError(option, section)
@@ -127,7 +129,7 @@
try:
ans = []
for opt in self.data[section]:
- ans.append((opt, self.data[section][opt]))
+ ans.append((opt, self.get(section, opt)))
return ans
except KeyError:
raise NoSectionError(section)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/iniparse/config.py new/iniparse-0.3.1/iniparse/config.py
--- old/iniparse-0.2.4/iniparse/config.py 2008-12-06 22:47:49.000000000 +0100
+++ new/iniparse-0.3.1/iniparse/config.py 2009-02-23 01:09:20.000000000 +0100
@@ -63,6 +63,12 @@
except AttributeError:
self.__delitem__(name)
+ def __getstate__(self):
+ return self.__dict__
+
+ def __setstate__(self, state):
+ self.__dict__.update(state)
+
class Undefined(object):
"""Helper class used to hold undefined names until assignment.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/iniparse/ini.py new/iniparse-0.3.1/iniparse/ini.py
--- old/iniparse-0.2.4/iniparse/ini.py 2008-12-06 22:47:45.000000000 +0100
+++ new/iniparse-0.3.1/iniparse/ini.py 2009-03-01 23:30:31.000000000 +0100
@@ -183,6 +183,8 @@
def to_string(self):
return ''
+ value = property(lambda _: '')
+
def parse(cls, line):
if line.strip(): return None
return cls(line)
@@ -192,9 +194,11 @@
class ContinuationLine(LineType):
regex = re.compile(r'^\s+(?P<value>.*)$')
- def __init__(self, value, value_offset=8, line=None):
+ def __init__(self, value, value_offset=None, line=None):
super(ContinuationLine, self).__init__(line)
self.value = value
+ if value_offset is None:
+ value_offset = 8
self.value_offset = value_offset
def to_string(self):
@@ -235,19 +239,28 @@
return self.contents[0].value
else:
return '\n'.join([('%s' % x.value) for x in self.contents
- if not isinstance(x, (CommentLine, EmptyLine))])
+ if not isinstance(x, CommentLine)])
def set_value(self, data):
self.orgvalue = data
lines = ('%s' % data).split('\n')
- linediff = len(lines) - len(self.contents)
- if linediff > 0:
- for _ in range(linediff):
- self.add(ContinuationLine(''))
- elif linediff < 0:
- self.contents = self.contents[:linediff]
- for i,v in enumerate(lines):
- self.contents[i].value = v
+
+ # If there is an existing ContinuationLine, use its offset
+ value_offset = None
+ for v in self.contents:
+ if isinstance(v, ContinuationLine):
+ value_offset = v.value_offset
+ break
+
+ # Rebuild contents list, preserving initial OptionLine
+ self.contents = self.contents[0:1]
+ self.contents[0].value = lines[0]
+ del lines[0]
+ for line in lines:
+ if line.strip():
+ self.add(ContinuationLine(line, value_offset))
+ else:
+ self.add(EmptyLine())
name = property(get_name, set_name)
value = property(get_value, set_value)
@@ -296,6 +309,7 @@
_defaults = None
_optionxformvalue = None
_optionxformsource = None
+ _compat_skip_empty_lines = set()
def __init__(self, lineobj, defaults = None,
optionxformvalue=None, optionxformsource=None):
self._lines = [lineobj]
@@ -306,6 +320,25 @@
_optionxform = _make_xform_property('_optionxform')
+ def _compat_get(self, key):
+ # identical to __getitem__ except that _compat_XXX
+ # is checked for backward-compatible handling
+ if key == '__name__':
+ return self._lines[-1].name
+ if self._optionxform: key = self._optionxform(key)
+ try:
+ value = self._options[key].value
+ del_empty = key in self._compat_skip_empty_lines
+ except KeyError:
+ if self._defaults and key in self._defaults._options:
+ value = self._defaults._options[key].value
+ del_empty = key in self._defaults._compat_skip_empty_lines
+ else:
+ raise
+ if del_empty:
+ value = re.sub('\n+', '\n', value)
+ return value
+
def __getitem__(self, key):
if key == '__name__':
return self._lines[-1].name
@@ -321,6 +354,8 @@
def __setitem__(self, key, value):
if self._optionxform: xkey = self._optionxform(key)
else: xkey = key
+ if xkey in self._compat_skip_empty_lines:
+ self._compat_skip_empty_lines.remove(xkey)
if xkey not in self._options:
# create a dummy object - value may have multiple lines
obj = LineContainer(OptionLine(key, ''))
@@ -332,6 +367,8 @@
def __delitem__(self, key):
if self._optionxform: key = self._optionxform(key)
+ if key in self._compat_skip_empty_lines:
+ self._compat_skip_empty_lines.remove(key)
for l in self._lines:
remaining = []
for o in l.contents:
@@ -367,7 +404,7 @@
def make_comment(line):
- return CommentLine(line.rstrip())
+ return CommentLine(line.rstrip('\n'))
def readline_iterator(f):
@@ -441,6 +478,7 @@
def __iter__(self):
d = set()
+ d.add(DEFAULTSECT)
for x in self._data.contents:
if isinstance(x, LineContainer):
if x.name not in d:
@@ -490,6 +528,7 @@
cur_section_name = None
cur_option_name = None
pending_lines = []
+ pending_empty_lines = False
try:
fname = fp.name
except AttributeError:
@@ -523,8 +562,12 @@
if isinstance(lineobj, ContinuationLine):
if cur_option:
- cur_option.extend(pending_lines)
- pending_lines = []
+ if pending_lines:
+ cur_option.extend(pending_lines)
+ pending_lines = []
+ if pending_empty_lines:
+ optobj._compat_skip_empty_lines.add(cur_option_name)
+ pending_empty_lines = False
cur_option.add(lineobj)
else:
# illegal continuation line - convert to comment
@@ -534,8 +577,10 @@
lineobj = make_comment(line)
if isinstance(lineobj, OptionLine):
- cur_section.extend(pending_lines)
- pending_lines = []
+ if pending_lines:
+ cur_section.extend(pending_lines)
+ pending_lines = []
+ pending_empty_lines = False
cur_option = LineContainer(lineobj)
cur_section.add(cur_option)
if self._optionxform:
@@ -551,6 +596,7 @@
if isinstance(lineobj, SectionLine):
self._data.extend(pending_lines)
pending_lines = []
+ pending_empty_lines = False
cur_section = LineContainer(lineobj)
self._data.add(cur_section)
cur_option = None
@@ -572,6 +618,8 @@
if isinstance(lineobj, (CommentLine, EmptyLine)):
pending_lines.append(lineobj)
+ if isinstance(lineobj, EmptyLine):
+ pending_empty_lines = True
self._data.extend(pending_lines)
if line and line[-1]=='\n':
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/python-iniparse.spec new/iniparse-0.3.1/python-iniparse.spec
--- old/iniparse-0.2.4/python-iniparse.spec 2008-12-06 23:11:49.000000000 +0100
+++ new/iniparse-0.3.1/python-iniparse.spec 2009-03-02 16:12:15.000000000 +0100
@@ -1,7 +1,7 @@
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Name: python-iniparse
-Version: 0.2.4
+Version: 0.3.1
Release: 1%{?dist}
Summary: Python Module for Accessing and Modifying Configuration Data in INI files
Group: Development/Libraries
@@ -48,6 +48,10 @@
%changelog
+* Mon Mar 2 2009 Paramjit Oberoi - 0.3.1-1
+- Release 0.3.1
+* Fri Feb 27 2009 Paramjit Oberoi - 0.3.0-1
+- Release 0.3.0
* Tue Dec 6 2008 Paramjit Oberoi - 0.2.4-1
- Release 0.2.4
- added egg-info file to %%files
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/setup.py new/iniparse-0.3.1/setup.py
--- old/iniparse-0.2.4/setup.py 2008-12-06 22:19:04.000000000 +0100
+++ new/iniparse-0.3.1/setup.py 2009-03-02 16:11:22.000000000 +0100
@@ -2,7 +2,7 @@
from distutils.core import setup
-VERSION = '0.2.4'
+VERSION = '0.3.1'
setup(name ='iniparse',
version = VERSION,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/tests/__init__.py new/iniparse-0.3.1/tests/__init__.py
--- old/iniparse-0.2.4/tests/__init__.py 2008-12-06 23:04:02.000000000 +0100
+++ new/iniparse-0.3.1/tests/__init__.py 2009-03-01 17:20:28.000000000 +0100
@@ -2,6 +2,7 @@
import test_ini
import test_misc
+import test_fuzz
import test_compat
import test_unicode
from iniparse import config
@@ -14,6 +15,7 @@
doctest.DocTestSuite(ini),
test_ini.suite(),
test_misc.suite(),
+ test_fuzz.suite(),
test_compat.suite(),
test_unicode.suite(),
])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/tests/test_fuzz.py new/iniparse-0.3.1/tests/test_fuzz.py
--- old/iniparse-0.2.4/tests/test_fuzz.py 1970-01-01 01:00:00.000000000 +0100
+++ new/iniparse-0.3.1/tests/test_fuzz.py 2009-03-01 23:25:18.000000000 +0100
@@ -0,0 +1,111 @@
+import re
+import random
+import unittest
+import ConfigParser
+from textwrap import dedent
+from StringIO import StringIO
+from iniparse import compat, ini
+
+# TODO:
+# tabs
+# substitutions
+
+def random_string(maxlen=200):
+ length = random.randint(0, maxlen)
+ s = []
+ for i in range(length):
+ s.append(chr(random.randint(32, 126)))
+
+ return ''.join(s)
+
+def random_space(maxlen=10):
+ length = random.randint(0, maxlen)
+ return ' '*length
+
+def random_ini_file():
+ num_lines = random.randint(0, 100)
+ lines = []
+ for i in range(num_lines):
+ x = random.random()
+ if x < 0.1:
+ # empty line
+ lines.append(random_space())
+ elif x < 0.3:
+ # comment
+ sep = random.choice(['#', ';'])
+ lines.append(sep + random_string())
+ elif x < 0.5:
+ # section
+ if random.random() < 0.1:
+ name = 'DEFAULT'
+ else:
+ name = random_string()
+ name = re.sub(']', '' , name)
+ l = '[' + name + ']'
+ if random.randint(0,1):
+ l += random_space()
+ if random.randint(0,1):
+ sep = random.choice(['#', ';'])
+ l += sep + random_string()
+ lines.append(l)
+ elif x < 0.7:
+ # option
+ name = random_string()
+ name = re.sub(':|=| |\[', '', name)
+ sep = random.choice([':', '='])
+ l = name + random_space() + sep + random_space() + random_string()
+ if random.randint(0,1):
+ l += ' ' + random_space() + ';' +random_string()
+ lines.append(l)
+ elif x < 0.9:
+ # continuation
+ lines.append(' ' + random_space() + random_string())
+ else:
+ # junk
+ lines.append(random_string())
+
+ return '\n'.join(lines)
+
+class test_fuzz(unittest.TestCase):
+ def test_fuzz(self):
+ random.seed(42)
+ for i in range(100):
+ # parse random file with errors disabled
+ s = random_ini_file()
+ c = ini.INIConfig(parse_exc=False)
+ c._readfp(StringIO(s))
+ # check that file is preserved, except for
+ # commenting out erroneous lines
+ l1 = s.split('\n')
+ l2 = str(c).split('\n')
+ self.assertEqual(len(l1), len(l2))
+ good_lines = []
+ for i in range(len(l1)):
+ try:
+ self.assertEqual(l1[i], l2[i])
+ good_lines.append(l1[i])
+ except AssertionError:
+ self.assertEqual('#'+l1[i], l2[i])
+ # parse the good subset of the file
+ # using ConfigParser
+ s = '\n'.join(good_lines)
+ cc = compat.RawConfigParser()
+ cc.readfp(StringIO(s))
+ cc_py = ConfigParser.RawConfigParser()
+ cc_py.readfp(StringIO(s))
+ # compare the two configparsers
+ self.assertEqualSorted(cc_py.sections(), cc.sections())
+ self.assertEqualSorted(cc_py.defaults().items(), cc.defaults().items())
+ for sec in cc_py.sections():
+ self.assertEqualSorted(cc_py.items(sec), cc.items(sec))
+
+ def assertEqualSorted(self, l1, l2):
+ l1.sort()
+ l2.sort()
+ self.assertEqual(l1, l2)
+
+class suite(unittest.TestSuite):
+ def __init__(self):
+ unittest.TestSuite.__init__(self, [
+ unittest.makeSuite(test_fuzz, 'test'),
+ ])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/tests/test_ini.py new/iniparse-0.3.1/tests/test_ini.py
--- old/iniparse-0.2.4/tests/test_ini.py 2008-12-06 22:47:57.000000000 +0100
+++ new/iniparse-0.3.1/tests/test_ini.py 2009-03-01 17:17:10.000000000 +0100
@@ -177,6 +177,8 @@
I'm = desperate ; really!
[section2]
+# comment and empty line before the first option
+
just = what?
just = kidding
@@ -233,6 +235,8 @@
I'm = desperate ; really!
[section2]
+# comment and empty line before the first option
+
just = what?
just = kidding
@@ -311,6 +315,70 @@
ip = ini.INIConfig(StringIO(org), parse_exc=False)
self.assertEqual(str(ip), mod)
+ # test multi-line values
+ s2 = (
+"""
+[section]
+option =
+ foo
+ bar
+
+ baz
+ yam
+"""
+)
+
+ s3 = (
+"""
+[section]
+option =
+ foo
+ bar
+ mum
+
+ baz
+ yam
+"""
+)
+
+ def test_option_continuation(self):
+ ip = ini.INIConfig(StringIO(self.s2))
+ self.assertEqual(str(ip), self.s2)
+ value = ip.section.option.split('\n')
+ value.insert(3, 'mum')
+ ip.section.option = '\n'.join(value)
+ self.assertEqual(str(ip), self.s3)
+
+ s5 = (
+"""
+[section]
+option =
+ foo
+ bar
+"""
+)
+
+ s6 = (
+"""
+[section]
+option =
+
+
+ foo
+
+
+
+another = baz
+"""
+)
+
+ def test_option_continuation_single(self):
+ ip = ini.INIConfig(StringIO(self.s5))
+ self.assertEqual(str(ip), self.s5)
+ ip.section.option = '\n'.join(['', '', '', 'foo', '', '', ''])
+ ip.section.another = 'baz'
+ self.assertEqual(str(ip), self.s6)
+
class suite(unittest.TestSuite):
def __init__(self):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.2.4/tests/test_misc.py new/iniparse-0.3.1/tests/test_misc.py
--- old/iniparse-0.2.4/tests/test_misc.py 2008-12-06 11:21:16.000000000 +0100
+++ new/iniparse-0.3.1/tests/test_misc.py 2009-02-28 22:59:08.000000000 +0100
@@ -1,4 +1,7 @@
import unittest
+import pickle
+import ConfigParser
+from textwrap import dedent
from StringIO import StringIO
from iniparse import compat, ini
@@ -101,7 +104,7 @@
def test_read(self):
c = ini.INIConfig()
c._readfp(StringIO(self.s))
- self.assertEqual(c.sec.opt, '1\n2\n3')
+ self.assertEqual(c.sec.opt, '1\n2\n\n3')
def test_write(self):
c = ini.INIConfig()
@@ -133,6 +136,268 @@
def test_custom_dict_not_supported(self):
self.assertRaises(ValueError, compat.RawConfigParser, None, 'foo')
+class test_compat(unittest.TestCase):
+ """Miscellaneous compatibility tests."""
+
+ s = dedent("""\
+ [DEFAULT]
+ pi = 3.1415
+ three = 3
+ poet = e e
+
+ cummings
+ NH =
+ live free
+
+ or die
+
+ [sec]
+ opt = 6
+ three = 3.0
+ no-three = one
+ two
+
+ four
+ longopt = foo
+ bar
+
+ # empty line should not be part of value
+ baz
+
+ bat
+
+ """)
+
+ def do_test(self, c):
+ # default section is not acknowledged
+ self.assertEqual(c.sections(), ['sec'])
+ # options in the default section are merged with other sections
+ self.assertEqual(sorted(c.options('sec')),
+ ['longopt', 'nh', 'no-three', 'opt', 'pi', 'poet', 'three'])
+
+ # empty lines are stripped from multi-line values
+ self.assertEqual(c.get('sec', 'poet').split('\n'),
+ ['e e', 'cummings'])
+ self.assertEqual(c.get('DEFAULT', 'poet').split('\n'),
+ ['e e', 'cummings'])
+ self.assertEqual(c.get('sec', 'longopt').split('\n'),
+ ['foo', 'bar', 'baz', 'bat'])
+ self.assertEqual(c.get('sec', 'NH').split('\n'),
+ ['', 'live free', 'or die'])
+
+ # check that empy-line stripping happens on all access paths
+ # defaults()
+ self.assertEqual(c.defaults(), {
+ 'poet': 'e e\ncummings',
+ 'nh': '\nlive free\nor die',
+ 'pi': '3.1415',
+ 'three': '3',
+ })
+ # items()
+ l = c.items('sec')
+ l.sort()
+ self.assertEqual(l, [
+ ('longopt', 'foo\nbar\nbaz\nbat'),
+ ('nh', '\nlive free\nor die'),
+ ('no-three', 'one\ntwo\nfour'),
+ ('opt', '6'),
+ ('pi', '3.1415'),
+ ('poet', 'e e\ncummings'),
+ ('three', '3.0'),
+ ])
+
+ # empty lines are preserved on explicitly set values
+ c.set('sec', 'longopt', '\n'.join(['a', 'b', '', 'c', '', '', 'd']))
+ c.set('DEFAULT', 'NH', '\nlive free\n\nor die')
+ self.assertEqual(c.get('sec', 'longopt').split('\n'),
+ ['a', 'b', '', 'c', '', '', 'd'])
+ self.assertEqual(c.get('sec', 'NH').split('\n'),
+ ['', 'live free', '', 'or die'])
+ self.assertEqual(c.defaults(), {
+ 'poet': 'e e\ncummings',
+ 'nh': '\nlive free\n\nor die',
+ 'pi': '3.1415',
+ 'three': '3',
+ })
+ # items()
+ l = c.items('sec')
+ l.sort()
+ self.assertEqual(l, [
+ ('longopt', 'a\nb\n\nc\n\n\nd'),
+ ('nh', '\nlive free\n\nor die'),
+ ('no-three', 'one\ntwo\nfour'),
+ ('opt', '6'),
+ ('pi', '3.1415'),
+ ('poet', 'e e\ncummings'),
+ ('three', '3.0'),
+ ])
+
+ # empty line special magic goes away after remove_option()
+ self.assertEqual(c.get('sec', 'no-three').split('\n'),
+ ['one', 'two','four'])
+ c.remove_option('sec', 'no-three')
+ c.set('sec', 'no-three', 'q\n\nw')
+ self.assertEqual(c.get('sec', 'no-three'), 'q\n\nw')
+ c.remove_option('sec', 'no-three')
+
+ def do_configparser_test(self, cfg_class):
+ c = cfg_class()
+ c.readfp(StringIO(self.s))
+ self.do_test(c)
+ o = StringIO()
+ c.write(o)
+ self.assertEqual(o.getvalue().split('\n'), [
+ '[DEFAULT]',
+ 'poet = e e',
+ '\tcummings',
+ 'nh = ',
+ '\tlive free',
+ '\t',
+ '\tor die',
+ 'pi = 3.1415',
+ 'three = 3',
+ '',
+ '[sec]',
+ 'opt = 6',
+ 'longopt = a',
+ '\tb',
+ '\t',
+ '\tc',
+ '\t',
+ '\t',
+ '\td',
+ 'three = 3.0',
+ '',
+ ''])
+
+ def test_py_rawcfg(self):
+ self.do_configparser_test(ConfigParser.RawConfigParser)
+
+ def test_py_cfg(self):
+ self.do_configparser_test(ConfigParser.ConfigParser)
+
+ def test_py_safecfg(self):
+ self.do_configparser_test(ConfigParser.SafeConfigParser)
+
+ def do_compat_test(self, cfg_class):
+ c = cfg_class()
+ c.readfp(StringIO(self.s))
+ self.do_test(c)
+ o = StringIO()
+ c.write(o)
+ self.assertEqual(o.getvalue().split('\n'), [
+ '[DEFAULT]',
+ 'pi = 3.1415',
+ 'three = 3',
+ 'poet = e e',
+ '',
+ ' cummings',
+ 'NH =',
+ ' live free',
+ '',
+ ' or die',
+ '',
+ '[sec]',
+ 'opt = 6',
+ 'three = 3.0',
+ 'longopt = a',
+ ' b',
+ '',
+ ' c',
+ '',
+ '',
+ ' d',
+ '',
+ ''])
+
+ def test_py_rawcfg(self):
+ self.do_compat_test(compat.RawConfigParser)
+
+ def test_py_cfg(self):
+ self.do_compat_test(compat.ConfigParser)
+
+ def test_py_safecfg(self):
+ self.do_compat_test(compat.SafeConfigParser)
+
+class test_pickle(unittest.TestCase):
+ s = dedent("""\
+ [DEFAULT]
+ pi = 3.1415
+ three = 3
+ poet = e e
+
+ cummings
+ NH =
+ live free
+
+ or die
+
+ [sec]
+ opt = 6
+ three = 3.0
+ no-three = one
+ two
+
+ four
+
+ james = bond
+ """)
+
+ def do_compat_checks(self, c):
+ self.assertEqual(c.sections(), ['sec'])
+ self.assertEqual(sorted(c.options('sec')),
+ ['james', 'nh', 'no-three', 'opt', 'pi', 'poet', 'three'])
+ self.assertEqual(c.defaults(), {
+ 'poet': 'e e\ncummings',
+ 'nh': '\nlive free\nor die',
+ 'pi': '3.1415',
+ 'three': '3',
+ })
+ l = c.items('sec')
+ l.sort()
+ self.assertEqual(l, [
+ ('james', 'bond'),
+ ('nh', '\nlive free\nor die'),
+ ('no-three', 'one\ntwo\nfour'),
+ ('opt', '6'),
+ ('pi', '3.1415'),
+ ('poet', 'e e\ncummings'),
+ ('three', '3.0'),
+ ])
+ self.do_ini_checks(c.data)
+
+ def do_ini_checks(self, c):
+ self.assertEqual(list(c), ['sec'])
+ self.assertEqual(sorted(c['sec']), ['james', 'nh', 'no-three', 'opt', 'pi', 'poet', 'three'])
+ self.assertEqual(c._defaults['pi'], '3.1415')
+ self.assertEqual(c.sec.opt, '6')
+ self.assertEqual(c.sec.three, '3.0')
+ self.assertEqual(c.sec['no-three'], 'one\ntwo\n\nfour')
+ self.assertEqual(c.sec.james, 'bond')
+ self.assertEqual(c.sec.pi, '3.1415')
+ self.assertEqual(c.sec.poet, 'e e\n\ncummings')
+ self.assertEqual(c.sec.NH, '\nlive free\n\nor die')
+ self.assertEqual(str(c), self.s)
+
+ def test_compat(self):
+ for cfg_class in (compat.ConfigParser, compat.RawConfigParser, compat.SafeConfigParser):
+ c = cfg_class()
+ c.readfp(StringIO(self.s))
+ self.do_compat_checks(c)
+ p = pickle.dumps(c)
+ c = None
+ c2 = pickle.loads(p)
+ self.do_compat_checks(c2)
+
+ def test_ini(self):
+ c = ini.INIConfig()
+ c._readfp(StringIO(self.s))
+ self.do_ini_checks(c)
+ p = pickle.dumps(c)
+ c = None
+ c2 = pickle.loads(p)
+ self.do_ini_checks(c2)
+
class suite(unittest.TestSuite):
def __init__(self):
unittest.TestSuite.__init__(self, [
@@ -141,4 +406,6 @@
unittest.makeSuite(test_multiline_with_comments, 'test'),
unittest.makeSuite(test_empty_file, 'test'),
unittest.makeSuite(test_custom_dict, 'test'),
+ unittest.makeSuite(test_compat, 'test'),
+ unittest.makeSuite(test_pickle, 'test'),
])
\ No newline at end of file
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
--
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org