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

Tests: Explicitly set cursor position #2529

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Nov 18, 2024

Since we updated QScintilla 2.13 -> 2.14 in Fedora 41+, we see this test failure:

_____________ test_EditorPane_toggle_comments_handle_crlf_newline ______________
    def test_EditorPane_toggle_comments_handle_crlf_newline():
        """
        Check that stray "\r\n" line endings don't lead to deleting the first
        character of the following line.
        """
        ep = mu.interface.editor.EditorPane(None, "test\r\nline 2\n")
        ep.hasSelectedText = mock.MagicMock(return_value=False)
        ep.toggle_comments()
>       assert ep.text() == "# test\nline 2\n"
E       AssertionError: assert 'test\r\nline 2\n' == '# test\nline 2\n'
E
E         - # test
E         ? --
E         + test
E         ?     +
E           line 2
tests/interface/test_editor.py:940: AssertionError

I've added some debugging prints and realized that getCursorPosition() returns 2, 0 in this test, while is assumes the cursor is on line 0.

By explicitly calling setCursorPosition() we fix the test and we make it more clear to the reader.

Since we updated QScintilla 2.13 -> 2.14 in Fedora 41+,
we see this test failure:

    _____________ test_EditorPane_toggle_comments_handle_crlf_newline ______________
        def test_EditorPane_toggle_comments_handle_crlf_newline():
            """
            Check that stray "\r\n" line endings don't lead to deleting the first
            character of the following line.
            """
            ep = mu.interface.editor.EditorPane(None, "test\r\nline 2\n")
            ep.hasSelectedText = mock.MagicMock(return_value=False)
            ep.toggle_comments()
    >       assert ep.text() == "# test\nline 2\n"
    E       AssertionError: assert 'test\r\nline 2\n' == '# test\nline 2\n'
    E
    E         - # test
    E         ? --
    E         + test
    E         ?     +
    E           line 2
    tests/interface/test_editor.py:940: AssertionError

I've added some debugging prints and realized that getCursorPosition()
returns 2, 0 in this test, while is assumes the cursor is on line 0.

By explicitly calling setCursorPosition() we fix the test and we make it
more clear to the reader.
Copy link
Member

@carlosperate carlosperate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Thanks @hroncok!

@carlosperate carlosperate merged commit 701f7b4 into mu-editor:master Dec 13, 2024
22 of 31 checks passed
@carlosperate carlosperate added this to the 1.2.2 milestone Dec 16, 2024
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.

2 participants