Skip to content

gh-89722: Add tests for pprint.pprint #95281

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hp310780
Copy link

@hp310780 hp310780 commented Jul 26, 2022

Add tests for pprint.pprint arguments indent, width, depth, compact, sort_dicts and underscore_numbers.

@ghost
Copy link

ghost commented Jul 26, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot bedevere-bot added awaiting review tests Tests in the Lib/test dir labels Jul 26, 2022
@@ -327,6 +327,12 @@ def test_nested_indentations(self):
'third': 3}]"""
self.assertEqual(pprint.pformat(o, indent=4, width=41), expected)

expected = "[ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n" \
Copy link
Member

Choose a reason for hiding this comment

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

I think you can write a helper function, something like assert_pprint(self, obj, expected, indent=1, width=80, depth=None) (mirroring the defaults of pprint.pprint), that then tests both pprint.pformat to a string and pprint,pprint to a stream. Then use it everywhere instead of duplicating the expected values everywhere. You'll probably need to ignore the trailing newline on the stream version.

@ericvsmith
Copy link
Member

The full signature would probably be (self, expected, object, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True, underscore_numbers=False). I'm not sure what order makes the most sense for expected and object.

@Privat33r-dev
Copy link
Contributor

@hp310780 thanks for your contribution. Any plans to continue your work on it?

@hp310780
Copy link
Author

hp310780 commented Jul 1, 2024

@hp310780 thanks for your contribution. Any plans to continue your work on it?

Hi there! Many apologies, I was restricted from open source due to some work legalities, but this is no longer the case. I see that this PR is still active with other contributions. Should I continue?

@Privat33r-dev
Copy link
Contributor

Hi there! Many apologies, I was restricted from open source due to some work legalities, but this is no longer the case. I see that this PR is still active with other contributions. Should I continue?

That's not a problem, no pressure here :) It would be great if you can continue.

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants