-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/unit/test_dump_xapi_procs.py: Test dump_xapi_subprocess_info() (#…
…85) Signed-off-by: Bernhard Kaindl <[email protected]>
- Loading branch information
1 parent
493e0a2
commit bd7e5df
Showing
4 changed files
with
46 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ repos: | |
- defusedxml | ||
- lxml | ||
- mock | ||
- pyfakefs | ||
- pytest-coverage | ||
- pytest-mock | ||
- XenAPI | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
lxml | ||
mock | ||
pyfakefs | ||
pytest-coverage | ||
pytest-mock | ||
types-mock |
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,34 @@ | ||
"""This module contains the unit tests for the dump_xapi_procs function""" | ||
|
||
import sys | ||
|
||
|
||
def test_dump_xapi_subprocess_info(bugtool, fs): | ||
"""Test the dump_xapi_subprocess_info() function to perform as expected""" | ||
|
||
# Prepare the virtual pyfakefs filesystem for the test | ||
|
||
fs.create_file("/proc/2/status", contents="PPid: 1") | ||
fs.create_file("/proc/3/status", contents="PPid: 2") | ||
fs.create_file("/proc/4/status", contents="") | ||
fs.create_file("/proc/2/cmdline", contents="/opt/xensource/bin/xapi") | ||
fs.create_file("/proc/3/cmdline", contents="/bin/sh") | ||
fs.create_file("/proc/4/cmdline", contents="") | ||
fs.create_symlink("/proc/2/fd/1", "/dev/null") | ||
fs.create_symlink("/proc/3/fd/0", "/dev/zero") | ||
|
||
# Prepare the expected result | ||
|
||
expected_result = """{ '2': { 'children': { '3': { 'children': {}, | ||
'cmdline': '/bin/sh', | ||
'fds': {'0': '/dev/zero'}}}, | ||
'cmdline': '/opt/xensource/bin/xapi', | ||
'fds': {'1': '/dev/null'}}}""" | ||
|
||
if sys.version_info.major == 2: # pragma: no cover | ||
expected_result = expected_result.replace("{}", "{ }") | ||
expected_result = expected_result.replace(": {'", ": { '") | ||
|
||
# Assert the expected result | ||
|
||
assert bugtool.dump_xapi_subprocess_info("cap") == expected_result |