[python-debian/master 3/3] test_deb822.py: Add test cases for unicode handling

John Wright john.wright at hp.com
Fri Mar 5 02:13:38 UTC 2010


This commit also adds a paragraph to test_Sources, containing the
entry for python-debian, since it has a non-ascii character in Dato's
name.  It also adds a copy of that file encoded in iso8859-1.
---
 tests/test_Sources           |   23 +++++++++++
 tests/test_Sources.iso8859-1 |   87 ++++++++++++++++++++++++++++++++++++++++++
 tests/test_deb822.py         |   62 ++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 tests/test_Sources.iso8859-1

diff --git a/tests/test_Sources b/tests/test_Sources
index 254f9fb..f5d53a9 100644
--- a/tests/test_Sources
+++ b/tests/test_Sources
@@ -62,3 +62,26 @@ Checksums-Sha1:
 Checksums-Sha256: 
  9bdfe720407f5c134842eeaa8cfc9932be33150a5a3c041426216a90cce9e32d 13627 debian-archive-keyring_2009.01.31.tar.gz
 
+Package: python-debian
+Binary: python-debian
+Version: 0.1.14
+Priority: optional
+Section: devel
+Maintainer: Debian python-debian Maintainers <pkg-python-debian-maint at lists.alioth.debian.org>
+Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools
+Build-Depends-Indep: python-support (>= 0.3)
+Architecture: all
+Standards-Version: 3.8.1
+Format: 1.0
+Directory: pool/main/p/python-debian
+Files:
+ b153648eaf2fbf2b20e07986f3f8fc37 1224 python-debian_0.1.14.dsc
+ 9d05b7813dbbdb4fd8d41f4a2825de57 176558 python-debian_0.1.14.tar.gz
+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 <jsw at debian.org>
+Vcs-Browser: http://git.debian.org/?p=pkg-python-debian/python-debian.git
+Vcs-Git: git://git.debian.org/git/pkg-python-debian/python-debian.git
+Checksums-Sha1: 
+ 00521e603691403da83a517a8ff10cb4e0e05bcc 176558 python-debian_0.1.14.tar.gz
+Checksums-Sha256: 
+ 40be3da49191a26b3301f18d6824c2a3e7ef4ac52a99ed4484d9176ecc7685e8 176558 python-debian_0.1.14.tar.gz
+
diff --git a/tests/test_Sources.iso8859-1 b/tests/test_Sources.iso8859-1
new file mode 100644
index 0000000..253f9d6
--- /dev/null
+++ b/tests/test_Sources.iso8859-1
@@ -0,0 +1,87 @@
+Package: apache2-mpm-itk
+Binary: apache2-mpm-itk
+Version: 2.2.6-01-3
+Priority: extra
+Section: net
+Maintainer: Steinar H. Gunderson <sesse at debian.org>
+Build-Depends: apache2-src (>= 2.2.9), libaprutil1-dev, libcap-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], autoconf, debhelper (>> 5.0.0)
+Architecture: any
+Standards-Version: 3.7.3
+Format: 1.0
+Directory: pool/main/a/apache2-mpm-itk
+Files:
+ 24d02f8ecf0f37164cfcc2fb23bf1013 1135 apache2-mpm-itk_2.2.6-01-3.dsc
+ f8041c58e43dae9814f903919d222c73 33269 apache2-mpm-itk_2.2.6-01.orig.tar.gz
+ 71dcfe1d2349b376c062c964a87cd213 12824 apache2-mpm-itk_2.2.6-01-3.diff.gz
+Checksums-Sha1: 
+ c9ab75c5b2360d1f1ebee513cbf62963023196b9 33269 apache2-mpm-itk_2.2.6-01.orig.tar.gz
+ 12b996db5c4a628388c1402e13bd30aa0db3cec4 12824 apache2-mpm-itk_2.2.6-01-3.diff.gz
+Checksums-Sha256: 
+ e789b7754072fa6a629c55b931411806432102be7a379f750ac6d328df7790c3 33269 apache2-mpm-itk_2.2.6-01.orig.tar.gz
+ db631e44c83f7086b15e701bafcc7e6e1481f957d47b8075092ba80d863f83bb 12824 apache2-mpm-itk_2.2.6-01-3.diff.gz
+
+Package: binutils
+Binary: binutils, binutils-dev, binutils-multiarch, binutils-hppa64, binutils-spu, binutils-doc, binutils-source
+Version: 2.18.1~cvs20080103-6
+Priority: optional
+Section: devel
+Maintainer: James Troup <james at nocrew.org>
+Build-Depends: dpkg-dev (>= 1.13.9), autoconf (>= 2.13), bash, bison, flex, gettext, texinfo, expect-tcl8.3 (>= 5.32.2) [hppa], dejagnu (>= 1.4.2-1.1), dpatch, file, bzip2, lsb-release
+Architecture: any
+Standards-Version: 3.7.3
+Format: 1.0
+Directory: pool/main/b/binutils
+Files:
+ 04c6dfcfa9d7e2057fea9561610b009a 1331 binutils_2.18.1~cvs20080103-6.dsc
+ 23b4c0bdda7c9974489bc9d3aaf7a754 19746003 binutils_2.18.1~cvs20080103.orig.tar.gz
+ b57f7ed234c299f56a6545c4251e509e 64334 binutils_2.18.1~cvs20080103-6.diff.gz
+Uploaders: Matthias Klose <doko at debian.org>
+Checksums-Sha1: 
+ ec4182b10960eb6ce927af37326feaa114a232cc 19746003 binutils_2.18.1~cvs20080103.orig.tar.gz
+ 5589356c2c4cc9a94aeb9ba658c08a4ec3fae11b 64334 binutils_2.18.1~cvs20080103-6.diff.gz
+Checksums-Sha256: 
+ bf2e12578caf3b79be6182bb109b3a0215d8a3b89ae2049773f56f286eeb8ad3 19746003 binutils_2.18.1~cvs20080103.orig.tar.gz
+ 44e346757ce336f6a16879264b6cc4ff4e2b4da517e4b5db6cc7f1d254f302dd 64334 binutils_2.18.1~cvs20080103-6.diff.gz
+
+Package: debian-archive-keyring
+Binary: debian-archive-keyring, debian-archive-keyring-udeb
+Version: 2009.01.31
+Priority: important
+Section: misc
+Maintainer: Debian Release Team <packages at release.debian.org>
+Architecture: all
+Standards-Version: 3.7.3
+Format: 1.0
+Directory: pool/main/d/debian-archive-keyring
+Files:
+ 2675031b2286ca8dfc085e2a9c9d38ed 838 debian-archive-keyring_2009.01.31.dsc
+ 5365c07ddcf639544933552e31a571ee 13627 debian-archive-keyring_2009.01.31.tar.gz
+Uploaders: Luk Claes <luk at debian.org>
+Checksums-Sha1: 
+ dd987a5ee85d8c4fc3e115f60a6a021e78c626dd 13627 debian-archive-keyring_2009.01.31.tar.gz
+Checksums-Sha256: 
+ 9bdfe720407f5c134842eeaa8cfc9932be33150a5a3c041426216a90cce9e32d 13627 debian-archive-keyring_2009.01.31.tar.gz
+
+Package: python-debian
+Binary: python-debian
+Version: 0.1.14
+Priority: optional
+Section: devel
+Maintainer: Debian python-debian Maintainers <pkg-python-debian-maint at lists.alioth.debian.org>
+Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools
+Build-Depends-Indep: python-support (>= 0.3)
+Architecture: all
+Standards-Version: 3.8.1
+Format: 1.0
+Directory: pool/main/p/python-debian
+Files:
+ b153648eaf2fbf2b20e07986f3f8fc37 1224 python-debian_0.1.14.dsc
+ 9d05b7813dbbdb4fd8d41f4a2825de57 176558 python-debian_0.1.14.tar.gz
+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 <jsw at debian.org>
+Vcs-Browser: http://git.debian.org/?p=pkg-python-debian/python-debian.git
+Vcs-Git: git://git.debian.org/git/pkg-python-debian/python-debian.git
+Checksums-Sha1: 
+ 00521e603691403da83a517a8ff10cb4e0e05bcc 176558 python-debian_0.1.14.tar.gz
+Checksums-Sha256: 
+ 40be3da49191a26b3301f18d6824c2a3e7ef4ac52a99ed4484d9176ecc7685e8 176558 python-debian_0.1.14.tar.gz
+
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index 4b10838..f9a1f55 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -641,6 +641,68 @@ Description: python modules to work with Debian-related data formats
             d3['Some-Test-Key'] = 'some value'
         self.assertEqual(d3.dump(), "Some-Test-Key: some value\n")
 
+    def test_unicode_values(self):
+        """Deb822 objects should contain only unicode values
+
+        (Technically, they are allowed to contain any type of object, but when
+        parsed from files, and when only string-type objects are added, the
+        resulting object should have only unicode values.)
+        """
+
+        objects = []
+        objects.append(deb822.Deb822(UNPARSED_PACKAGE))
+        objects.append(deb822.Deb822(CHANGES_FILE))
+        objects.extend(deb822.Deb822.iter_paragraphs(file('test_Packages')))
+        objects.extend(deb822.Packages.iter_paragraphs(file('test_Packages')))
+        objects.extend(deb822.Deb822.iter_paragraphs(file('test_Sources')))
+        objects.extend(deb822.Deb822.iter_paragraphs(
+                         file('test_Sources.iso8859-1'), encoding="iso8859-1"))
+        for d in objects:
+            for value in d.values():
+                self.assert_(isinstance(value, unicode))
+
+        # The same should be true for Sources and Changes except for their
+        # _multivalued fields
+        multi = []
+        multi.append(deb822.Changes(CHANGES_FILE))
+        multi.append(deb822.Changes(SIGNED_CHECKSUM_CHANGES_FILE
+                                    % CHECKSUM_CHANGES_FILE))
+        multi.extend(deb822.Sources.iter_paragraphs(file('test_Sources')))
+        for d in multi:
+            for key, value in d.items():
+                if key.lower() not in d.__class__._multivalued_fields:
+                    self.assert_(isinstance(value, unicode))
+
+    def test_encoding_integrity(self):
+        utf8 = list(deb822.Deb822.iter_paragraphs(file('test_Sources')))
+        latin1 = list(deb822.Deb822.iter_paragraphs(
+                                                file('test_Sources.iso8859-1'),
+                                                encoding='iso8859-1'))
+
+        # dump() with no fd returns a unicode object - both should be identical
+        self.assertEqual(len(utf8), len(latin1))
+        for i in range(len(utf8)):
+            self.assertEqual(utf8[i].dump(), latin1[i].dump())
+
+        # XXX: The way multiline fields parsing works, we can't guarantee
+        # that trailing whitespace is reproduced.
+        utf8_contents = "\n".join([line.rstrip() for line in
+                                   file('test_Sources')] + [''])
+        latin1_contents = "\n".join([line.rstrip() for line in
+                                     file('test_Sources.iso8859-1')] + [''])
+
+        utf8_to_latin1 = StringIO()
+        for d in utf8:
+            d.dump(fd=utf8_to_latin1, encoding='iso8859-1')
+            utf8_to_latin1.write("\n")
+
+        latin1_to_utf8 = StringIO()
+        for d in latin1:
+            d.dump(fd=latin1_to_utf8, encoding='utf-8')
+            latin1_to_utf8.write("\n")
+
+        self.assertEqual(utf8_contents, latin1_to_utf8.getvalue())
+        self.assertEqual(latin1_contents, utf8_to_latin1.getvalue())
 
 class TestPkgRelations(unittest.TestCase):
 
-- 
1.6.3.3




More information about the pkg-python-debian-commits mailing list