Exemple #1
0
def test_parse_config(
        path_dict: typing.Dict[str, typing.Any],
        expected: typing.Any) -> None:
    """Parse a nominal configuration

    Arguments:
        path_dict {typing.Dict[str, typing.Any]} --
            arguments for Parser initialization
        expected {typing.Any} -- idiom config or exception
    """
    path_kwargs = {'root': BUILTIN, 'idiom': DEFAULT_IDIOM}
    path_kwargs.update(path_dict)
    cfg_path = get_config_path(**path_kwargs)

    try:
        ideal, language, stop_words = parse_config(cfg_path)
        received = (ideal, language, len(stop_words))

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)

    assert (received == expected), assert_ex(
        'parse config',
        received,
        expected)
Exemple #2
0
def test_load_json(path: PathOrString, expected) -> None:
    """Test `load_json`

    Arguments:
        path {PathOrString} -- path to document
    """
    try:
        received = load_json(path)

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)

    assert received == expected
def test_score_keyword(count: int, total: int,
                       expected: typing.Union[float, Exception]):
    """Test score_keyword in parser subpackage

    Arguments:
        count {int} -- instances of word in text
        total {int} -- total number of words in text
        expected {typing.Union[float, Exception]} -- expected outcome
    """
    try:
        received = score_keyword(count, total)

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)

    assert received == expected
Exemple #4
0
def test_calc_decile(index: int, total: int,
                     expected: typing.Union[int, Exception]):
    """Test `calc_decile` in summarizer subpackage

    Arguments:
        index {int} -- index of sentence position (0-based)
        total {int} -- total number of sentences
        expected {typing.Union[int, Exception]} --
            decile of position (0-9) or error
    """
    try:
        received = calc_decile(index, total)

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)

    assert received == expected
Exemple #5
0
def test_score_position(index: int, expected: typing.Union[float, Exception]):
    """Test `score_position` in summarizer subpackage

    Arguments:
        index {int} -- index of sentence position (0-based)
        expected {typing.Union[float, Exception]} -- position score or error
    """
    total = 1000

    try:
        received = score_position(index, total)
        test = kinda.eq(received, expected)

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)
        test = (received == expected)

    assert test
Exemple #6
0
def _test_read(func: typing.Callable, path: PathOrString, expected) -> bool:
    """Test an I/O reading function

    Arguments:
        func {typing.Callable} -- oolongt.io function
        path {PathOrString} -- path to document
        expected {typing.Any} -- contents of document or exception

    Returns:
        bool -- result is expected
    """
    try:
        received = func(path).strip()

    except Exception as err:  # pylint: disable=broad-except
        received = check_exception(err, expected)

    return received == expected
Exemple #7
0
def test_load_idiom(
        kwargs: typing.Dict[str, typing.Any],
        expected: typing.Tuple[int, str, int]) -> None:
    """Test `load_idiom` for ParserConfig

    Arguments:
        kwargs {typing.Dict[str, typing.Any]} -- kwargs passed to Parser
        expected {typing.Tuple[int, str, int]} -- expected data
    """
    test = False

    try:
        received = load_idiom(**kwargs)
        test = compare_loaded_idiom(received, expected)

    # pylint: disable=broad-except
    except (PermissionError, FileNotFoundError, ValueError) as err:
        test = check_exception(err, expected) is not None
    # pylint: enable=broad-except

    assert test, assert_ex('config', received, expected)
Exemple #8
0
def test_get_slice_length(
        nominal: typing.Any,
        total: int,
        expected: typing.Any) -> None:
    """Test `get_slice_length` in text subpackage

    Arguments:
        nominal {float} -- exact number (int) or percentage (0 < nominal < 1)
        total {int} -- number of items to slice from
        expected {typing.Any} -- expected Exception/number of items
    """
    try:
        received = get_slice_length(nominal, total)

    except ValueError as err:
        received = check_exception(err, expected)

    assert (expected == received), assert_ex(
        'slice length',
        received,
        expected,
        hint='nominal: {!r}'.format(nominal))