-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[sonic-py-common] Add getstatusoutput_noshell() functions to general module #12065
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a6dd70
Add getstatusoutput_noshell functions
maipbui f7d90d0
Fix getstatusoutput and add check_output_pipe
maipbui 0e8f4ce
Fix PR commends and add UT
maipbui 8e3b376
Add ref
maipbui 5b256df
Modify code for python 2
maipbui bfd3862
Modify UT to pass py2
maipbui 38ca258
Return p1.stdout in exception 1
maipbui fbe43bf
Extend 2 functions to handle more pipe commands
maipbui 99ccf28
Fix PR comments
maipbui cd007de
Fix comments
maipbui 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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
import pytest | ||
import subprocess | ||
from sonic_py_common.general import getstatusoutput_noshell, getstatusoutput_noshell_pipe, check_output_pipe | ||
|
||
|
||
def test_getstatusoutput_noshell(tmp_path): | ||
exitcode, output = getstatusoutput_noshell(['echo', 'sonic']) | ||
assert (exitcode, output) == (0, 'sonic') | ||
|
||
exitcode, output = getstatusoutput_noshell([sys.executable, "-c", "import sys; sys.exit(6)"]) | ||
assert exitcode != 0 | ||
|
||
def test_getstatusoutput_noshell_pipe(): | ||
exitcode, output = getstatusoutput_noshell_pipe(['echo', 'sonic'], ['awk', '{print $1}']) | ||
assert (exitcode, output) == ([0, 0], 'sonic') | ||
|
||
exitcode, output = getstatusoutput_noshell_pipe([sys.executable, "-c", "import sys; sys.exit(6)"], [sys.executable, "-c", "import sys; sys.exit(8)"]) | ||
assert exitcode == [6, 8] | ||
|
||
def test_check_output_pipe(): | ||
output = check_output_pipe(['echo', 'sonic'], ['awk', '{print $1}']) | ||
assert output == 'sonic\n' | ||
|
||
with pytest.raises(subprocess.CalledProcessError) as e: | ||
check_output_pipe([sys.executable, "-c", "import sys; sys.exit(6)"], [sys.executable, "-c", "import sys; sys.exit(0)"]) | ||
assert e.returncode == [6, 0] | ||
|
||
with pytest.raises(subprocess.CalledProcessError) as e: | ||
check_output_pipe([sys.executable, "-c", "import sys; sys.exit(0)"], [sys.executable, "-c", "import sys; sys.exit(6)"]) | ||
assert e.returncode == [0, 6] |
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.
Please add unit tests to cover new functions. #Closed
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.
Sure, working on UT