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

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

Open
wants to merge 3 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.

@cpython-cla-bot
Copy link

cpython-cla-bot bot 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?

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.

None yet

4 participants