-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 rule to remove leading shell prompt literal $ #996
Conversation
Rule added to handle cases where the $ symbol is used in the command, this usually happens when the command is copy pasted from a documentation that includes the shell prompt symbol in the code blocks.
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.
Thanks for contributing! Please, mind my comments.
|
||
|
||
@pytest.mark.parametrize( | ||
"command", |
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.
How about parametrizing only script
(as string) and declare a Command
instance with "$: command not found"
as output
?
"command", | |
"script", |
That would make all test tables more readable.
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
Command("$ cd newdir", "$: command not found"), |
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.
Command("$ cd newdir", "$: command not found"), | |
"$ cd newdir", |
Command(" $ cd newdir", "$: command not found"), | ||
], | ||
) | ||
def test_match(command): |
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.
def test_match(command): | |
def test_match(script): |
], | ||
) | ||
def test_match(command): | ||
assert match(command) |
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.
assert match(command) | |
assert match(Command(script, "$: command not found")) |
@pytest.mark.parametrize( | ||
"command", | ||
[Command("$", ""), Command("$?", ""), Command(" $?", ""), Command("", "")], | ||
) | ||
def test_not_match(command): | ||
assert not match(command) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, new_command", | ||
[ | ||
(Command("$ cd newdir", ""), "cd newdir"), | ||
(Command("$ python3 -m virtualenv env", ""), "python3 -m virtualenv env"), | ||
], | ||
) | ||
def test_get_new_command(command, new_command): | ||
assert get_new_command(command) == new_command |
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.
Ditto.
return command.script.replace("$", "", 1).strip() | ||
|
||
|
||
requires_output = True |
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.
This can be omitted as requires_output
's default value is True
.
- Refactor test for cleaner test tables - Removed unnecessary requires_output=True option
Thanks for the comments @scorphus! I have made the modifications as suggested. However, the non matches were not changed as I realised that the outputs were not the same for every test case. |
Looks good, thanks! |
Rule added to remove leading shell prompt literals found in the command.
This usually happens when a command is copy pasted from documentations with code blocks that contain it.