Skip to content

bpo-41734: refactor b32{encode,decode} tests#22122

Closed
FFY00 wants to merge 1 commit into
python:mainfrom
FFY00:bpo-41734
Closed

bpo-41734: refactor b32{encode,decode} tests#22122
FFY00 wants to merge 1 commit into
python:mainfrom
FFY00:bpo-41734

Conversation

@FFY00
Copy link
Copy Markdown
Member

@FFY00 FFY00 commented Sep 6, 2020

Matching b32hex{encode,decode}.

Signed-off-by: Filipe Laíns lains@archlinux.org

https://bugs.python.org/issue41734

Matching b32hex{encode,decode}.

Signed-off-by: Filipe Laíns <lains@archlinux.org>
@FFY00
Copy link
Copy Markdown
Member Author

FFY00 commented Sep 6, 2020

cc @pganssle

Copy link
Copy Markdown
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

I'm +1 on this, but I think it should probably have a news entry, even though it only affects the tests, in case it breaks something for downstream redistributors for some reason.

Given that there's a tests section to the Changelog, I think we may as well err on the side of caution here.

Comment thread Lib/test/test_base64.py
eq(base64.b32decode(data, True), res)
eq(base64.b32decode(data.decode('ascii'), True), res)
def test_b32hexdecode(self):
test_cases = [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like we've had this conversation before and I must have been convinced otherwise, but I can't help but think that this might be a bit easier to read as some variation on this:

test_cases = [
    (to_decode, expected, casefold)
    for casefold in [True, False]
    for to_decode, expected in [
    # to_decode, expected
    (b'',         b'')
    (b'AA======', b'\x00'),
    (b'ME======', b'a'),
    (b'MFRA====', b'ab'),
    (b'MFRGG===', b'abc'),
    (b'MFRGGZA=', b'abcd'),
    (b'MFRGGZDF', b'abcde'),
]] + [
    # to_decode, expected, casefold
    (b'me======', b'a',     True),
    (b'mfra====', b'ab',    True),
    (b'mfrgg===', b'abc',   True),
    (b'mfrggza=', b'abcd',  True),
    (b'mfrggzdf', b'abcde', True),
]

Downsides: It's got a control structure in it, and the final version of it isn't fully "spelled out".

Upsides: The test cases that are tested with both casefold=True and casefold=False are much more clearly delineated from the ones that are only tested with casefold=True, and the test cases aren't repeated.

I'm on the fence so I'll defer to the author in case anyone else feels strongly about it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can make that change, sure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Personally I find the less logic in tests, the better. Flat list of cases is the easiest to read and change. I even like the alignment of entries which I strongly dislike in regular code! 🙂

@bedevere-bot
Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@FFY00
Copy link
Copy Markdown
Member Author

FFY00 commented Sep 8, 2020

Before putting any more work into this can we discuss it in BPO as @serhiy-storchaka marked it as rejected?

@arhadthedev
Copy link
Copy Markdown
Member

@FFY00 2.5 years passed with no reconsideration. Should this stylistic PR and associated issue be closed then?

@FFY00
Copy link
Copy Markdown
Member Author

FFY00 commented Nov 17, 2024

Yeah, closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants