Skip to content

Transcript regexes now have predictable, tested, and documented behavior#216

Merged
tleonhardt merged 19 commits intopython-cmd2:masterfrom
kotfu:fix/transcript_regexes
Aug 23, 2017
Merged

Transcript regexes now have predictable, tested, and documented behavior#216
tleonhardt merged 19 commits intopython-cmd2:masterfrom
kotfu:fix/transcript_regexes

Conversation

@kotfu
Copy link
Copy Markdown
Contributor

@kotfu kotfu commented Aug 22, 2017

This PR makes a breaking change to the format and expectations of transcript testing. The prior behavior removed whitespace before making the comparison. This new version does not, whitespace must match exactly. In addition, slash characters not intended to denote regular expressions must now be escaped to match properly.

This closes #213

@kotfu kotfu requested a review from tleonhardt as a code owner August 22, 2017 17:45
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 22, 2017

Codecov Report

Merging #216 into master will increase coverage by 0.07%.
The diff coverage is 97.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
+ Coverage   96.74%   96.81%   +0.07%     
==========================================
  Files           1        1              
  Lines        1167     1194      +27     
==========================================
+ Hits         1129     1156      +27     
  Misses         38       38
Impacted Files Coverage Δ
cmd2.py 96.81% <97.5%> (+0.07%) ⬆️

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 3a842ab...d5f91bd. Read the comment docs.

@tleonhardt
Copy link
Copy Markdown
Member

I'll review this significant change later tonight. From a brief look, this looks fantastic! Thanks for the PR. I think you might want to pull the latest stuff from master to pick up some minor changes.

Copy link
Copy Markdown
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

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

Thank you for this fantastic PR.

You did an awesome job. Clear well-commented code, updated straightforward documentation, and thorough unit tests.

Comment thread cmd2.py

"""
listformat = '-------------------------[%d]\n%s\n'
listformat = '-------------------------[{}]\n{}\n'
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 like it! You are leaving code cleaner than you found it.

I've slowly been converting string formatting to use this newer .format() style with {} instead of the older printf-style formatting, but only when I change some nearby or related code.

Comment thread cmd2.py
# turn through the loop
start = second_slash_pos + 1
else:
# No closing slash, we have to add the first slash,
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.

Excellent comments throughout. Thanks for taking the time to comment well.

Comment thread cmd2.py

def _escaped_find(self, regex, s, start, in_regex):
"""
Find the next slash in {s} after {start} that is not preceded by a backslash.
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.

Just curious, does putting a function argument name inside curly braces within the function docstring do something special? I've got more of a C++ background and am relatively new to Python, so please forgive my ignorance and maybe I will learn something ;-)

Comment thread docs/transcript.rst
@@ -0,0 +1,161 @@
========================
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.

This section is a very nice addition to the existing user manual. It does a great job explaining what transcripts are, how to use them, and what some of the common pitfalls are and how to avoid them. Well done!

Comment thread examples/example.py
self.stdout.write('\n')
# self.stdout.write is better than "print", because Cmd can be
# initialized with a non-standard output destination
self.poutput(arg)
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.

Good catch. I recently converted all of the code within cmd2.py to use .poutput() instead of using stdout.write directly. I didn't go through all of the examples to make sure they were doing the same however.

Comment thread examples/example.py
do_orate = do_speak # another synonym, but this one takes multi-line input

@options([ make_option('-r', '--repeat', type="int", help="output [n] times") ])
def do_mumble(self, arg, opts=None):
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 like this addition. It is a convenient way to introduce motivation for using regexes within transcripts due to unpredictable randomness.

Comment thread tests/test_transcript.py

def test_regex_transcript(request, capsys):
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
@pytest.mark.parametrize('filename, feedback_to_output', [
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.

This was a smart way to expand the test coverage for transcripts essentially just by creating the transcripts themselves. I'm jealous I didn't think of it first ;-)

Comment thread tests/test_transcript.py
assert out == ''


@pytest.mark.parametrize('expected, transformed', [
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 am not a regex guy and am fundamentally unqualified to review this code. But you really seem like you know what you are doing, so thanks for the good work. Your code modifications seem to have excellent test coverage.

@tleonhardt
Copy link
Copy Markdown
Member

I manually forced an update to your PR branch to pull in the small number of changes from master. As long as that happened without conflicts and all of the unit tests pass, I'll merge it in shortly.

@tleonhardt tleonhardt merged commit 319e66b into python-cmd2:master Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backslashes get stripped from regexes used in transcript testing

2 participants