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

irc.utils, test: also remove null (\x00) in safe() #2620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dgw
Copy link
Member

@dgw dgw commented Sep 14, 2024

Description

Fixes #2566.

In test_irc_utils suite, rewrote test_safe and test_safe_bytes to generate a bunch more permutations of invalid characters automatically rather than writing them all out. The horse is definitely beaten far past death at this point... but the tests sure are thorough(bred).

Also renamed test_safe_null -> test_safe_none to avoid confusion; test_safe and test_safe_bytes are the cases that check behavior with null characters/bytes. Python's docs technically do refer to None as the "null object" once or twice, but most of the docs (and most of us devs) simply call it None.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make lint and make test)
    • Ran make lint myself, and tried out the test runner integration in VS Code / Gitpod. Very slick; made iterating my updated tests much easier without always tabbing back to the terminal.
  • I have tested the functionality of the things this change touches

Notes

This could go into 8.0.1, but I don't really want to mess around with hotfixes unless there's a major bug. I'm open to suggestions for improving the maintenance-branch workflow; since master is de facto for 8.1.0 dev now, the options are to keep the 8.0.x branch unprotected so I can push cherry-picks to it directly, or make @sopel-irc/rockstars review the same PR twice (once to master, once to 8.0.x) for full CI coverage. I don't love either of those.

In `test_irc_utils` suite, rewrote `test_safe` and `test_safe_bytes` to
generate a bunch more permutations of invalid characters automatically
rather than writing them all out. The horse is definitely beaten *far*
past death at this point... but the tests sure are thorough(bred).

Also renamed `test_safe_null` -> `test_safe_none` to avoid confusion;
`test_safe` and `test_safe_bytes` are the cases that check behavior with
null characters/bytes. Python's docs technically do refer to `None` as
the "null object" once or twice, but most of the docs (and most of us
devs) simply call it `None`.
@dgw dgw added the Bugfix Generally, PRs that reference (and fix) one or more issue(s) label Sep 14, 2024
@dgw dgw added this to the 8.1.0 milestone Sep 14, 2024
@dgw dgw requested a review from a team September 14, 2024 13:24
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Even tho I don't like when tests have too much logic in them, I draw the line at assert inside for-in bloc. I think @pytest.mark.parametrize is a much better option for these tests.

test/irc/test_irc_utils.py Outdated Show resolved Hide resolved
test/irc/test_irc_utils.py Outdated Show resolved Hide resolved
Using `pytest.mark.parametrize()` instead. Two test cases become 12.

Note: Yes, it is possible to have pytest treat each tuple generated by
`itertools.permutations()` as a single argument. Doing so yields useless
generated test-case names like `test_safe[seq0]`, though. Using three
separate test parameters of simple types (`str` or `bytes`) yields more
informative names like `test_safe[\n-\r-\x00]`.
@dgw dgw requested a review from Exirel September 15, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NUL (\x00) is not filtered from IRC args/text
2 participants