Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_invalid_utf8: Use distinct if/else branches #468

Closed
wants to merge 1 commit into from

Conversation

jamessan
Copy link
Member

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

See pytest-dev/pytest#7727

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

See pytest-dev/pytest#7727
@jamessan
Copy link
Member Author

jamessan commented Nov 25, 2020

Forcing an error does show the expected reporting
===================================================================================================== FAILURES =====================================================================================================
________________________________________________________________________________________________ test_invalid_utf8 _________________________________________________________________________________________________

vim = <pynvim.api.nvim.Nvim object at 0xb608d1f0>

    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
Copy link
Member Author

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
Copy link
Contributor

blueyed commented Nov 25, 2020

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

@blueyed
Copy link
Contributor

blueyed commented Nov 25, 2020

Distinct branches are good for code coverage though anyway.

@jamessan
Copy link
Member Author

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

@bfredl
Copy link
Member

bfredl commented Nov 25, 2020

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

@jamessan
Copy link
Member Author

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
Copy link
Member Author

jamessan commented Aug 6, 2021

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

@jamessan jamessan closed this Aug 6, 2021
@jamessan jamessan deleted the error-reporting branch August 6, 2021 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants