コード例 #1
0
ファイル: test_app.py プロジェクト: zennsocial/funky
def test_main(commands, argv, cmd_cls_string):
    """Tests that arguments are parsed correctly."""
    setattr(commands, cmd_cls_string, mock.Mock())
    cmd_class = getattr(commands, cmd_cls_string)
    app.main(argv)

    cmd_class.assert_called_once_with(argv[1:],
                                      color=False,
                                      global_=False,
                                      verbose=False)
    app._CmdAction.flag = None
コード例 #2
0
def test_main(
    commands: mock.MagicMock, argv: List[str], cmd_cls_string: str
) -> None:
    """Tests that arguments are parsed correctly."""
    setattr(commands, cmd_cls_string, mock.Mock())
    cmd_class = getattr(commands, cmd_cls_string)
    app.main(argv)

    cmd_class.assert_called_once_with(
        argv[1:], color=False, global_=False, verbose=False
    )
    app._CmdAction.flag = None  # pylint: disable=protected-access
コード例 #3
0
ファイル: test_shell.py プロジェクト: bbugyi200/funky
def test_init(shell: str, snapshot: Snapshot, capsys: CaptureFixture) -> None:
    """Tests the --init option."""
    exit_code = app.main(["--init", shell])
    assert exit_code == 0

    captured = capsys.readouterr()
    assert captured.out == snapshot
コード例 #4
0
ファイル: test_app.py プロジェクト: zennsocial/funky
def test_main_exceptions(_get_argparser):
    """Tests that main handles exceptions appropriately."""
    class TestError(Exception):
        pass

    def raise_error(opt, verbose=False):
        if opt == 1:
            raise errors.FunkyError(returncode=5)
        elif opt == 2:
            raise TestError('Test Exception')

    _get_argparser.side_effect = functools.partial(raise_error, 1)
    assert app.main() == 5

    _get_argparser.side_effect = functools.partial(raise_error, 2)
    with pytest.raises(TestError):
        app.main()
コード例 #5
0
def test_main_validate_args(logger: mock.MagicMock, argv: List[str]) -> None:
    """Tests that arguments are validated properly."""
    assert app.main(argv) == 2
    logger.error.called_once()
    funky.app._CmdAction.flag = None  # pylint: disable=protected-access
    funky.app._CmdAction.option_string = (
        None  # pylint: disable=protected-access
    )
コード例 #6
0
ファイル: test_shell.py プロジェクト: bbugyi200/funky
def test_setup_shell(shell: str, contents: Optional[str], tmp_home: Path,
                     snapshot: Snapshot) -> None:
    """Tests the --setup-shell option."""
    config_file = tmp_home / SHELL_TO_CONFIG[shell]
    if contents:
        config_file.write_text(contents)

    exit_code = app.main(["--setup-shell", shell])
    assert exit_code == 0

    assert config_file.read_text() == snapshot
コード例 #7
0
def test_main_exceptions(_get_argparser: mock.MagicMock) -> None:
    """Tests that main handles exceptions appropriately."""

    class TestError(Exception):
        pass

    def raise_error(opt: int, verbose: bool = True) -> None:
        del verbose

        if opt == 1:
            raise errors.FunkyError(returncode=5)

        if opt == 2:
            raise TestError("Test Exception")

    _get_argparser.side_effect = functools.partial(raise_error, 1)
    assert app.main() == 5

    _get_argparser.side_effect = functools.partial(raise_error, 2)
    with pytest.raises(TestError):
        app.main()
コード例 #8
0
import os
import sys

this_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, this_dir)

from funky import app  # noqa

if __name__ == "__main__":
    sys.exit(app.main())
コード例 #9
0
ファイル: test_app.py プロジェクト: zennsocial/funky
def test_main_validate_args(logger, argv):
    """Tests that arguments are validated properly."""
    assert app.main(argv) == 2
    logger.error.called_once()
    funky.app._CmdAction.flag = None
    funky.app._CmdAction.option_string = None