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

Show diff report in accessible colors and reveal hidden line characters #126

Merged
merged 17 commits into from
Mar 7, 2020

Conversation

noahnu
Copy link
Collaborator

@noahnu noahnu commented Feb 9, 2020

Description

Refactors the diff reporter to improve accessibility and show diff on newlines and carriage returns.

Related Issues

Checklist

  • This PR has sufficient test coverage.
  • I have updated the CHANGELOG.md.

Additional Comments

No additional comments.

@codecov
Copy link

codecov bot commented Mar 6, 2020

Codecov Report

Merging #126 into master will not change coverage by %.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #126   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines          757       847   +90     
=========================================
+ Hits           757       847   +90     

@iamogbz iamogbz changed the title wip: rewrite assertion diff report Show diff report in accessible colors and reveal hidden line characters Mar 6, 2020

@property
def _context_line_count(self) -> int:
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Previous implementation is equivalent to setting this to 0

@@ -28,7 +29,7 @@ class DataSerializer:

class MarkerDepthMax:
def __repr__(self) -> str:
return "..."
return SYMBOL_ELLIPSIS
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Even though we use the same symbol for context & max depth, semantically they're different and could theoretically change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, but then we could split the symbols apart at that point

Comment on lines +343 to +352
count_leading_whitespace: Callable[[str], int] = (
lambda s: len(s) - len(s.lstrip()) # noqa: E731
)
if self._context_line_count:
num_space = (
count_leading_whitespace(lines[self._context_line_count - 1])
+ count_leading_whitespace(lines[-self._context_line_count])
) // 2
else:
num_space = count_leading_whitespace(lines[num_lines // 2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Simpler to reason about but leaves room for ... having weird indentation

Suggested change
count_leading_whitespace: Callable[[str], int] = (
lambda s: len(s) - len(s.lstrip()) # noqa: E731
)
if self._context_line_count:
num_space = (
count_leading_whitespace(lines[self._context_line_count - 1])
+ count_leading_whitespace(lines[-self._context_line_count])
) // 2
else:
num_space = count_leading_whitespace(lines[num_lines // 2])
mid_line = lines[num_lines // 2]
num_space = len(mid_line) - len(mid_line.lstrip())

@iamogbz iamogbz marked this pull request as ready for review March 6, 2020 22:39
@noahnu noahnu self-assigned this Mar 6, 2020
is_diff_line = line[0] == "?"

if is_context_line or is_diff_line:
line = self.__strip_ends(line)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was originally thinking of only showing the new line endings (i.e. the symbols) if necessary. So if the line endings are the only change.

[
(
"line 0\nline 1\nline 02\nline 3\nline 4\r\nline 5\nline 6\nline 7",
"line 0\nline 1\nline 2\r\nline 3\nline 04\nline 5\nline 6\nline 7",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

more cases:

  • trailing newlines
  • where the difference between 2 sets is extra whitespace (space, tab) at the end
  • different number of lines (additions + deletions)

@noahnu
Copy link
Collaborator Author

noahnu commented Mar 7, 2020

LGTM

Copy link
Collaborator

@iamogbz iamogbz left a comment

Choose a reason for hiding this comment

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

LGTM

@iamogbz iamogbz merged commit fa442df into master Mar 7, 2020
@iamogbz iamogbz deleted the improved_assertion_diff branch March 7, 2020 00:27
syrupy-bot pushed a commit that referenced this pull request Mar 8, 2020
## [0.3.4](v0.3.3...v0.3.4) (2020-03-08)

### Bug Fixes

* show hidden line characters and accessible colors ([#126](#126)) ([fa442df](fa442df)), closes [#150](#150)
@syrupy-bot
Copy link
Contributor

🎉 This PR is included in version 0.3.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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