neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.48k stars 118 forks source link

test_invalid_utf8: Use distinct if/else branches #468

Closed jamessan closed 2 years ago

jamessan commented 3 years ago

pytest isn't able to report the expected value when using the X if Y else Z syntax.

See pytest-dev/pytest#7727

jamessan commented 3 years ago
Forcing an error does show the expected reporting ``` ===================================================================================================== FAILURES ===================================================================================================== ________________________________________________________________________________________________ test_invalid_utf8 _________________________________________________________________________________________________ vim = def test_invalid_utf8(vim): vim.command('normal "=printf("%c", 0xFF)\np') assert vim.eval("char2nr(getline(1))") == 0xFF if IS_PYTHON3: assert vim.current.buffer[:] == ['\udcff'] else: assert vim.current.buffer[:] == ['\xff'] vim.current.line += 'x' if IS_PYTHON3: assert vim.eval("getline(1)", decode=False) == '\udcffx' > assert vim.current.buffer[:] == ['\udcffxy'] E AssertionError: assert ['\udcffx'] == ['\udcffxy'] E At index 0 diff: '\udcffx' != '\udcffxy' E Full diff: E - ['\udcffx'] E + ['\udcffxy'] E ? + test/test_buffer.py:175: AssertionError ```
jamessan commented 3 years ago

Guess I didn't need to force a failure to see how this looks. Python 2 tests are failing and probably have been since they were added:

    def test_invalid_utf8(vim):
        vim.command('normal "=printf("%c", 0xFF)\np')
        assert vim.eval("char2nr(getline(1))") == 0xFF

        if IS_PYTHON3:
            assert vim.current.buffer[:] == ['\udcff']
        else:
>           assert vim.current.buffer[:] == ['\xff']
E           AssertionError: assert [''] == ['\xff']
E             At index 0 diff: u'' != '\xff'
E             Full diff:
E             - [u'']
E             + ['\xff']
blueyed commented 3 years ago

Note that assert 1 == 2 if 0 else 3 does not fail, but only assert 1 == (2 if 0 else 3)..!?

blueyed commented 3 years ago

Distinct branches are good for code coverage though anyway.

jamessan commented 3 years ago

I'm not sure what the correct behavior is supposed to be for Py2. @Shougo or @bfredl, can you advise?

bfredl commented 3 years ago

the correct default behaviour in python2 should be no decoding, i e get the raw '\xFF' byte out (and no unicode string)

jamessan commented 3 years ago

the correct default behaviour in python2 should be no decoding

Maybe you can push the right changes to my branch? I'm not familiar with the pynvim APIs.

jamessan commented 2 years ago

Closing in favor of #492, which rips out the py2 code, thus getting rid of the bug.