jaraco / irc

Full-featured Python IRC library for Python.
MIT License
392 stars 86 forks source link

DecodingLineBuffer doctest fails #42

Closed jaraco closed 8 years ago

jaraco commented 8 years ago

On my system, the DecodingLineBuffer doctest fails. It seems that doctest is expecting the exception output to exactly match by default.

Per a quick read of https://docs.python.org/2/library/doctest.html#what-about-exceptions, it seems like you need either +ELLIPSIS or +IGNORE_EXCEPTION_DETAIL.

The attached patch sets IGNORE_EXCEPTION_DETAIL, since it's supposedly more strict, but ELLIPSIS works too.

$ nosetests --with-doctest
.F............................F.......
======================================================================
FAIL: Doctest: irc.buffer.DecodingLineBuffer
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 2226, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for irc.buffer.DecodingLineBuffer
  File "/home/user/src/irc/irc/buffer.py", line 57, in DecodingLineBuffer

----------------------------------------------------------------------
File "/home/user/src/irc/irc/buffer.py", line 81, in irc.buffer.DecodingLineBuffer
Failed example:
    list(b.lines())
Expected:
    Traceback (most recent call last):
    ...
    UnicodeDecodeError: ...
Got:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest irc.buffer.DecodingLineBuffer[11]>", line 1, in <module>
        list(b.lines())
      File "/home/user/src/irc/irc/buffer.py", line 94, in lines
        self.handle_exception()
      File "/home/user/src/irc/irc/buffer.py", line 92, in lines
        yield line.decode(self.encoding, self.errors)
      File "/home/user/src/ircenv/lib/python2.7/encodings/utf_8.py", line 16, in decode
        return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 2: unexpected end of data

(The other test failure is due to me not using setuptools/pkg_resources.)


jaraco commented 8 years ago

Do you know why this test doesn't fail for me? Could it be that pytest enables those features for tests that need them? I recommend against nosetests, because I've found the project to be unresponsive to tickets, so I use pytest exclusively. I find it to be better maintained and more robust. Try running the tests with "python setup.py ptr" and let me know if you still encounter the error.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

python setup.py ptr passes. I'll dig some more.

But I need to make things work without setuptools, as well as exit non-zero if there are failing tests. py.test --ignore docs seems to do the trick.


Original comment by: Mikel Ward

jaraco commented 8 years ago

I'm surprised running py.test by itself doesn't result in the same outcome as ptr. In any case, I'm glad you found something that works.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

I'd prefer not to complicate the tests to support edge cases if possible.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

FTR, as expected, pytest is calling doctest with optionflags=doctest.ELLIPSIS.

_pytest/doctest.py:122

So nothing to do here.


Original comment by: Mikel Ward

jaraco commented 8 years ago

Thanks for the clarification. I learned something new.


Original comment by: Jason R. Coombs