-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for safe completer and utils
- Loading branch information
Showing
5 changed files
with
91 additions
and
5 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
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,29 @@ | ||
import unittest | ||
|
||
from prompt_toolkit.completion import CompleteEvent, Completion | ||
from prompt_toolkit.document import Document | ||
|
||
from safe_cli.safe_completer import SafeCompleter | ||
|
||
|
||
class TestSafeCompleter(unittest.TestCase): | ||
def test_get_completions(self): | ||
safe_completer = SafeCompleter() | ||
|
||
with self.assertRaises(StopIteration): | ||
next( | ||
safe_completer.get_completions( | ||
Document("not-supported-command"), CompleteEvent() | ||
) | ||
) | ||
|
||
self.assertIsInstance( | ||
next( | ||
safe_completer.get_completions(Document("send_ether"), CompleteEvent()) | ||
), | ||
Completion, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,12 @@ | ||
import unittest | ||
|
||
from .safe_cli_test_case_mixin import SafeCliTestCaseMixin | ||
|
||
|
||
class TestSafeCreator(SafeCliTestCaseMixin, unittest.TestCase): | ||
def test_main(self): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,39 @@ | ||
import os | ||
import unittest | ||
from unittest import mock | ||
from unittest.mock import MagicMock | ||
|
||
from safe_cli.utils import yes_or_no_question | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
@mock.patch("safe_cli.utils.get_input") | ||
def test_yes_or_no_question(self, input_mock: MagicMock): | ||
# Input defaults to `yes` if running tests | ||
pytest_current_test = os.environ.pop("PYTEST_CURRENT_TEST") | ||
input_mock.return_value = "yes" | ||
self.assertTrue(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "yay" | ||
self.assertTrue(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "Y" | ||
self.assertTrue(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "Nope" | ||
self.assertFalse(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "No" | ||
self.assertFalse(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "n" | ||
self.assertFalse(yes_or_no_question("")) | ||
|
||
input_mock.return_value = "random" | ||
self.assertFalse(yes_or_no_question("")) | ||
|
||
os.environ["PYTEST_CURRENT_TEST"] = pytest_current_test | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |