Esempio n. 1
0
def _helper_assert_path_isfile_not_present(config, program,
                                           file_path_for_program,
                                           defaultOrCustom, isfile, has_entry):
    """
    Helper for asserting whether or not a default file is present. Pass in the
    parameters defining the program and directories and say whether or not that
    file should be found.
    """
    if defaultOrCustom != 'default' and defaultOrCustom != 'custom':
        raise TypeError('defaultOrCustom must be default or custom, not ' +
                        defaultOrCustom)
    with patch('eg.util.get_file_path_for_program',
               return_value=file_path_for_program) as mock_get_path:
        with patch('os.path.isfile', return_value=isfile) as mock_isfile:

            actual = None
            correct_dir = None

            if (defaultOrCustom == 'default'):
                correct_dir = config.examples_dir
                actual = util.has_default_entry_for_program(program, config)
            else:
                correct_dir = config.custom_dir
                actual = util.has_custom_entry_for_program(program, config)

            mock_get_path.assert_called_once_with(program, correct_dir)
            mock_isfile.assert_called_once_with(file_path_for_program)

            assert_equal(actual, has_entry)
Esempio n. 2
0
def test_has_custom_entry_for_program_no_custom_dir():
    test_config = _create_config(
        examples_dir='examplesdir',
        custom_dir=None,
    )

    program = 'find'

    has_entry = util.has_custom_entry_for_program(program, test_config)

    assert_equal(False, has_entry)
Esempio n. 3
0
def test_has_custom_entry_for_program_no_custom_dir():
    test_config = config.Config(examples_dir='examplesdir',
                                custom_dir=None,
                                color_config=None,
                                use_color=False,
                                pager_cmd=None)

    program = 'find'

    has_entry = util.has_custom_entry_for_program(program, test_config)

    assert_equal(False, has_entry)
Esempio n. 4
0
def test_has_custom_entry_for_program_no_custom_dir():
    test_config = config.Config(
        examples_dir='examplesdir',
        custom_dir=None,
        color_config=None,
        use_color=False,
        pager_cmd=None,
        squeeze=False,
        subs=None
    )

    program = 'find'

    has_entry = util.has_custom_entry_for_program(program, test_config)

    assert_equal(False, has_entry)
Esempio n. 5
0
def _helper_assert_path_isfile_not_present(
        config,
        program,
        file_path_for_program,
        defaultOrCustom,
        isfile,
        has_entry
):
    """
    Helper for asserting whether or not a default file is present. Pass in the
    parameters defining the program and directories and say whether or not that
    file should be found.
    """
    if defaultOrCustom != 'default' and defaultOrCustom != 'custom':
        raise TypeError(
            'defaultOrCustom must be default or custom, not ' + defaultOrCustom
        )
    with patch(
        'eg.util.get_file_path_for_program',
        return_value=file_path_for_program
    ) as mock_get_path:
        with patch('os.path.isfile', return_value=isfile) as mock_isfile:

            actual = None
            correct_dir = None

            if (defaultOrCustom == 'default'):
                correct_dir = config.examples_dir
                actual = util.has_default_entry_for_program(program, config)
            else:
                correct_dir = config.custom_dir
                actual = util.has_custom_entry_for_program(program, config)

            mock_get_path.assert_called_once_with(program, correct_dir)
            mock_isfile.assert_called_once_with(file_path_for_program)

            assert_equal(actual, has_entry)