Exemple #1
0
def test_get_config_tuple_from_egrc_when_present():
    """Make sure we extract values correctly from the egrc."""
    # These are the values hardcoded into the files.
    egrc_examples_dir = 'test/example/dir/in/egrc_withdata'
    egrc_custom_dir = 'test/custom/dir/in/egrc_withdata'
    egrc_use_color = True
    egrc_pager_cmd = 'more egrc'
    color_config_from_file = _get_color_config_from_egrc_withdata()

    def return_expanded_path(*args, **kwargs):
        if args[0] == egrc_examples_dir:
            return egrc_examples_dir
        elif args[0] == egrc_custom_dir:
            return egrc_custom_dir
        else:
            raise TypeError(args[0] + ' was an unexpected path--should be ' +
                            egrc_examples_dir + ' or ' + egrc_custom_dir)

    with patch('eg.config.get_expanded_path',
               side_effect=return_expanded_path) as mock_expand:

        actual = config.get_config_tuple_from_egrc('test/assets/egrc_withdata')

        target = config.Config(examples_dir=egrc_examples_dir,
                               custom_dir=egrc_custom_dir,
                               color_config=color_config_from_file,
                               use_color=egrc_use_color,
                               pager_cmd=egrc_pager_cmd)
        assert_equal(actual, target)

        mock_expand.assert_any_call(egrc_examples_dir)
        mock_expand.assert_any_call(egrc_custom_dir)
Exemple #2
0
def test_get_config_tuple_from_egrc_when_present():
    """Make sure we extract values correctly from the egrc."""
    # These are the values hardcoded into the files.
    egrc_examples_dir = 'test/example/dir/in/egrc_withdata'
    egrc_custom_dir = 'test/custom/dir/in/egrc_withdata'
    egrc_use_color = True
    egrc_pager_cmd = 'more egrc'
    color_config_from_file = _get_color_config_from_egrc_withdata()
    egrc_squeeze = True
    # Order matters--we apply substitutions alphabetically.
    egrc_subs = [
        substitute.Substitution(r'    ', r'', False),
        substitute.Substitution('\n\n\n', '\n\n', True)
    ]

    def return_expanded_path(*args, **kwargs):
        if args[0] == egrc_examples_dir:
            return egrc_examples_dir
        elif args[0] == egrc_custom_dir:
            return egrc_custom_dir
        else:
            raise TypeError(
                args[0] +
                ' was an unexpected path--should be ' +
                egrc_examples_dir +
                ' or ' +
                egrc_custom_dir
            )

    with patch(
        'eg.config.get_expanded_path',
        side_effect=return_expanded_path
    ) as mock_expand:

        actual = config.get_config_tuple_from_egrc(PATH_EGRC_WITH_DATA)

        target = config.Config(
            examples_dir=egrc_examples_dir,
            custom_dir=egrc_custom_dir,
            color_config=color_config_from_file,
            use_color=egrc_use_color,
            pager_cmd=egrc_pager_cmd,
            squeeze=egrc_squeeze,
            subs=egrc_subs
        )

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

        mock_expand.assert_any_call(egrc_examples_dir)
        mock_expand.assert_any_call(egrc_custom_dir)
Exemple #3
0
def test_get_config_tuple_from_egrc_when_present(mock_expand):
    """
    Make sure we extract values correctly from the egrc.
    """
    # These are the values hardcoded into the files.
    egrc_examples_dir = 'test/example/dir/in/egrc_withdata'
    egrc_custom_dir = 'test/custom/dir/in/egrc_withdata'
    egrc_use_color = True
    egrc_pager_cmd = 'more egrc'
    egrc_editor_cmd = 'vim egrc'
    color_config_from_file = _get_color_config_from_egrc_withdata()
    egrc_squeeze = True
    # Order matters--we apply substitutions alphabetically.
    egrc_subs = [
        substitute.Substitution(r'    ', r'', False),
        substitute.Substitution('\n\n\n', '\n\n', True)
    ]

    def return_expanded_path(*args, **kwargs):
        if args[0] == egrc_examples_dir:
            return egrc_examples_dir
        elif args[0] == egrc_custom_dir:
            return egrc_custom_dir
        else:
            raise TypeError(
                args[0] +
                ' was an unexpected path--should be ' +
                egrc_examples_dir +
                ' or ' +
                egrc_custom_dir
            )

    mock_expand.side_effect = return_expanded_path

    actual = config.get_config_tuple_from_egrc(PATH_EGRC_WITH_DATA)

    expected = config.Config(
        examples_dir=egrc_examples_dir,
        custom_dir=egrc_custom_dir,
        color_config=color_config_from_file,
        use_color=egrc_use_color,
        pager_cmd=egrc_pager_cmd,
        squeeze=egrc_squeeze,
        subs=egrc_subs,
        editor_cmd=egrc_editor_cmd,
    )

    assert actual == expected

    mock_expand.assert_any_call(egrc_examples_dir)
    mock_expand.assert_any_call(egrc_custom_dir)
Exemple #4
0
def test_get_config_tuple_from_egrc_all_none_when_not_present():
    """
    Return correct data if the egrc has no data.

    We should return None for all values and an empty color_config if there is
    no data in the egrc.
    """
    actual = config.get_config_tuple_from_egrc('test/assets/egrc_nodata')

    empty_color_config = config.get_empty_color_config()

    target = config.Config(examples_dir=None,
                           custom_dir=None,
                           color_config=empty_color_config,
                           use_color=None,
                           pager_cmd=None)
    assert_equal(actual, target)
Exemple #5
0
def test_get_config_tuple_from_egrc_when_present():
    """Make sure we extract values correctly from the egrc."""
    # These are the values hardcoded into the files.
    egrc_examples_dir = 'test/example/dir/in/egrc_withdata'
    egrc_custom_dir = 'test/custom/dir/in/egrc_withdata'
    egrc_use_color = True
    egrc_pager_cmd = 'more egrc'
    color_config_from_file = _get_color_config_from_egrc_withdata()

    def return_expanded_path(*args, **kwargs):
        if args[0] == egrc_examples_dir:
            return egrc_examples_dir
        elif args[0] == egrc_custom_dir:
            return egrc_custom_dir
        else:
            raise TypeError(
                args[0] +
                ' was an unexpected path--should be ' +
                egrc_examples_dir +
                ' or ' +
                egrc_custom_dir
            )

    with patch(
        'eg.config.get_expanded_path',
        side_effect=return_expanded_path
    ) as mock_expand:

        actual = config.get_config_tuple_from_egrc(
            'test/assets/egrc_withdata'
        )

        target = config.Config(
            examples_dir=egrc_examples_dir,
            custom_dir=egrc_custom_dir,
            color_config=color_config_from_file,
            use_color=egrc_use_color,
            pager_cmd=egrc_pager_cmd
        )
        assert_equal(actual, target)

        mock_expand.assert_any_call(egrc_examples_dir)
        mock_expand.assert_any_call(egrc_custom_dir)
Exemple #6
0
def test_get_config_tuple_from_egrc_all_none_when_not_present():
    """
    Return correct data if the egrc has no data.

    We should return None for all values and an empty color_config if there is
    no data in the egrc.
    """
    actual = config.get_config_tuple_from_egrc('test/assets/egrc_nodata')

    empty_color_config = config.get_empty_color_config()

    target = config.Config(
        examples_dir=None,
        custom_dir=None,
        color_config=empty_color_config,
        use_color=None,
        pager_cmd=None
    )
    assert_equal(actual, target)
Exemple #7
0
def test_get_config_tuple_from_egrc_all_none_when_not_present():
    """
    Return correct data if the egrc has no data.

    We should return None for all values and an empty color_config if there is
    no data in the egrc.
    """
    actual = config.get_config_tuple_from_egrc(PATH_EGRC_NO_DATA)

    empty_color_config = config.get_empty_color_config()

    target = config.Config(
        examples_dir=None,
        custom_dir=None,
        color_config=empty_color_config,
        use_color=None,
        pager_cmd=None,
        squeeze=None,
        subs=None,
        editor_cmd=None,
    )
    assert actual == target
Exemple #8
0
def test_get_config_tuple_from_egrc_all_none_when_not_present():
    """
    Return correct data if the egrc has no data.

    We should return None for all values and an empty color_config if there is
    no data in the egrc.
    """
    actual = config.get_config_tuple_from_egrc(PATH_EGRC_NO_DATA)

    empty_color_config = config.get_empty_color_config()

    target = config.Config(
        examples_dir=None,
        custom_dir=None,
        color_config=empty_color_config,
        use_color=None,
        pager_cmd=None,
        squeeze=None,
        subs=None,
        editor_cmd=None,
    )
    assert actual == target