[Pkg-python-debian-commits] trunk r95: Fix _multivalued.dump() (#457929).
Adeodato Simó
dato at net.com.org.es
Fri Dec 28 17:43:40 UTC 2007
------------------------------------------------------------
revno: 95
committer: Adeodato Simó <dato at net.com.org.es>
branch nick: pd.deb822_multivalued
timestamp: Fri 2007-12-28 18:43:40 +0100
message:
Fix _multivalued.dump() (#457929).
Two bugs needed fixing (and it was difficult adding a test for the first
one without fixing the second one as well):
* When checking if a key was in _multivalued_fields, the plain key as
returned by self.keys() was used, but .keys() does not return case
insensitive strings (why??), so fields were never regarded as
multivalue. Add test_bug457929_multivalued_dump_works to check for
this.
* For multi-line but not multi-valued fields, an extra trailing space
was being printed. Copy code to handle this from Deb822.dump(), and
extend test_multiline_trailing_whitespace_after_colon to exercise
both Deb822 and _multivalued via deb822.Changes (changing the parsed
file from a dsc to a changes file, which contains multi-line not
multi-valued fields).
modified:
debian/changelog
debian_bundle/deb822.py
tests/test_deb822.py
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog 2007-12-28 10:56:45 +0000
+++ b/debian/changelog 2007-12-28 17:43:40 +0000
@@ -22,6 +22,8 @@
accomodate the above change, make it cope with stanzas without a
maintainer field as well. (Closes: #457855)
+ * Fix dump() method of deb822._multivalued. (Closes: #457929)
+
* Small improvements to the exception handling in the grep-maintainer
example.
=== modified file 'debian_bundle/deb822.py'
--- a/debian_bundle/deb822.py 2007-12-27 17:12:42 +0000
+++ b/debian_bundle/deb822.py 2007-12-28 17:43:40 +0000
@@ -263,6 +263,7 @@
if not value or value[0] == '\n':
# Avoid trailing whitespace after "Field:" if it's on its own
# line or the value is empty
+ # XXX Uh, really print value if value == '\n'?
fd.write('%s:%s\n' % (key, value))
else:
fd.write('%s: %s\n' % (key, value))
@@ -430,18 +431,23 @@
else:
return_string = False
for key in self.keys():
- if key not in self._multivalued_fields:
- # normal behavior
- fd.write(key + ": " + self[key] + "\n")
+ keyl = key.lower()
+ if keyl not in self._multivalued_fields:
+ value = self[key]
+ if not value or value[0] == '\n':
+ # XXX Uh, really print value if value == '\n'?
+ fd.write('%s:%s\n' % (key, value))
+ else:
+ fd.write('%s: %s\n' % (key, value))
else:
fd.write(key + ":")
if isinstance(self[key], dict): # single-line
array = [ self[key] ]
else: # multi-line
- fd.write(" \n")
+ fd.write("\n")
array = self[key]
- order = self._multivalued_fields[key]
+ order = self._multivalued_fields[keyl]
for item in array:
fd.write(" " + " ".join([item[x] for x in order]))
fd.write("\n")
=== modified file 'tests/test_deb822.py'
--- a/tests/test_deb822.py 2007-11-29 17:03:50 +0000
+++ b/tests/test_deb822.py 2007-12-28 17:43:40 +0000
@@ -145,6 +145,34 @@
]
+CHANGES_FILE = '''\
+Format: 1.7
+Date: Fri, 28 Dec 2007 17:08:48 +0100
+Source: bzr-gtk
+Binary: bzr-gtk
+Architecture: source all
+Version: 0.93.0-2
+Distribution: unstable
+Urgency: low
+Maintainer: Debian Bazaar Maintainers <pkg-bazaar-maint at lists.alioth.debian.org>
+Changed-By: Chris Lamb <chris at chris-lamb.co.uk>
+Description:
+ bzr-gtk - provides graphical interfaces to Bazaar (bzr) version control
+Closes: 440354 456438
+Changes:
+ bzr-gtk (0.93.0-2) unstable; urgency=low
+ .
+ [ Chris Lamb ]
+ * Add patch for unclosed progress window. (Closes: #440354)
+ Patch by Jean-François Fortin Tam <jeff at ecchi.ca>
+ * Fix broken icons in .desktop files (Closes: #456438).
+Files:
+ 0fd797f4138a9d4fdeb8c30597d46bc9 1003 python optional bzr-gtk_0.93.0-2.dsc
+ d9523676ae75c4ced299689456f252f4 3860 python optional bzr-gtk_0.93.0-2.diff.gz
+ 8960459940314b21019dedd5519b47a5 168544 python optional bzr-gtk_0.93.0-2_all.deb
+'''
+
+
class TestDeb822Dict(unittest.TestCase):
def make_dict(self):
d = deb822.Deb822Dict()
@@ -365,29 +393,15 @@
should be a space after the colon, as with non-multiline fields.
"""
- dsc_string = """Format: 1.0
-Source: python-debian
-Binary: python-debian
-Architecture: all
-Version: 0.1.4
-Maintainer: Debian python-debian Maintainers <pkg-python-debian-maint at lists.alioth.debian.org>
-Uploaders: Adeodato Simó <dato at net.com.org.es>, Enrico Zini <enrico at debian.org>, James Westby <jw+debian at jameswestby.net>, Reinhard Tartler <siretart at tauware.de>, Stefano Zacchiroli <zack at debian.org>, John Wright <john at movingsucks.org>
-Standards-Version: 3.7.2
-Build-Depends: debhelper (>= 5.0.37.2), python, m4
-Build-Depends-Indep: python-support (>= 0.3)
-Files:
- 065aa27943a4fc9e7020f324fed57b65 68575 python-debian_0.1.4.tar.gz
-Vcs-Bzr: http://bzr.debian.org/pkg-python-debian/trunk/
-"""
- parsed_dsc = deb822.Deb822(dsc_string.splitlines())
-
# bad_re: match a line that starts with a "Field:", and ends in
# whitespace
bad_re = re.compile(r"^\S+:\s+$")
- for line in parsed_dsc.dump().splitlines():
- self.assert_(bad_re.match(line) is None,
- "There should not be trailing whitespace after the "
- "colon in a multiline field starting with a newline")
+ for cls in deb822.Deb822, deb822.Changes:
+ parsed = cls(CHANGES_FILE.splitlines())
+ for line in parsed.dump().splitlines():
+ self.assert_(bad_re.match(line) is None,
+ "There should not be trailing whitespace after the "
+ "colon in a multiline field starting with a newline")
control_paragraph = """Package: python-debian
@@ -445,5 +459,10 @@
expected_dump = "Foo: bar\nBar: baz\n"
self.assertEqual(d_copy.dump(), expected_dump)
+ def test_bug457929_multivalued_dump_works(self):
+ """dump() was not working in multivalued classes, see #457929."""
+ changesobj = deb822.Changes(CHANGES_FILE.splitlines())
+ self.assertEqual(CHANGES_FILE, changesobj.dump())
+
if __name__ == '__main__':
unittest.main()
More information about the pkg-python-debian-commits
mailing list