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

add tests for multiline reprs #2267

Closed
wants to merge 2 commits into from
Closed

add tests for multiline reprs #2267

wants to merge 2 commits into from

Conversation

rodrigogiraoserrao
Copy link
Contributor

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

This pull request will fix #2073 . Reasoning and thought process described in excruciating detail in this article about contributing to Open Source.

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2022

Codecov Report

Merging #2267 (cd7070f) into master (14d47c9) will decrease coverage by 0.08%.
The diff coverage is 96.89%.

@@            Coverage Diff             @@
##           master    #2267      +/-   ##
==========================================
- Coverage   98.88%   98.80%   -0.09%     
==========================================
  Files          73       73              
  Lines        7629     7681      +52     
==========================================
+ Hits         7544     7589      +45     
- Misses         85       92       +7     
Flag Coverage Δ
unittests 98.80% <96.89%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/_export_format.py 100.00% <ø> (ø)
rich/console.py 98.28% <95.91%> (-0.50%) ⬇️
rich/pretty.py 99.24% <100.00%> (+0.02%) ⬆️
rich/syntax.py 99.30% <100.00%> (+0.02%) ⬆️
rich/terminal_theme.py 100.00% <100.00%> (ø)
rich/traceback.py 98.68% <0.00%> (-0.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1772458...cd7070f. Read the comment docs.

@rodrigogiraoserrao
Copy link
Contributor Author

rodrigogiraoserrao commented May 14, 2022

@willmcgugan I have a question about this.

There's 2 main things to solving #2073. Making sure pretty_repr understands that some objects might have multiline reprs and pprint not adding vertical guidelines to those. So far, this draft takes care of pretty_repr.
I will study pprint better to see how I can take care of not adding vertical guidelines.

Question: do I add unit tests that comprehensively check that the pretty_repr function does the proper job of indenting objects with multiline reprs when inside all the containers that pretty_repr knows about? So far, the tests only cover a couple of containers like tuples, dictionaries, and lists.

Question: I only changed the file pretty.py, how come I managed to change the code coverage of traceback.py, syntax.py, console.py?

@willmcgugan
Copy link
Collaborator

It's probably not necessary to test every container, as long as the system is well-tests.

The coverage calculation is quite flakey. It always seems to be off!

@rodrigogiraoserrao
Copy link
Contributor Author

rodrigogiraoserrao commented May 15, 2022

Right.

There is another fundamental issue with what I've done. I changed _Line.__str__ so that, sometimes, it returns a multi-line string. I know how careful you are with naming, so what should happen now?

  1. _Line gets renamed because it doesn't represent a line of output, but more like a unit block or something.
  2. I create multiple _Line instances for nodes with multi-line reprs.
  3. My changes are actually OK because _Line says it represents some node output that starts on its own line, which is still true.

@willmcgugan
Copy link
Collaborator

I think _Line being private, I can relax my pedantry a bit. But equally open to a better name if you can think of one!

@willmcgugan
Copy link
Collaborator

@rodrigogiraoserrao Is this stale?

@rodrigogiraoserrao
Copy link
Contributor Author

Nah, I'm just overwhelmed with life. I'll finish this ASAP.
If you want, close this PR draft and I'll open a new one with all the changes when they're done.

@willmcgugan
Copy link
Collaborator

No hurry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] When pretty-printed, items with a multi-line repr are not indented
3 participants