Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_process
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
common_helper_process
Commits
60092602
Commit
60092602
authored
7 years ago
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return code variant added
parent
a22ebb76
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
3 deletions
+28
-3
fail_safe_subprocess.py
common_helper_process/fail_safe_subprocess.py
+15
-1
setup.py
setup.py
+1
-1
test_fail_safe_subprocess.py
test/test_fail_safe_subprocess.py
+12
-1
No files found.
common_helper_process/fail_safe_subprocess.py
View file @
60092602
...
@@ -10,7 +10,21 @@ def execute_shell_command(shell_command):
...
@@ -10,7 +10,21 @@ def execute_shell_command(shell_command):
:type shell_command: str
:type shell_command: str
:return: str
:return: str
"""
"""
return
execute_shell_command_get_return_code
(
shell_command
)[
0
]
def
execute_shell_command_get_return_code
(
shell_command
):
"""
Execute a shell command and return STDOUT and STDERR in one combined result string.
This function shall not raise any errors
:param shell_command: command to execute
:type shell_command: str
:return: str, int
"""
output
=
""
output
=
""
rc
=
1
with
Popen
(
shell_command
,
shell
=
True
,
stdout
=
PIPE
,
stderr
=
STDOUT
)
as
pl
:
with
Popen
(
shell_command
,
shell
=
True
,
stdout
=
PIPE
,
stderr
=
STDOUT
)
as
pl
:
output
=
pl
.
communicate
()[
0
]
.
decode
(
'utf-8'
,
errors
=
'replace'
)
output
=
pl
.
communicate
()[
0
]
.
decode
(
'utf-8'
,
errors
=
'replace'
)
return
output
rc
=
pl
.
returncode
return
output
,
rc
This diff is collapsed.
Click to expand it.
setup.py
View file @
60092602
from
setuptools
import
setup
,
find_packages
from
setuptools
import
setup
,
find_packages
VERSION
=
0.
1
VERSION
=
0.
2
setup
(
setup
(
name
=
"common_helper_process"
,
name
=
"common_helper_process"
,
...
...
This diff is collapsed.
Click to expand it.
test/test_fail_safe_subprocess.py
View file @
60092602
import
unittest
import
unittest
from
common_helper_process
import
execute_shell_command
from
common_helper_process
import
execute_shell_command
from
common_helper_process.fail_safe_subprocess
import
execute_shell_command_get_return_code
class
Test
(
unittest
.
TestCase
):
class
Test
ProcessHelper
(
unittest
.
TestCase
):
def
test_execute_shell_command
(
self
):
def
test_execute_shell_command
(
self
):
result
=
execute_shell_command
(
"echo 'test 123'"
)
result
=
execute_shell_command
(
"echo 'test 123'"
)
...
@@ -12,3 +13,13 @@ class Test(unittest.TestCase):
...
@@ -12,3 +13,13 @@ class Test(unittest.TestCase):
def
test_execute_shell_command_error
(
self
):
def
test_execute_shell_command_error
(
self
):
result
=
execute_shell_command
(
"echo 'test 123' 1>&2 && exit 2"
)
result
=
execute_shell_command
(
"echo 'test 123' 1>&2 && exit 2"
)
self
.
assertEqual
(
result
,
'test 123
\n
'
,
'result not correct'
)
self
.
assertEqual
(
result
,
'test 123
\n
'
,
'result not correct'
)
def
test_execute_shell_command_incl_rc
(
self
):
output
,
rc
=
execute_shell_command_get_return_code
(
"echo 'test 123'"
)
self
.
assertEqual
(
output
,
'test 123
\n
'
,
'result not correct'
)
self
.
assertEqual
(
rc
,
0
,
'return code not correct'
)
def
test_execute_shell_command_error_incl_rc
(
self
):
output
,
rc
=
execute_shell_command_get_return_code
(
"echo 'test 123' 1>&2 && exit 2"
)
self
.
assertEqual
(
output
,
'test 123
\n
'
,
'result not correct'
)
self
.
assertEqual
(
rc
,
2
,
'return code not correct'
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment