示例#1
0
文件: core.py 项目: ioncodes/eg
def run_eg():
    args = _parse_arguments()

    resolved_config = config.get_resolved_config(
        egrc_path=args.config_file,
        examples_dir=args.examples_dir,
        custom_dir=args.custom_dir,
        use_color=args.use_color,
        pager_cmd=args.pager_cmd,
        squeeze=args.squeeze)

    if args.list:
        _show_list_message(resolved_config)
    elif args.version:
        _show_version()
    elif args.edit:
        if not resolved_config.editor_cmd:
            _handle_no_editor()
        else:
            util.edit_custom_examples(args.program, resolved_config)
    elif args.labels:
        _show_labels(args.program)
    elif args.add_label:
        _add_label(args.program, args.add_label)
    elif args.find_file:
        _find_file(args.find_file)
    elif args.remove_label:
        _remove_label(args.program, args.remove_label)
    else:
        util.handle_program(args.program, resolved_config)
示例#2
0
def test_config_returns_egrc_values_if_present(mock_get_config, mock_isfile):
    """
    If values are present from an egrc, make sure we take them.

    Doesn't make sure they are extracted correctly from an egrc file.
    """
    examples_dir = 'test_eg_dir_from_egrc'
    custom_dir = 'test_custom_dir_from_egrc'
    test_color_config = _get_color_config_from_egrc_withdata()
    test_use_color = True
    test_pager_cmd = 'more baby'
    test_editor_cmd = 'vim is the best'
    test_squeeze = True
    test_subs = ['alpha', 'beta']

    def_config = config.Config(
        examples_dir=examples_dir,
        custom_dir=custom_dir,
        color_config=test_color_config,
        use_color=test_use_color,
        pager_cmd=test_pager_cmd,
        editor_cmd=test_editor_cmd,
        squeeze=test_squeeze,
        subs=test_subs,
    )

    mock_get_config.return_value = def_config

    resolved_config = config.get_resolved_config(
        None,
        None,
        None,
        None,
        None,
        None,
    )

    assert_equal(resolved_config.examples_dir, examples_dir)
    assert_equal(resolved_config.custom_dir, custom_dir)
    assert_equal(resolved_config.color_config, test_color_config)
    assert_equal(resolved_config.use_color, test_use_color)
    assert_equal(resolved_config.pager_cmd, test_pager_cmd)
    assert_equal(resolved_config.editor_cmd, test_editor_cmd)
    assert_equal(resolved_config.squeeze, test_squeeze)
    assert_equal(resolved_config.subs, test_subs)
示例#3
0
文件: config_test.py 项目: NaWer/eg
def test_config_returns_egrc_values_if_present(mock_get_config, mock_isfile):
    """
    If values are present from an egrc, make sure we take them.

    Doesn't make sure they are extracted correctly from an egrc file.
    """
    examples_dir = 'test_eg_dir_from_egrc'
    custom_dir = 'test_custom_dir_from_egrc'
    test_color_config = _get_color_config_from_egrc_withdata()
    test_use_color = True
    test_pager_cmd = 'more baby'
    test_editor_cmd = 'vim is the best'
    test_squeeze = True
    test_subs = ['alpha', 'beta']

    def_config = config.Config(
        examples_dir=examples_dir,
        custom_dir=custom_dir,
        color_config=test_color_config,
        use_color=test_use_color,
        pager_cmd=test_pager_cmd,
        editor_cmd=test_editor_cmd,
        squeeze=test_squeeze,
        subs=test_subs,
    )

    mock_get_config.return_value = def_config

    resolved_config = config.get_resolved_config(
        None,
        None,
        None,
        None,
        None,
        None,
    )

    assert_equal(resolved_config.examples_dir, examples_dir)
    assert_equal(resolved_config.custom_dir, custom_dir)
    assert_equal(resolved_config.color_config, test_color_config)
    assert_equal(resolved_config.use_color, test_use_color)
    assert_equal(resolved_config.pager_cmd, test_pager_cmd)
    assert_equal(resolved_config.editor_cmd, test_editor_cmd)
    assert_equal(resolved_config.squeeze, test_squeeze)
    assert_equal(resolved_config.subs, test_subs)
