-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Greg Balke <[email protected]> Topic: cli_unit_test_framework Reviewers: jerry-skydio Relative: github_workflow_python_install
- Loading branch information
Showing
2 changed files
with
52 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
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,48 @@ | ||
import asyncio | ||
import builtins | ||
import dataclasses | ||
import io | ||
import sys | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from revup import revup | ||
|
||
|
||
def mock_revup(args, user_input) -> str: | ||
# The first arg is always the program path. | ||
args = ["revup"] + args | ||
|
||
# We want to ensure that no connection to github is established (as we are | ||
# not actually githubbing)! | ||
mock.patch("revup.revup.github_connection") | ||
# User input mocks the user typing things into the terminal. | ||
user_input = list(user_input) if isinstance(user_input, list) else [user_input] | ||
with mock.patch.object(sys, "argv", args): | ||
with mock.patch.object(builtins, "input", lambda x: user_input.pop(0)): | ||
with mock.patch("sys.stdout", new_callable=io.StringIO): | ||
# Ensure we finish main. | ||
loop = asyncio.get_event_loop() | ||
coroutine = revup.main() | ||
loop.run_until_complete(coroutine) | ||
output = sys.stdout.getvalue() | ||
|
||
# This is the stdout output. | ||
return output | ||
|
||
|
||
def test_help_menu(mocker): | ||
# Test the default help menu. | ||
help_action = mocker.patch("revup.revup.HelpAction", wraps=revup.HelpAction) | ||
with pytest.raises(SystemExit): | ||
mock_revup(["-h"], []) | ||
help_action.assert_called() | ||
|
||
# Test the help menu stops code flow where expected. | ||
help_action.reset_mock() | ||
upload_main = mocker.patch("revup.upload.main") | ||
with pytest.raises(SystemExit): | ||
mock_revup(["upload", "-h"], []) | ||
help_action.assert_called() | ||
upload_main.assert_not_called() |