1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #908 closed

Test failures with PIL (Pillow) and Python 3

Arfrever Frehtes Taifersar Arahesis
created an issue

Pillow is a Python-3-compatible fork of PIL. When Pillow is installed for Python 3, then 8 tests of Pygments fail due to mixing of str and bytes. I use Pillow 2.1.0 and Pygments 1.6.

Example error:

======================================================================
ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.img.ImageFormatter'>, ('img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/tmp/Pygments-1.6/build/lib/test/test_basic_api.py", line 158, in verify
    inst.format(ts, out)
  File "/tmp/Pygments-1.6/build/lib/pygments/formatters/img.py", line 505, in format
    im.save(outfile, self.image_format.upper())
  File "/usr/lib64/python3.3/site-packages/PIL/Image.py", line 1452, in save
    save_handler(self, fp, filename)
  File "/usr/lib64/python3.3/site-packages/PIL/PngImagePlugin.py", line 538, in _save
    fp.write(_MAGIC)
TypeError: string argument expected, got 'bytes'

Comments (7)

  1. Arfrever Frehtes Taifersar Arahesis reporter
    • changed status to open

    Current trunk of Pygments has 4 errors in test_basic_api.py:

    ======================================================================
    ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.img.ImageFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python3.4/site-packages/nose/case.py", line 198, in runTest
        self.test(*self.arg)
      File "/tmp/pygments-main/tests/test_basic_api.py", line 179, in verify
        inst.format(ts, out)
      File "../pygments/formatters/img.py", line 515, in format
        im.save(outfile, self.image_format.upper())
      File "/usr/lib64/python3.4/site-packages/PIL/Image.py", line 1684, in save
        save_handler(self, fp, filename)
      File "/usr/lib64/python3.4/site-packages/PIL/PngImagePlugin.py", line 631, in _save
        fp.write(_MAGIC)
    TypeError: string argument expected, got 'bytes'
    
    ======================================================================
    ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.img.BmpImageFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python3.4/site-packages/nose/case.py", line 198, in runTest
        self.test(*self.arg)
      File "/tmp/pygments-main/tests/test_basic_api.py", line 179, in verify
        inst.format(ts, out)
      File "../pygments/formatters/img.py", line 515, in format
        im.save(outfile, self.image_format.upper())
      File "/usr/lib64/python3.4/site-packages/PIL/Image.py", line 1684, in save
        save_handler(self, fp, filename)
      File "/usr/lib64/python3.4/site-packages/PIL/BmpImagePlugin.py", line 229, in _save
        o32(offset))                 # image data offset
    TypeError: string argument expected, got 'bytes'
    
    ======================================================================
    ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.img.JpgImageFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python3.4/site-packages/PIL/ImageFile.py", line 468, in _save
        fh = fp.fileno()
    io.UnsupportedOperation: fileno
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/lib64/python3.4/site-packages/nose/case.py", line 198, in runTest
        self.test(*self.arg)
      File "/tmp/pygments-main/tests/test_basic_api.py", line 179, in verify
        inst.format(ts, out)
      File "../pygments/formatters/img.py", line 515, in format
        im.save(outfile, self.image_format.upper())
      File "/usr/lib64/python3.4/site-packages/PIL/Image.py", line 1684, in save
        save_handler(self, fp, filename)
      File "/usr/lib64/python3.4/site-packages/PIL/JpegImagePlugin.py", line 696, in _save
        ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
      File "/usr/lib64/python3.4/site-packages/PIL/ImageFile.py", line 479, in _save
        fp.write(d)
    TypeError: string argument expected, got 'bytes'
    
    ======================================================================
    ERROR: test_basic_api.test_formatter_public_api(<class 'pygments.formatters.img.GifImageFormatter'>,)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib64/python3.4/site-packages/nose/case.py", line 198, in runTest
        self.test(*self.arg)
      File "/tmp/pygments-main/tests/test_basic_api.py", line 179, in verify
        inst.format(ts, out)
      File "../pygments/formatters/img.py", line 515, in format
        im.save(outfile, self.image_format.upper())
      File "/usr/lib64/python3.4/site-packages/PIL/Image.py", line 1684, in save
        save_handler(self, fp, filename)
      File "/usr/lib64/python3.4/site-packages/PIL/GifImagePlugin.py", line 295, in _save
        fp.write(s)
    TypeError: string argument expected, got 'bytes'
    
    ----------------------------------------------------------------------
    Ran 1493 tests in 28.718s
    
    FAILED (errors=4)
    
  2. Log in to comment