-
Notifications
You must be signed in to change notification settings - Fork 15
[New test]: Add test_cmd_output.py: Test for cmd_output()
#170
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
bernhardkaindl
merged 2 commits into
xenserver:master
from
xenserver-next:add-test-case-for-cmd_output-function
Feb 9, 2026
Merged
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
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
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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """tests/unit/test_cmd_output.py: Unit-Test bugtool.cmd_output()""" | ||
|
|
||
|
|
||
| def test_cmd_output_mismatching_cap(bugtool_fixture): | ||
| """Assert that mismatching cap causes no extension of bugtool.data:""" | ||
|
|
||
| # Prepare that mismatching cap causes no output in bugtool.data: | ||
| bugtool_fixture.entries = [bugtool_fixture.CAP_PAM] | ||
|
|
||
| # Act | ||
| bugtool_fixture.cmd_output(bugtool_fixture.CAP_XENSERVER_LOGS, ["/bin/sh"]) | ||
|
|
||
| # Assert that the command is not added to data | ||
| assert bugtool_fixture.data == {} | ||
|
|
||
|
|
||
| def check_cmd_output_data(bugtool, command, label=None, filter_func=None): | ||
| """ | ||
| Assert that cmd_output() stores the expected command in bugtool.data | ||
| It works by setting bugtool.data and bugtool.entries to fixed values | ||
| and asserting the expected bugtool.data after the check. | ||
|
|
||
| Use this function only with bugtool_fixture which saves and restores | ||
| the original values of these variables to avoid affecting other test cases. | ||
| """ | ||
|
|
||
| # Prepare | ||
| bugtool.entries = [bugtool.CAP_PAM] | ||
| bugtool.data = {} | ||
|
|
||
| # Act | ||
| bugtool.cmd_output(bugtool.entries[0], command, label, filter=filter_func) | ||
|
|
||
| # Assert | ||
| assert bugtool.data == { | ||
| label | ||
| or command: { | ||
| "filter": filter_func, | ||
| "cap": bugtool.entries[0], | ||
| "cmd_args": command, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| def test_cmd_output_command(bugtool_fixture): | ||
| """Test how cmd_output() handles a command which can be found""" | ||
|
|
||
| check_cmd_output_data(bugtool_fixture, "pwd --version") | ||
|
|
||
|
|
||
| def test_cmd_output_command_label(bugtool_fixture): | ||
| """Test how cmd_output() handles a command which can be found with a label""" | ||
|
|
||
| check_cmd_output_data(bugtool_fixture, "pwd --version", "label") | ||
|
|
||
|
|
||
| def test_cmd_output_missing_command(bugtool_fixture): | ||
| """Test how cmd_output() handles a missing command""" | ||
|
|
||
| check_cmd_output_data(bugtool_fixture, "/missing-cmd arg") | ||
|
|
||
|
|
||
| def test_cmd_output_missing_command_with_label(bugtool_fixture): | ||
| """Test how cmd_output() handles a missing command with a label""" | ||
|
|
||
| check_cmd_output_data(bugtool_fixture, "/missing-cmd arg", "label") | ||
|
|
||
|
|
||
| def test_cmd_output_multiple_calls(bugtool_fixture): | ||
| """Assert the cumulative effect of multiple cmd_output() calls.""" | ||
|
|
||
| # Prepare | ||
| # | ||
| cap1 = bugtool_fixture.CAP_OEM | ||
| cap2 = bugtool_fixture.CAP_PAM | ||
| bugtool_fixture.entries = [cap1, cap2] | ||
|
|
||
| def mock_filter(): | ||
| """No-op mock filter used in tests for asserting it in bugtool_fixture.data""" | ||
|
|
||
| # Act | ||
| # | ||
| cmd1 = ["/usr/bin/pwd", "--version"] | ||
| cmd2 = ["/missing-cmd", "arg1", "arg2"] | ||
| bugtool_fixture.cmd_output("not_an_activated_capability", cmd1) | ||
| bugtool_fixture.cmd_output(cap1, [cmd1[0]], filter=mock_filter) | ||
| bugtool_fixture.cmd_output(cap1, cmd1) | ||
| bugtool_fixture.cmd_output(cap2, cmd2) | ||
|
|
||
| # Assert | ||
| # | ||
| assert bugtool_fixture.data == { | ||
| "pwd": { | ||
| "cap": cap1, | ||
| "cmd_args": ["/usr/bin/pwd"], | ||
| "filter": mock_filter, | ||
| }, | ||
| # At the moment, we also add commands which are missing on the system to data | ||
| "missing-cmd arg1 arg2": { | ||
| "cap": cap2, | ||
| "cmd_args": cmd2, | ||
| "filter": None, | ||
| }, | ||
| # Uses command as string without path as key when no label is set | ||
| "pwd --version": { | ||
| "cap": cap1, | ||
| "cmd_args": cmd1, | ||
| "filter": None, | ||
| }, | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.