Пример #1
0
def test_item_with_newlines_at_the_beginning(testapp):
    """Markdown processor has to ignore newlines at the beginning."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\


                        # some title

                        text with **bold**
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>text with <strong>bold</strong></p>"),
            "destination":
            pathlib.Path("1.html"),
            "title":
            "some title",
        })
    ]
Пример #2
0
def test_item_with_table(testapp):
    """Markdown processor has to support table syntax (markup extension)."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        column a | column b
                        ---------|---------
                           foo   |   bar
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)

    stream = list(stream)
    assert stream == [
        holocron.Item({
            "content": unittest.mock.ANY,
            "destination": pathlib.Path("1.html"),
        })
    ]

    item = stream[0]
    assert "table" in item["content"]
    assert "<th>column a</th>" in item["content"]
    assert "<th>column b</th>" in item["content"]
    assert "<td>foo</td>" in item["content"]
    assert "<td>bar</td>" in item["content"]
Пример #3
0
def test_item_with_alt_title_syntax(testapp):
    """Markdown processor has to work with alternative title syntax."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        some title
                        ==========

                        text with **bold**
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>text with <strong>bold</strong></p>"),
            "destination":
            pathlib.Path("1.html"),
            "title":
            "some title",
        })
    ]
Пример #4
0
def test_args_extensions(testapp, extensions, rendered):
    """Markdown processor has to respect extensions argument."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        test codeblock

                            :::
                            lambda x: pass
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
        extensions=extensions,
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": _pytest_regex(rendered),
            "destination": pathlib.Path("1.html"),
        })
    ]
Пример #5
0
def test_item_with_inline_code(testapp):
    """Markdown processor has to use <code> for inline code."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        test `code`
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>test <code>code</code></p>"),
            "destination":
            pathlib.Path("1.html"),
        })
    ]
Пример #6
0
def test_item_with_fenced_code(testapp):
    """Markdown processor has to support GitHub"s fence code syntax."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        test codeblock

                        ```python
                        lambda x: pass
                        ```
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>test codeblock</p>\s*.*highlight.*"
                          r"<pre>[\s\S]+</pre>.*"),
            "destination":
            pathlib.Path("1.html"),
        })
    ]
Пример #7
0
def test_item_title_ignored_in_the_middle_of_text(testapp):
    """Markdown processor has to ignore title if it"s in the middle of text."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        text

                        # some title

                        text with **bold**
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>text</p>\s*"
                          r"<h1>some title</h1>\s*"
                          r"<p>text with <strong>bold</strong></p>"),
            "destination":
            pathlib.Path("1.html"),
        })
    ]
Пример #8
0
def test_item_title_is_not_overwritten(testapp):
    """Markdown processor hasn"t to set title if it"s already set."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        # some title

                        text with **bold**
                    """),
                "destination":
                pathlib.Path("1.md"),
                "title":
                "another title",
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>text with <strong>bold</strong></p>"),
            "destination":
            pathlib.Path("1.html"),
            "title":
            "another title",
        })
    ]
Пример #9
0
def test_item_without_title(testapp):
    """Markdown processor has to work process items without title."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        text with **bold**
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>text with <strong>bold</strong></p>"),
            "destination":
            pathlib.Path("1.html"),
        })
    ]
Пример #10
0
def test_item_with_sections(testapp):
    """Markdown processor has to work even for complex items."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content":
                textwrap.dedent("""\
                        some title 1
                        ============

                        aaa

                        some section 1
                        --------------

                        bbb

                        some section 2
                        --------------

                        ccc

                        # some title 2

                        xxx

                        ## some section 3

                        yyy
                    """),
                "destination":
                pathlib.Path("1.md"),
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content":
            _pytest_regex(r"<p>aaa</p>\s*"
                          r"<h2>some section 1</h2>\s*<p>bbb</p>\s*"
                          r"<h2>some section 2</h2>\s*<p>ccc</p>\s*"
                          r"<h1>some title 2</h1>\s*<p>xxx</p>\s*"
                          r"<h2>some section 3</h2>\s*<p>yyy</p>\s*"),
            "destination":
            pathlib.Path("1.html"),
            "title":
            "some title 1",
        })
    ]
Пример #11
0
def test_item_many(testapp, amount):
    """Markdown processor has to work with stream."""

    stream = markdown.process(
        testapp,
        [
            holocron.Item({
                "content": "the key is **%d**" % i,
                "destination": pathlib.Path("1.md"),
            }) for i in range(amount)
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": "<p>the key is <strong>%d</strong></p>" % i,
            "destination": pathlib.Path("1.html"),
        }) for i in range(amount)
    ]
Пример #12
0
def test_args_bad_value(testapp, args, error):
    """Markdown processor has to validate input arguments."""

    with pytest.raises(ValueError) as excinfo:
        next(markdown.process(testapp, [], **args))
    assert str(excinfo.value) == error