def test_validate_basic_content(settings):
    """Validate a basic valid input"""
    source = """Lorem **ipsum** salace"""

    renderer = RstExtendedRenderer()
    renderer.parse(source)

    assert renderer.is_valid() == True

    assert renderer.messages == []
def test_validate_invalid_syntax(settings, capsys):
    """Validate a basic invalid input"""
    source = """Lorem **ipsum salace"""

    renderer = RstExtendedRenderer()
    renderer.parse(source)

    out, err = capsys.readouterr()

    assert renderer.is_valid() == False

    # Ensure parser is totally silent
    assert out == ""
    assert err == ""

    assert renderer.messages == [
        (1, 2, 'Inline strong start-string without end-string.'),
    ]
def test_validate_invalid2_syntax_formatted(settings, capsys):
    """Validate another basic invalid input but with formatted messages"""
    input_filepath = os.path.join(settings.TESTS_FIXTURES_DIR, "invalid-2/input.rst")
    with open(input_filepath, 'r') as fp:
        source = fp.read()

    renderer = RstExtendedRenderer()
    renderer.parse(source)

    out, err = capsys.readouterr()

    assert renderer.is_valid() == False

    # Ensure parser is totally silent
    assert out == ""
    assert err == ""

    assert renderer.get_messages() == [
        u'Line 1 : Inline strong start-string without end-string.',
        u'Line 8 : Inline strong start-string without end-string.',
        u'Line 8 : Inline strong start-string without end-string.',
        u'Line 8 : Inline emphasis start-string without end-string.',
        u'Line 31 : Inline literal start-string without end-string.'
    ]
Beispiel #4
0
def rst_render(source, *args, **kwargs):
    """
    Parse and render given string using a parser configuration.

    Examples:

        Basic usage: ::

            {% load rstview_tags %}

            {% rst_render SOURCE_STRING %}

        Using a specific config set: ::

            {% load rstview_tags %}

            {% rst_render SOURCE_STRING config='myconfig' %}

        Muting error and warning from parser: ::

            {% load rstview_tags %}

            {% rst_render SOURCE_STRING silent=True %}

        Everything joined: ::

            {% load rstview_tags %}

            {% rst_render SOURCE_STRING config='myconfig' silent=True %}

        Tag signature: ::

            {% rst_render SOURCE_STRING [config='default'] [silent=True] %}


    Args:
        source (string): reStructuredText markup to parse.

    Keyword Arguments:
        config (string): Name of an option set from
            ``settings.RSTVIEW_PARSER_FILTER_SETTINGS``.
        silent (bool): Enable to override default *silent mode* behavior.
            Default value is the same as ``settings.RSTVIEW_PARSER_SILENT``.

    Returns:
        string: Rendered source from parser.
    """  # noqa: E501
    config_name = kwargs.get('config', 'default')
    silent = kwargs.get('silent', settings.RSTVIEW_PARSER_SILENT)
    parser = RstExtendedRenderer()

    # ``body_only`` is enforced to True else tag would return a dict of values
    # serialized to a string.
    return mark_safe(
        parser.parse(
            source,
            setting_key=config_name,
            body_only=True,
            silent=silent,
        )
    )