-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
messages: Add tests for transform_content. #1507
base: main
Are you sure you want to change the base?
Conversation
223c99d
to
9d51e8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other PR,
- type annotations
- test ids
Nice work with the noqa exceptions 😉
Nicely done!
I haven't looked into the scope and history behind this PR yet.
But the implementation lgtm.
[ | ||
( | ||
""" | ||
<p><a href="https://github.com/zulip/zulip-terminal/pull/1">https://github.com/zulip/zulip-terminal/pull/1</a></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have some link where the text is not the same as the link?
One of the first two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
9d51e8e
to
44fd0b4
Compare
44fd0b4
to
6db6378
Compare
Thanks for helping out with the noqa exceptions and for the detailed review! :) @Niloth-p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @rsashank
The test cases considered for each of the functions seem appropriate and enough for testing the respective aspects of the transform_content
function.
@@ -1585,14 +1587,120 @@ def test_keypress_EDIT_MESSAGE( | |||
# fmt: on | |||
], | |||
) | |||
def test_transform_content(self, mocker, raw_html, expected_content): | |||
def test_transform_content(self, raw_html: str, expected_content: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if there's a need for this change as we don't usually define data type for the function arguments or the function return variable as we decide what to pass.
You may not keep them in the newly created test function as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not currently type-checked, though it would be good to do so (there's an issue for it). Adding these right now are more like comments, which is fine but won't be tested or maintained, which is the downside - though if they keep passing manual review then they should help when we do apply mypy to these files.
Given the introduction of the similar transform_content tests, it would make sense to rename this test to define what set of cases it handles, so I'd consider it reasonable to update nearby lines like the types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rsashank This looks like an improvement to me 👍
In addition to my points inline, I'd consider the case of no links/mentions, and multiple ones.
Did you see an improvement in numeric coverage compared to this rebased against main
?
Historically we tested transform_content separately since it became a wrapper around soup2markup for quotes. These tests could be considered more complex tests for soup2markup, but transform_content seems fine too - the current soup2markup test is a simple rendering test only. One readability confusion in that regard is that all these tests are not near the soup2markup test (L676).
This PR has an interesting connection to the muted user work; there I mentioned that we likely need to parse the message to get these fields in any case, which could suggest we do the transform completely separately (earlier) than the header calculation. We currently remake the entire messagebox, I recall, but storing the content earlier may make updating only the content/author easier for muting/unmuting events.
@@ -1585,14 +1587,120 @@ def test_keypress_EDIT_MESSAGE( | |||
# fmt: on | |||
], | |||
) | |||
def test_transform_content(self, mocker, raw_html, expected_content): | |||
def test_transform_content(self, raw_html: str, expected_content: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not currently type-checked, though it would be good to do so (there's an issue for it). Adding these right now are more like comments, which is fine but won't be tested or maintained, which is the downside - though if they keep passing manual review then they should help when we do apply mypy to these files.
Given the introduction of the similar transform_content tests, it would make sense to rename this test to define what set of cases it handles, so I'd consider it reasonable to update nearby lines like the types.
tests/ui_tools/test_messages.py
Outdated
ids=[ | ||
"github_pr", | ||
"external_link_no_footlink", | ||
"internal_link", | ||
"github_link_with_text", | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have these ids inline.
Also the first is a github_pr (link) but it'd be useful to clarify what form it takes, ie. the link matches the text in that first case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github_pr_link_matches_text
?
), | ||
( | ||
""" | ||
<p><a href="#narrow/stream/206-zulip-terminal/topic/announce">https://chat.zulip.zulip/#narrow/stream/206-zulip-terminal/topic/announce</a></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these test cases all from real example messages, to indicate this is what we actually receive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I printed in debug mode and got them.
tests/ui_tools/test_messages.py
Outdated
], | ||
), | ||
], | ||
ids=["test_date", "distant_future_date", "past_date"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest inlining these too.
4d8ae77
to
9b09c07
Compare
This commit introduces tests for the `transform_content` class method, specifically focusing on the `message_links` and `time_mentions`. These enhancements improve the reliability and testing coverage of the `transform_content` method.
9b09c07
to
290ae47
Compare
Updated this PR @neiljp! Thanks for the feedback |
What does this PR do, and why?
This update PR tests for the transform_content class method for
self.message_links
andself.time_mentions
. The addition of these tests addresses feedback from issue #1455, which pointed out the lack of tests for these aspects.@neiljp said:
External discussion & connections
topic
How did you test this?
Self-review checklist for each commit