示例#4
0
def _assert_about_get_resolved_config(
    mock_get_egrc_config,
    mock_inform,
    mock_get_editor,
    cli_egrc_path=None,
    cli_examples_dir=None,
    cli_custom_dir=None,
    cli_use_color=None,
    cli_pager_cmd=None,
    cli_squeeze=None,
    egrc_config=None,
    environment_editor_cmd=None,
    expected_config=None,
):
    """
    Helper for assertions surrounding get_resolved_config.
    """
    mock_get_egrc_config.return_value = expected_config
    mock_get_editor.return_value = environment_editor_cmd

    actual = config.get_resolved_config(
        cli_egrc_path,
        cli_examples_dir,
        cli_custom_dir,
        cli_use_color,
        cli_pager_cmd,
        cli_squeeze,
        debug=False
    )

    assert actual.examples_dir == expected_config.examples_dir
    assert actual.custom_dir == expected_config.custom_dir
    assert actual.use_color == expected_config.use_color
    assert actual.color_config == expected_config.color_config
    assert actual.pager_cmd == expected_config.pager_cmd
    assert actual.squeeze == expected_config.squeeze
    assert actual.subs == expected_config.subs
    assert actual.editor_cmd == expected_config.editor_cmd

    mock_get_egrc_config.assert_called_once_with(cli_egrc_path)
    mock_get_editor.assert_called_once_with()
示例#5
0
文件: config_test.py 项目: NaWer/eg
def _assert_about_get_resolved_config(
    mock_get_egrc_config,
    mock_inform,
    mock_get_editor,
    cli_egrc_path=None,
    cli_examples_dir=None,
    cli_custom_dir=None,
    cli_use_color=None,
    cli_pager_cmd=None,
    cli_squeeze=None,
    egrc_config=None,
    environment_editor_cmd=None,
    expected_config=None,
):
    """
    Helper for assertions surrounding get_resolved_config.
    """
    mock_get_egrc_config.return_value = expected_config
    mock_get_editor.return_value = environment_editor_cmd

    actual = config.get_resolved_config(
        cli_egrc_path,
        cli_examples_dir,
        cli_custom_dir,
        cli_use_color,
        cli_pager_cmd,
        cli_squeeze,
        debug=False
    )

    assert_equal(actual.examples_dir, expected_config.examples_dir)
    assert_equal(actual.custom_dir, expected_config.custom_dir)
    assert_equal(actual.use_color, expected_config.use_color)
    assert_equal(actual.color_config, expected_config.color_config)
    assert_equal(actual.pager_cmd, expected_config.pager_cmd)
    assert_equal(actual.squeeze, expected_config.squeeze)
    assert_equal(actual.subs, expected_config.subs)
    assert_equal(actual.editor_cmd, expected_config.editor_cmd)

    mock_get_egrc_config.assert_called_once_with(cli_egrc_path)
    mock_get_editor.assert_called_once_with()
示例#6
0
def _call_get_resolved_config_with_defaults(
    egrc_path=None,
    examples_dir=None,
    custom_dir=None,
    use_color=None,
    pager_cmd=None,
    squeeze=None,
    debug=False,
):
    """
    Wraps config.get_resolved_config_items with default values to allow callers
    to set fewer variables.
    """
    return config.get_resolved_config(
        egrc_path=egrc_path,
        examples_dir=examples_dir,
        custom_dir=custom_dir,
        use_color=use_color,
        pager_cmd=pager_cmd,
        squeeze=squeeze,
        debug=debug,
    )
示例#7
0
文件: config_test.py 项目: NaWer/eg
def _call_get_resolved_config_with_defaults(
    egrc_path=None,
    examples_dir=None,
    custom_dir=None,
    use_color=None,
    pager_cmd=None,
    squeeze=None,
    debug=False,
):
    """
    Wraps config.get_resolved_config_items with default values to allow callers
    to set fewer variables.
    """
    return config.get_resolved_config(
        egrc_path=egrc_path,
        examples_dir=examples_dir,
        custom_dir=custom_dir,
        use_color=use_color,
        pager_cmd=pager_cmd,
        squeeze=squeeze,
        debug=debug,
    )
示例#8
0
文件: core.py 项目: NaWer/eg
def run_eg():
    args = _parse_arguments()

    resolved_config = config.get_resolved_config(
        egrc_path=args.config_file,
        examples_dir=args.examples_dir,
        custom_dir=args.custom_dir,
        use_color=args.use_color,
        pager_cmd=args.pager_cmd,
        squeeze=args.squeeze
    )

    if args.list:
        _show_list_message(resolved_config)
    elif args.version:
        _show_version()
    elif args.edit:
        if not resolved_config.editor_cmd:
            _handle_no_editor()
        else:
            util.edit_custom_examples(args.program, resolved_config)
    else:
        util.handle_program(args.program, resolved_config)