-
Notifications
You must be signed in to change notification settings - Fork 124
Fix for #244 #245
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
Merged
Merged
Fix for #244 #245
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ cmd2.egg-info | |
| .cache | ||
| *.pyc | ||
| .coverage | ||
| .tox | ||
| htmlcov | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2398,7 +2398,22 @@ def _test_transcript(self, fname, transcript): | |
| self.assertTrue(re.match(expected, result, re.MULTILINE | re.DOTALL), message) | ||
|
|
||
| def _transform_transcript_expected(self, s): | ||
| """parse the string with slashed regexes into a valid regex""" | ||
| """parse the string with slashed regexes into a valid regex | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice description |
||
|
|
||
| Given a string like: | ||
|
|
||
| Match a 10 digit phone number: /\d{3}-\d{3}-\d{4}/ | ||
|
|
||
| Turn it into a valid regular expression which matches the literal text | ||
| of the string and the regular expression. We have to remove the slashes | ||
| because they differentiate between plain text and a regular expression. | ||
| Unless the slashes are escaped, in which case they are interpreted as | ||
| plain text, or there is only one slash, which is treated as plain text | ||
| also. | ||
|
|
||
| Check the tests in tests/test_transcript.py to see all the edge | ||
| cases. | ||
| """ | ||
| regex = '' | ||
| start = 0 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| """ | ||
| import os | ||
| import sys | ||
| import re | ||
| import random | ||
|
|
||
| import mock | ||
|
|
@@ -309,21 +310,25 @@ def test_transcript(request, capsys, filename, feedback_to_output): | |
|
|
||
|
|
||
| @pytest.mark.parametrize('expected, transformed', [ | ||
| ( 'text with no slashes', 'text\ with\ no\ slashes' ), | ||
| # stuff with just one slash | ||
| ( 'use 2/3 cup', 'use\ 2\/3\ cup' ), | ||
| ( '/tmp is nice', '\/tmp\ is\ nice'), | ||
| ( 'slash at end/', 'slash\ at\ end\/'), | ||
| # strings with zero or one slash or with escaped slashes means no regular | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. |
||
| # expression present, so the result should just be what re.escape returns. | ||
| # we don't use static strings in these tests because re.escape behaves | ||
| # differently in python 3.7 than in prior versions | ||
| ( 'text with no slashes', re.escape('text with no slashes') ), | ||
| ( 'specials .*', re.escape('specials .*') ), | ||
| ( 'use 2/3 cup', re.escape('use 2/3 cup') ), | ||
| ( '/tmp is nice', re.escape('/tmp is nice') ), | ||
| ( 'slash at end/', re.escape('slash at end/') ), | ||
| # escaped slashes | ||
| ( 'not this slash\/ or this one\/', re.escape('not this slash/ or this one/' ) ), | ||
| # regexes | ||
| ( 'specials .*', 'specials\ \.\*' ), | ||
| ( '/.*/', '.*' ), | ||
| ( 'specials ^ and + /[0-9]+/', 'specials\ \^\ and\ \+\ [0-9]+' ), | ||
| ( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}\ but\ not\ \/a\{6\}\ with\ .*?\ more' ), | ||
| ( 'not this slash\/ or this one\/', 'not\ this\ slash\\/\ or\ this\ one\\/' ), | ||
| ( 'not \/, use /\|?/, not \/', 'not\ \\/\,\ use\ \|?\,\ not\ \\/' ), | ||
| ( 'specials ^ and + /[0-9]+/', re.escape('specials ^ and + ') + '[0-9]+' ), | ||
| ( '/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}' + re.escape(' but not /a{6} with ') + '.*?' + re.escape(' more') ), | ||
| ( 'not \/, use /\|?/, not \/', re.escape('not /, use ') + '\|?' + re.escape(', not /') ), | ||
| # inception: slashes in our regex. backslashed on input, bare on output | ||
| ( 'not \/, use /\/?/, not \/', 'not\ \\/\,\ use\ /?\,\ not\ \\/' ), | ||
| ( 'the /\/?/ more /.*/ stuff', 'the\ /?\ more\ .*\ stuff' ), | ||
| ( 'not \/, use /\/?/, not \/', re.escape('not /, use ') + '/?' + re.escape(', not /') ), | ||
| ( 'lots /\/?/ more /.*/ stuff', re.escape('lots ') + '/?' + re.escape(' more ') + '.*' + re.escape(' stuff') ), | ||
| ]) | ||
| def test_parse_transcript_expected(expected, transformed): | ||
| app = CmdLineApp() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, that should have always been there ;-)