File size: 1,546 Bytes
b93364a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
"""Test the choices controller."""
from argparse import ArgumentParser
from unittest.mock import patch
import pytest
from openbb_cli.controllers.choices import (
build_controller_choice_map,
)
# pylint: disable=redefined-outer-name, protected-access, unused-argument, unused-variable
class MockController:
"""Mock controller class for testing."""
CHOICES_COMMANDS = ["test_command"]
controller_choices = ["test_command", "help"]
def call_test_command(self, args):
"""Mock function for test_command."""
parser = ArgumentParser()
parser.add_argument(
"--example", choices=["option1", "option2"], help="Example argument."
)
return parser.parse_args(args)
@pytest.fixture
def mock_controller():
"""Mock controller fixture."""
return MockController()
def test_build_command_choice_map(mock_controller):
"""Test the building of a command choice map."""
with patch(
"openbb_cli.controllers.choices._get_argument_parser"
) as mock_get_parser:
parser = ArgumentParser()
parser.add_argument(
"--option", choices=["opt1", "opt2"], help="A choice option."
)
mock_get_parser.return_value = parser
choice_map = build_controller_choice_map(controller=mock_controller)
assert "test_command" in choice_map
assert "--option" in choice_map["test_command"]
assert "opt1" in choice_map["test_command"]["--option"]
assert "opt2" in choice_map["test_command"]["--option"]
|