[Python-modules-commits] [python-djvulibre] 01/14: Import python-djvulibre_0.7.1.orig.tar.xz

Daniel Stender danstender-guest at moszumanska.debian.org
Mon Mar 21 15:43:13 UTC 2016


This is an automated email from the git hooks/post-receive script.

danstender-guest pushed a commit to branch master
in repository python-djvulibre.

commit 30750487564fe434c7bf02fa0e2c2bc50732e8ac
Author: Daniel Stender <stender at debian.org>
Date:   Fri Mar 18 20:07:31 2016 +0100

    Import python-djvulibre_0.7.1.orig.tar.xz
---
 MANIFEST.in                                        |   2 +-
 PKG-INFO                                           |   8 +-
 djvu/const.py                                      |   2 +-
 djvu/decode.pyx                                    |  37 +++--
 doc/api/conf.py                                    |   2 +-
 doc/api/event-model.rst                            |   2 +-
 doc/api/expressions.rst                            |   4 +-
 doc/api/messages.rst                               |   6 +-
 doc/api/text-zones.rst                             |   2 +-
 doc/changelog                                      |  10 ++
 examples/djvu-crop-text                            |   1 -
 examples/djvu-dump-text                            |   2 +-
 private/{build-and-test => apt-install-build-reqs} |  43 +++--
 private/build-and-test                             |  11 +-
 private/mingw32-setup-env                          |   4 +-
 python_djvulibre.egg-info/PKG-INFO                 |   8 +-
 python_djvulibre.egg-info/SOURCES.txt              |   1 +
 setup.py                                           |  24 ++-
 tests/test_decode.py                               |  56 +++----
 tests/tools.py                                     | 183 +++++++++++----------
 20 files changed, 223 insertions(+), 185 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index b59516c..e7169e8 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -10,6 +10,6 @@ include examples/*
 
 recursive-include djvu *.py *.pxi *.pxd *.pyx
 
-recursive-include tests *.py Makefile *.jpeg *.tex *.djvu
+recursive-include tests *.py Makefile *.tex *.djvu
 
 include private/*
diff --git a/PKG-INFO b/PKG-INFO
index 123cb9a..3052e9d 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,14 +1,14 @@
 Metadata-Version: 1.1
 Name: python-djvulibre
-Version: 0.7
+Version: 0.7.1
 Summary: Python support for the DjVu image format
 Home-page: http://jwilk.net/software/python-djvulibre
 Author: Jakub Wilk
 Author-email: jwilk at jwilk.net
 License: GNU GPL 2
-Description: *python-djvulibre* is a set of `Python <https://www.python.org>`_ bindings for
-        the `DjVuLibre <http://djvu.sf.net/>`_ library, an open source implementation
-        of `DjVu <http://djvu.org/>`_.
+Description: *python-djvulibre* is a set of Python bindings for
+        the `DjVuLibre <http://djvu.sourceforge.net/>`_ library,
+        an open source implementation of `DjVu <http://djvu.org/>`_.
 Platform: all
 Classifier: Development Status :: 4 - Beta
 Classifier: Intended Audience :: Developers
diff --git a/djvu/const.py b/djvu/const.py
index 24cea2f..1a78dad 100644
--- a/djvu/const.py
+++ b/djvu/const.py
@@ -57,7 +57,7 @@ Producer
 Subject
 Title
 Trapped'''.split())
-# Retrived from the PDF specification
+# Retrieved from the PDF specification
 
 METADATA_KEYS = METADATA_BIBTEX_KEYS | METADATA_PDFINFO_KEYS
 
diff --git a/djvu/decode.pyx b/djvu/decode.pyx
index b34b506..a2c85e0 100644
--- a/djvu/decode.pyx
+++ b/djvu/decode.pyx
@@ -684,7 +684,7 @@ cdef class DocumentFiles(DocumentExtension):
                 raise KeyError(key)
             if self._page_map is None:
                 self._page_map = {}
-                for i from 0 <= i < len(self):
+                for i in range(len(self)):
                     file = File(self._document, i, sentinel = the_sentinel)
                     n_page = file.n_page
                     if n_page is not None:
@@ -897,7 +897,7 @@ cdef object pages_to_opt(object pages, int sort_uniq):
         pages = sorted(frozenset(pages))
     else:
         pages = list(pages)
-    for i from 0 <= i < len(pages):
+    for i in range(len(pages)):
         if not is_int(pages[i]):
             raise TypeError('page numbers must be integers')
         if pages[i] < 0:
@@ -1178,7 +1178,7 @@ cdef class Document:
             RENDER_FOREGROUND
                 render only the foreground layer
             RENDER_BACKGROUND
-                redner only the background layer
+                render only the background layer
         zoom
             Specifies a zoom factor. The default zoom factor scales the image to
             fit the page.
@@ -1314,22 +1314,23 @@ cdef class Document:
         cdef const char **optv
         cdef int optc
         cdef size_t buffer_size
-        optc = 0
         buffer_size = len(options) * sizeof (char*)
         optv = <const char**> py_malloc(buffer_size)
         if optv == NULL:
             raise MemoryError('Unable to allocate {0} bytes for print options'.format(buffer_size))
         try:
-            for optc from 0 <= optc < len(options):
+            for optc in range(len(options)):
                 option = options[optc]
                 if is_unicode(option):
                     options[optc] = option = encode_utf8(option)
                 optv[optc] = option
-            assert optc == len(options)
             with nogil: acquire_lock(loft_lock, WAIT_LOCK)
             try:
                 job = SaveJob(sentinel = the_sentinel)
-                job.__init(self._context, ddjvu_document_print(self.ddjvu_document, output, optc, optv))
+                job.__init(
+                    self._context,
+                    ddjvu_document_print(self.ddjvu_document, output, len(options), optv)
+                )
                 job._file = file_wrapper
             finally:
                 release_lock(loft_lock)
@@ -1528,7 +1529,7 @@ cdef class Context:
         - The URI is used as a key for the cache of decoded pages.
         - The URI is used to document NewStreamMessage messages.
 
-        Setting argument cache to a true vaule indicates that decoded pages
+        Setting argument cache to a true value indicates that decoded pages
         should be cached when possible.
 
         It is important to understand that the URI is not used to access the
@@ -1833,9 +1834,9 @@ cdef class PixelFormatPalette(PixelFormat):
 
     def __cinit__(self, palette, unsigned int bpp = 8):
         cdef int i, j, k, n
-        for i from 0 <= i < 6:
-            for j from 0 <= j < 6:
-                for k from 0 <= k < 6:
+        for i in range(6):
+            for j in range(6):
+                for k in range(6):
                     n = palette[(i, j, k)]
                     if not 0 <= n < 0x100:
                         raise ValueError('palette entries must be in range(0, 0x100)')
@@ -1846,12 +1847,12 @@ cdef class PixelFormatPalette(PixelFormat):
         self.ddjvu_format = ddjvu_format_create(DDJVU_FORMAT_PALETTE8, 216, self._palette)
 
     def __repr__(self):
-        cdef int i
+        cdef int i, j, k
         io = StringIO()
         io.write(get_type_name(PixelFormatPalette) + '({')
-        for i from 0 <= i < 6:
-            for j from 0 <= j < 6:
-                for k from 0 <= k < 6:
+        for i in range(6):
+            for j in range(6):
+                for k in range(6):
                     io.write('({i}, {j}, {k}): 0x{v:02x}'.format(i=i, j=j, k=k, v=self._palette[i * 6 * 6 + j * 6 + k]))
                     if not (i == j == k == 5):
                         io.write(', ')
@@ -2648,7 +2649,7 @@ cdef class NewStreamMessage(Message):
         It indicates that the decoder needs to access the data in the main DjVu
         file.
 
-        Further NewStreamMessage messages messages are generated to access the
+        Further NewStreamMessage messages are generated to access the
         auxiliary files of indirect or indexed DjVu documents. .name then
         provides the base name of the auxiliary file.
         '''
@@ -2657,9 +2658,9 @@ cdef class NewStreamMessage(Message):
 
     property uri:
         '''
-        Return the requrested URI.
+        Return the requested URI.
 
-        URI is is set according to the uri argument provided to function
+        URI is set according to the uri argument provided to function
         Context.new_document(). The first NewMessageStream message always
         contain the URI passed to Context.new_document(). Subsequent
         NewMessageStream messages contain the URI of the auxiliary files for
diff --git a/doc/api/conf.py b/doc/api/conf.py
index f175a36..34519c4 100644
--- a/doc/api/conf.py
+++ b/doc/api/conf.py
@@ -60,7 +60,7 @@ rst_epilog = '''
 .. _djvused: http://djvu.sourceforge.net/doc/man/djvused.html
 
 .. |djvuext| replace:: Actual and proposed changes to the DjVu format
-.. _djvuext: http://djvu.git.sourceforge.net/git/gitweb.cgi?p=djvu/djvulibre.git;a=blob;f=doc/djvuchanges.txt;hb=refs/tags/release.3.5.23
+.. _djvuext: https://sourceforge.net/p/djvu/djvulibre-git/ci/release.3.5.23/tree/doc/djvuchanges.txt
 '''
 
 # vim:ts=4 sts=4 sw=4 et
diff --git a/doc/api/event-model.rst b/doc/api/event-model.rst
index d508b44..1a9f5ef 100644
--- a/doc/api/event-model.rst
+++ b/doc/api/event-model.rst
@@ -59,7 +59,7 @@ The DDJVU API hides this complexity with a familiar event model.
       - The URI is used as a key for the cache of decoded pages.
       - The URI is used to document :class:`NewStreamMessage` messages.
 
-      Setting argument `cache` to a true vaule indicates that decoded pages
+      Setting argument `cache` to a true value indicates that decoded pages
       should be cached when possible.
 
       It is important to understand that the URI is not used to access the
diff --git a/doc/api/expressions.rst b/doc/api/expressions.rst
index 9d7d232..14c52c8 100644
--- a/doc/api/expressions.rst
+++ b/doc/api/expressions.rst
@@ -137,8 +137,8 @@ S-expressions
    >>> x.value
    Symbol('ham')
 
-Variétés
---------
+Varieties
+---------
 .. data:: EMPTY_LIST
 
    Empty list S-expression.
diff --git a/doc/api/messages.rst b/doc/api/messages.rst
index fdd8782..bb5cc23 100644
--- a/doc/api/messages.rst
+++ b/doc/api/messages.rst
@@ -82,16 +82,16 @@ Messages
       to ``None``.  It indicates that the decoder needs to access the data in
       the main DjVu file.
 
-      Further :class:`NewStreamMessage` messages messages are generated to access the
+      Further :class:`NewStreamMessage` messages are generated to access the
       auxiliary files of indirect or indexed DjVu documents. :attr:`name` then
       provides the base name of the auxiliary file.
 
 
    .. attribute:: uri
 
-      :return: the requrested URI.
+      :return: the requested URI.
 
-      URI is is set according to the `uri` argument provided to function
+      URI is set according to the `uri` argument provided to function
       :meth:`Context.new_document`. The first :class:`NewStreamMessage` message
       always contain the URI passed to :meth:`Context.new_document`.
       Subsequent :class:`NewStreamMessage` messages contain the URI of the
diff --git a/doc/api/text-zones.rst b/doc/api/text-zones.rst
index 1a4a493..b2110e1 100644
--- a/doc/api/text-zones.rst
+++ b/doc/api/text-zones.rst
@@ -112,7 +112,7 @@ Text zones
 .. currentmodule:: djvu.const
 .. data:: TEXT_ZONE_SEPARATORS
 
-   Dictionary that maps text types to their seprators.
+   Dictionary that maps text types to their separators.
 
    >>> pprint(TEXT_ZONE_SEPARATORS)
    {<djvu.const.TextZoneType: char>: '',
diff --git a/doc/changelog b/doc/changelog
index 8469086..962b918 100644
--- a/doc/changelog
+++ b/doc/changelog
@@ -1,3 +1,13 @@
+python-djvulibre (0.7.1) unstable; urgency=low
+
+  * Update URL for “actual and proposed changes to the DjVu format”.
+  * Use HTTPS for sourceforge.net URLs.
+  * Fix a few typos in the documentation.
+  * Improve the test suite:
+    + Normalize whitespace in ps2ascii output.
+
+ -- Jakub Wilk <jwilk at jwilk.net>  Fri, 11 Mar 2016 22:09:00 +0100
+
 python-djvulibre (0.7) unstable; urgency=low
 
   * Make Expression.from_string() accept both Unicode and byte strings.
diff --git a/examples/djvu-crop-text b/examples/djvu-crop-text
index 2025218..3bd305b 100755
--- a/examples/djvu-crop-text
+++ b/examples/djvu-crop-text
@@ -18,7 +18,6 @@ from __future__ import print_function
 
 import argparse
 import os
-import subprocess
 import sys
 
 import djvu.const
diff --git a/examples/djvu-dump-text b/examples/djvu-dump-text
index c4b9a70..d31eb2a 100755
--- a/examples/djvu-dump-text
+++ b/examples/djvu-dump-text
@@ -47,7 +47,7 @@ class Context(djvu.decode.Context):
         document.decoding_job.wait()
         for page in document.pages:
             page.get_info()
-            text = print_text(page.text.sexpr)
+            print_text(page.text.sexpr)
 
 def main():
     if len(sys.argv) != 2:
diff --git a/private/build-and-test b/private/apt-install-build-reqs
similarity index 56%
copy from private/build-and-test
copy to private/apt-install-build-reqs
index 3af78a6..bd7bff0 100755
--- a/private/build-and-test
+++ b/private/apt-install-build-reqs
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright © 2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2015-2016 Jakub Wilk <jwilk at jwilk.net>
 #
 # This file is part of python-djvulibre.
 #
@@ -13,36 +13,51 @@
 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 # more details.
 
+pkgs_base='
+build-essential
+libdjvulibre-dev
+pkg-config
+python-dev
+cython
+'
+pkgs_tests='
+python-nose
+djvulibre-bin
+ghostscript
+'
+pkgs="$pkgs_base"
+
 usage()
 {
-    printf 'Usage: %s [--no-build] [pythonX.Y...]\n' "$0"
+    printf '%s [--tests]\n' "$0"
 }
 
-args=$(getopt -n "$0" -o 'hj:' --long 'help,jobs:,no-build' -- "$@")
+args=$(getopt -n "$0" -o 'h' --long 'help,tests' -- "$@")
 if [ $? -ne 0 ]
 then
     usage >&2
     exit 1
 fi
+opt_tests=
 eval set -- "$args"
-opt_jobs=$(nproc) || opt_jobs=1
-opt_build=y
 while true
 do
     case "$1" in
         -h|--help) usage; exit 0;;
-	-j|--jobs) opt_jobs=$2; shift 2;;
-        --no-build) opt_build=; shift;;
+        --tests) opt_tests=y ; shift;;
         --) shift; break;;
         *) printf '%s: internal error (%s)\n' "$0" "$1" >&2; exit 1;;
     esac
 done
 
+[ "$opt_tests" ] && pkgs="$pkgs $pkgs_tests"
+
+PS4='# '
 set -e
-[ $# = 0 ] && set -- python
-[ -z $opt_build ] || \
-printf '%s\n' "$@" \
-| xargs -P"$opt_jobs" -t -I{python} env {python} setup.py build --build-lib build/{python}
-cd tests
-printf '%s\n' "$@" \
-| xargs -t -I{python} env PYTHONPATH="$PWD/../build/{python}" {python} $(which nosetests) --verbose
+(
+    set -x
+    # shellcheck disable=SC2086
+    apt-get install $pkgs
+)
+
+# vim:ts=4 sts=4 sw=4 et
diff --git a/private/build-and-test b/private/build-and-test
index 3af78a6..2ff9f47 100755
--- a/private/build-and-test
+++ b/private/build-and-test
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright © 2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2015-2016 Jakub Wilk <jwilk at jwilk.net>
 #
 # This file is part of python-djvulibre.
 #
@@ -31,7 +31,7 @@ while true
 do
     case "$1" in
         -h|--help) usage; exit 0;;
-	-j|--jobs) opt_jobs=$2; shift 2;;
+        -j|--jobs) opt_jobs=$2; shift 2;;
         --no-build) opt_build=; shift;;
         --) shift; break;;
         *) printf '%s: internal error (%s)\n' "$0" "$1" >&2; exit 1;;
@@ -42,7 +42,10 @@ set -e
 [ $# = 0 ] && set -- python
 [ -z $opt_build ] || \
 printf '%s\n' "$@" \
-| xargs -P"$opt_jobs" -t -I{python} env {python} setup.py build --build-lib build/{python}
+| xargs -P"$opt_jobs" -t -I'{python}' env '{python}' setup.py build --build-lib 'build/{python}'
 cd tests
+nosetests=$(command -v nosetests) || { echo nosetests not found >&2; exit 1; }
 printf '%s\n' "$@" \
-| xargs -t -I{python} env PYTHONPATH="$PWD/../build/{python}" {python} $(which nosetests) --verbose
+| xargs -t -I'{python}' env PYTHONPATH="$PWD/../build/{python}" '{python}' "$nosetests" --verbose
+
+# vim:ts=4 sts=4 sw=4 et
diff --git a/private/mingw32-setup-env b/private/mingw32-setup-env
index 167fb88..c58d2a8 100755
--- a/private/mingw32-setup-env
+++ b/private/mingw32-setup-env
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright © 2010-2014 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2010-2016 Jakub Wilk <jwilk at jwilk.net>
 #
 # This file is part of python-djvulibre.
 #
@@ -61,7 +61,7 @@ fflush
 free
 malloc
 EOF
-$target-dlltool --kill-at --def msvcr.def --dllname msvcr90.dll --output-lib "$pwd/$target/common/libmsvcr.a"
+"$target-dlltool" --kill-at --def msvcr.def --dllname msvcr90.dll --output-lib "$pwd/$target/common/libmsvcr.a"
 cd 'drive_c/Program Files/DjVuZone/DjVuLibre/'
 cp -v libdjvulibre.dll libjpeg.dll "$pwd/$target/common/"
 cp -vr include/libdjvu "$pwd/$target/common/"
diff --git a/python_djvulibre.egg-info/PKG-INFO b/python_djvulibre.egg-info/PKG-INFO
index 123cb9a..3052e9d 100644
--- a/python_djvulibre.egg-info/PKG-INFO
+++ b/python_djvulibre.egg-info/PKG-INFO
@@ -1,14 +1,14 @@
 Metadata-Version: 1.1
 Name: python-djvulibre
-Version: 0.7
+Version: 0.7.1
 Summary: Python support for the DjVu image format
 Home-page: http://jwilk.net/software/python-djvulibre
 Author: Jakub Wilk
 Author-email: jwilk at jwilk.net
 License: GNU GPL 2
-Description: *python-djvulibre* is a set of `Python <https://www.python.org>`_ bindings for
-        the `DjVuLibre <http://djvu.sf.net/>`_ library, an open source implementation
-        of `DjVu <http://djvu.org/>`_.
+Description: *python-djvulibre* is a set of Python bindings for
+        the `DjVuLibre <http://djvu.sourceforge.net/>`_ library,
+        an open source implementation of `DjVu <http://djvu.org/>`_.
 Platform: all
 Classifier: Development Status :: 4 - Beta
 Classifier: Intended Audience :: Developers
diff --git a/python_djvulibre.egg-info/SOURCES.txt b/python_djvulibre.egg-info/SOURCES.txt
index 6aa4d22..6e4ea0c 100644
--- a/python_djvulibre.egg-info/SOURCES.txt
+++ b/python_djvulibre.egg-info/SOURCES.txt
@@ -29,6 +29,7 @@ doc/api/text-zones.rst
 examples/djvu-crop-text
 examples/djvu-dump-text
 examples/djvu2png
+private/apt-install-build-reqs
 private/build-and-test
 private/mingw32-setup-env
 python_djvulibre.egg-info/PKG-INFO
diff --git a/setup.py b/setup.py
index f130791..6a2e4fd 100644
--- a/setup.py
+++ b/setup.py
@@ -14,9 +14,9 @@
 # more details.
 
 '''
-*python-djvulibre* is a set of `Python <https://www.python.org>`_ bindings for
-the `DjVuLibre <http://djvu.sf.net/>`_ library, an open source implementation
-of `DjVu <http://djvu.org/>`_.
+*python-djvulibre* is a set of Python bindings for
+the `DjVuLibre <http://djvu.sourceforge.net/>`_ library,
+an open source implementation of `DjVu <http://djvu.org/>`_.
 '''
 
 classifiers = '''
@@ -36,7 +36,6 @@ Topic :: Text Processing
 
 import glob
 import os
-import re
 import sys
 import subprocess as ipc
 
@@ -82,11 +81,13 @@ def ext_modules():
 ext_modules = list(ext_modules())
 
 def get_version():
-    if sys.version_info >= (3, 0):
-        extra = dict(encoding='UTF-8')
-    else:
-        extra = {}
-    changelog = open(os.path.join(os.path.dirname(__file__), 'doc', 'changelog'), **extra)
+    open_opts = {}
+    if str != bytes:
+        open_opts.update(encoding='UTF-8')
+    changelog = open(
+        os.path.join(os.path.dirname(__file__), 'doc', 'changelog'),
+        **open_opts
+    )
     try:
         return changelog.readline().split()[1].strip('()')
     finally:
@@ -158,10 +159,7 @@ djvulibre_version = pkgconfig_version('ddjvuapi')
 py_version = get_version()
 
 # Work-around for <https://bugs.python.org/issue969718>:
-try:
-    del os.environ['CFLAGS']
-except KeyError:
-    pass
+os.environ.pop('CFLAGS', None)
 
 class build_ext(distutils.command.build_ext.build_ext):
 
diff --git a/tests/test_decode.py b/tests/test_decode.py
index d06e93d..d0445e6 100644
--- a/tests/test_decode.py
+++ b/tests/test_decode.py
@@ -1,6 +1,6 @@
 # encoding=UTF-8
 
-# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2016 Jakub Wilk <jwilk at jwilk.net>
 #
 # This file is part of python-djvulibre.
 #
@@ -79,6 +79,7 @@ from tools import (
     assert_is,
     assert_is_instance,
     assert_list_equal,
+    assert_multi_line_equal,
     assert_raises,
     assert_raises_regex,
     assert_raises_str,
@@ -93,7 +94,6 @@ from tools import (
     wildcard_import,
     # Python 2/3 compat:
     b,
-    bytes,
     maxsize,
     py3k,
     u,
@@ -136,11 +136,11 @@ def create_djvu(commands='', sexpr=''):
         commands += '\nset-ant\n{sexpr}\n.\n'.format(sexpr=sexpr)
     file = tempfile.NamedTemporaryFile(prefix='test', suffix='djvu')
     file.seek(0)
-    file.write(bytes([
-        0x41, 0x54, 0x26, 0x54, 0x46, 0x4f, 0x52, 0x4d, 0x00, 0x00, 0x00, 0x22, 0x44, 0x4a, 0x56, 0x55,
-        0x49, 0x4e, 0x46, 0x4f, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x01, 0x18, 0x00, 0x2c, 0x01,
-        0x16, 0x01, 0x53, 0x6a, 0x62, 0x7a, 0x00, 0x00, 0x00, 0x04, 0xbc, 0x73, 0x1b, 0xd7,
-    ]))
+    file.write(
+        b'\x41\x54\x26\x54\x46\x4f\x52\x4d\x00\x00\x00\x22\x44\x4a\x56\x55'
+        b'\x49\x4e\x46\x4f\x00\x00\x00\x0a\x00\x01\x00\x01\x18\x00\x2c\x01'
+        b'\x16\x01\x53\x6a\x62\x7a\x00\x00\x00\x04\xbc\x73\x1b\xd7'
+    )
     file.flush()
     (stdout, stderr) = run('djvused', '-s', file.name, stdin=commands.encode(locale_encoding))
     assert_equal(stdout, ''.encode(locale_encoding))
@@ -428,20 +428,18 @@ class test_documents:
             assert_false(job.is_error)
             stdout, stderr = run('ps2ascii', tmp.name, LC_ALL='C')
             assert_equal(stderr, b(''))
-            stdout = stdout.split(b('\n'))
-            stdout = [b(' ').join(line.split()) for line in stdout]
-            assert_equal(stdout, [
-                b(''),
-                b(''),
-                b('1 Lorem ipsum'),
-                b('Optio reprehenderit molestias amet aliquam, similique doloremque fuga labore'),
-                b('voluptatum voluptatem, commodi culpa voluptas, officia tenetur expedita quidem hic'),
-                b(''),
-                b('repellat molestiae quis accusamus dolores repudiandae, quidem in ad voluptas'),
-                b('eligendi maiores placeat ex consectetur at tenetur amet.'),
-                b(''),
-                b('1'),
-            ])
+            stdout = stdout.decode('ASCII')
+            stdout = ' '.join(stdout.split())
+            expected = '''
+                1 Lorem ipsum
+                Optio reprehenderit molestias amet aliquam, similique doloremque fuga labore
+                voluptatum voluptatem, commodi culpa voluptas, officia tenetur expedita quidem
+                hic repellat molestiae quis accusamus dolores repudiandae, quidem in ad
+                voluptas eligendi maiores placeat ex consectetur at tenetur amet.
+                1
+            '''
+            expected = ' '.join(expected.split())
+            assert_multi_line_equal(stdout, expected)
         finally:
             del tmp
 
@@ -543,16 +541,16 @@ class test_page_jobs():
             page_job.render(RENDER_COLOR, (0, 0, x, x), (0, 0, x, x), PixelFormatRgb(), 8)
 
         s = page_job.render(RENDER_COLOR, (0, 0, 10, 10), (0, 0, 4, 4), PixelFormatGrey(), 1)
-        assert_equal(s, bytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xa4, 0xff, 0xff, 0xff, 0xb8]))
+        assert_equal(s, b'\xff\xff\xff\xff\xff\xff\xff\xef\xff\xff\xff\xa4\xff\xff\xff\xb8')
 
-        buffer = array.array('B', bytes([0]))
+        buffer = array.array('B', b'\0')
         with assert_raises_str(ValueError, 'Image buffer is too small (16 > 1)'):
             page_job.render(RENDER_COLOR, (0, 0, 10, 10), (0, 0, 4, 4), PixelFormatGrey(), 1, buffer)
 
-        buffer = array.array('B', bytes([0] * 16))
+        buffer = array.array('B', b'\0' * 16)
         assert_is(page_job.render(RENDER_COLOR, (0, 0, 10, 10), (0, 0, 4, 4), PixelFormatGrey(), 1, buffer), buffer)
         s = array_tobytes(buffer)
-        assert_equal(s, bytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xa4, 0xff, 0xff, 0xff, 0xb8]))
+        assert_equal(s, b'\xff\xff\xff\xff\xff\xff\xff\xef\xff\xff\xff\xa4\xff\xff\xff\xb8')
 
 class test_thumbnails:
 
@@ -572,15 +570,15 @@ class test_thumbnails:
         assert_is(pixels, None)
         (w, h, r), pixels = thumbnail.render((5, 5), PixelFormatGrey())
         assert_equal((w, h, r), (5, 3, 5))
-        assert_equal(pixels[:15], bytes([0xff, 0xeb, 0xa7, 0xf2, 0xff, 0xff, 0xbf, 0x86, 0xbe, 0xff, 0xff, 0xe7, 0xd6, 0xe7, 0xff]))
-        buffer = array.array('B', bytes([0]))
+        assert_equal(pixels[:15], b'\xff\xeb\xa7\xf2\xff\xff\xbf\x86\xbe\xff\xff\xe7\xd6\xe7\xff')
+        buffer = array.array('B', b'\0')
         with assert_raises_str(ValueError, 'Image buffer is too small (25 > 1)'):
             (w, h, r), pixels = thumbnail.render((5, 5), PixelFormatGrey(), buffer=buffer)
-        buffer = array.array('B', bytes([0] * 25))
+        buffer = array.array('B', b'\0' * 25)
         (w, h, r), pixels = thumbnail.render((5, 5), PixelFormatGrey(), buffer=buffer)
         assert_is(pixels, buffer)
         s = array_tobytes(buffer[:15])
-        assert_equal(s, bytes([0xff, 0xeb, 0xa7, 0xf2, 0xff, 0xff, 0xbf, 0x86, 0xbe, 0xff, 0xff, 0xe7, 0xd6, 0xe7, 0xff]))
+        assert_equal(s, b'\xff\xeb\xa7\xf2\xff\xff\xbf\x86\xbe\xff\xff\xe7\xd6\xe7\xff')
 
 def test_jobs():
 
diff --git a/tests/tools.py b/tests/tools.py
index 7aa0b07..89304be 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -20,92 +20,112 @@ import os
 import re
 import sys
 
+from nose import SkipTest
+
+import nose.tools
+
 from nose.tools import (
     assert_true,
     assert_false,
     assert_equal,
     assert_not_equal,
 )
-from nose import SkipTest
 
-if sys.version_info >= (2, 7):
-    from nose.tools import (
-        assert_in,
-        assert_is,
-        assert_is_instance,
-        assert_less,
-        assert_list_equal,
-        assert_multi_line_equal,
-        assert_not_in,
-        assert_raises,
+def noseimport(vmaj, vmin, name=None):
+    def wrapper(f):
+        if f.__module__ == 'unittest.case':
+            return f
+        if sys.version_info >= (vmaj, vmin):
+            return getattr(nose.tools, name or f.__name__)
+        return f
+    return wrapper
+
+ at noseimport(2, 7)
+def assert_in(x, y):
+    assert_true(
+        x in y,
+        msg='{0!r} not found in {1!r}'.format(x, y)
+    )
+
+ at noseimport(2, 7)
+def assert_is(x, y):
+    assert_true(
+        x is y,
+        msg='{0!r} is not {1!r}'.format(x, y)
+    )
+
+ at noseimport(2, 7)
+def assert_is_instance(obj, cls):
+    assert_true(
+        isinstance(obj, cls),
+        msg='{0!r} is not an instance of {1!r}'.format(obj, cls)
     )
-    if sys.version_info >= (3, 2):
-        from nose.tools import assert_raises_regex
-        from nose.tools import assert_regex
-    else:
-        from nose.tools import assert_raises_regexp as assert_raises_regex
-        from nose.tools import assert_regexp_matches as assert_regex
+
+ at noseimport(2, 7)
+def assert_less(x, y):
+    assert_true(
+        x < y,
+        msg='{0!r} not less than {1!r}'.format(x, y)
+    )
+
+ at noseimport(2, 7)
+def assert_list_equal(x, y):
+    assert_is_instance(x, list)
+    assert_is_instance(y, list)
+    return assert_equal(x, y)
+
+ at noseimport(2, 7)
+def assert_multi_line_equal(x, y):
+    return assert_equal(x, y)
+if sys.version_info >= (2, 7):
     type(assert_multi_line_equal.__self__).maxDiff = None
-else:
-    def assert_in(x, y):
-        assert_true(
-            x in y,
-            msg='{0!r} not found in {1!r}'.format(x, y)
-        )
-    def assert_is(x, y):
-        assert_true(
-            x is y,
-            msg='{0!r} is not {1!r}'.format(x, y)
-        )
-    def assert_is_instance(obj, cls):
-        assert_true(
-            isinstance(obj, cls),
-            msg='{0!r} is not an instance of {1!r}'.format(obj, cls)
-        )
-    def assert_less(x, y):
-        assert_true(
-            x < y,
-            msg='{0!r} not less than {1!r}'.format(x, y)
-        )
-    assert_list_equal = assert_equal
-    assert_multi_line_equal = assert_equal
-    def assert_not_in(x, y):
-        assert_true(
-            x not in y,
-            msg='{0!r} unexpectedly found in {1!r}'.format(x, y)
-        )
-    class assert_raises(object):
-        def __init__(self, exc_type):
-            self._exc_type = exc_type
-            self.exception = None
-        def __enter__(self):
-            return self
-        def __exit__(self, exc_type, exc_value, tb):
-            if exc_type is None:
-                assert_true(False, '{0} not raised'.format(self._exc_type.__name__))
-            if not issubclass(exc_type, self._exc_type):
-                return False
-            if isinstance(exc_value, exc_type):
-                pass
-                # This branch is not always taken in Python 2.6:
-                # https://bugs.python.org/issue7853
-            elif isinstance(exc_value, tuple):
-                exc_value = exc_type(*exc_value)
-            else:
-                exc_value = exc_type(exc_value)
-            self.exception = exc_value
-            return True
-    @contextlib.contextmanager
-    def assert_raises_regex(exc_type, regex):
-        with assert_raises(exc_type) as ecm:
-            yield
-        assert_regex(str(ecm.exception), regex)
-    def assert_regex(text, regex):
-        if isinstance(regex, basestring):
-            regex = re.compile(regex)
-        if not regex.search(text):
-            message = "Regex didn't match: {0!r} not found in {1!r}".format(regex.pattern, text)
-            assert_true(False, msg=message)
+
+ at noseimport(2, 7)
+def assert_not_in(x, y):
+    assert_true(
+        x not in y,
+        msg='{0!r} unexpectedly found in {1!r}'.format(x, y)
+    )
+
+ at noseimport(2, 7)
+class assert_raises(object):
+    def __init__(self, exc_type):
+        self._exc_type = exc_type
+        self.exception = None
+    def __enter__(self):
+        return self
+    def __exit__(self, exc_type, exc_value, tb):
+        if exc_type is None:
+            assert_true(False, '{0} not raised'.format(self._exc_type.__name__))
+        if not issubclass(exc_type, self._exc_type):
+            return False
+        if isinstance(exc_value, exc_type):
+            pass
+            # This branch is not always taken in Python 2.6:
+            # https://bugs.python.org/issue7853
+        elif isinstance(exc_value, tuple):
+            exc_value = exc_type(*exc_value)
+        else:
+            exc_value = exc_type(exc_value)
+        self.exception = exc_value
+        return True
+
+ at noseimport(2, 7, 'assert_raises_regexp')
+ at noseimport(3, 2)
+ at contextlib.contextmanager
+def assert_raises_regex(exc_type, regex):
+    with assert_raises(exc_type) as ecm:
+        yield
+    assert_regex(str(ecm.exception), regex)
+
+ at noseimport(2, 7, 'assert_regexp_matches')
+ at noseimport(3, 2)
+def assert_regex(text, regex):
+    if isinstance(regex, basestring):
+        regex = re.compile(regex)
+    if not regex.search(text):
+        message = "Regex didn't match: {0!r} not found in {1!r}".format(regex.pattern, text)
+        assert_true(False, msg=message)
 
 @contextlib.contextmanager
 def assert_raises_str(exc_type, s):
@@ -152,17 +172,11 @@ if py3k:
             return -1
         if x > y:
             return 1
-        assert 0
+        assert False
 else:
     cmp = cmp
 
 if py3k:
-    bytes = bytes
-else:
-    def bytes(iterable):
-        return ''.join(chr(c) for c in iterable)
-
-if py3k:
     from io import StringIO
 else:
     from io import BytesIO as StringIO
@@ -244,7 +258,6 @@ __all__ = [
     # Python 2/3 compat:
     'StringIO',
     'b',
-    'blob',
     'cmp',
     'long',
     'maxsize',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-djvulibre.git



More information about the Python-modules-commits mailing list