-
Notifications
You must be signed in to change notification settings - Fork 6
Update unittests #67
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
Merged
Update unittests #67
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9941ca0
Fallback to PATH when discovering hap executable
bmwant bbeec0b
Add tail_lines util function
bmwant 0099049
Fix typechecks for tests directory
bmwant 4a7e389
Add ty badge
bmwant d781eed
Add tests module for cli utils testing
bmwant b8c0236
Add tests for get_or_exit function
bmwant 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
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
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,38 @@ | ||
| from unittest.mock import Mock, PropertyMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from hapless.cli_utils import get_or_exit | ||
|
|
||
|
|
||
| @patch("hapless.cli_utils.hapless") | ||
| def test_get_or_exit_non_existing(hapless_mock, capsys): | ||
| with patch.object(hapless_mock, "get_hap", return_value=None) as get_hap_mock: | ||
| with pytest.raises(SystemExit) as e: | ||
| get_or_exit("hap-me") | ||
|
|
||
| assert e.value.code == 1 | ||
| get_hap_mock.assert_called_once_with("hap-me") | ||
|
|
||
| captured = capsys.readouterr() | ||
| assert "No such hap: hap-me" in captured.out | ||
|
|
||
|
|
||
| @patch("hapless.cli_utils.hapless") | ||
| def test_get_or_exit_not_accessible(hapless_mock, capsys): | ||
| hap_mock = Mock(owner="someone-else") | ||
| prop_mock = PropertyMock(return_value=False) | ||
| type(hap_mock).accessible = prop_mock | ||
| with patch.object(hapless_mock, "get_hap", return_value=hap_mock) as get_hap_mock: | ||
| with pytest.raises(SystemExit) as e: | ||
| get_or_exit("hap-not-mine") | ||
|
|
||
| assert e.value.code == 1 | ||
| get_hap_mock.assert_called_once_with("hap-not-mine") | ||
| prop_mock.assert_called_once_with() | ||
|
|
||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "Cannot manage hap launched by another user. Owner: someone-else" | ||
| in captured.out | ||
| ) |
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
Oops, something went wrong.
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.
The type ignore comment contains a typo. It should be
type: ignoreinstead ofty: ignore.