def test_args_pygmentize_unknown_language(testapp, language): """Commonmark has to assume text/plain for unknown languages.""" stream = commonmark.process( testapp, [ holocron.Item({ "content": textwrap.dedent(f""" test codeblock ```{language} lambda x: pass ``` """), "destination": pathlib.Path("1.md"), }) ], pygmentize=True, ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": (f"<p>test codeblock</p>\n" f'<pre><code class="language-{language}">' f"lambda x: pass\n</code></pre>"), "destination": pathlib.Path("1.html"), }) ]
def test_item(testapp): """reStructuredText processor has to work in simple case.""" stream = restructuredtext.process( testapp, [ holocron.Item( { "content": textwrap.dedent( """\ some title ========== text with **bold** """ ), "destination": pathlib.Path("1.rst"), } ) ], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item( { "content": _pytest_regex( r"<p>text with <strong>bold</strong></p>\s*" ), "destination": pathlib.Path("1.html"), "title": "some title", } ) ]
def test_item_processor_with_args(testapp): """Pipe processor has to pass down processors arguments.""" stream = pipe.process( testapp, [holocron.Item({ "content": "the Force", "author": "skywalker" })], pipe=[{ "name": "spam", "args": { "text": 1 } }], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the Force", "author": "skywalker", "spam": 1 }) ]
def test_args_todatetime(testapp, timestamp): """Todatetime processor has to respect "writeto" argument.""" stream = todatetime.process( testapp, [ holocron.Item({ "content": "the Force is strong with this one", "timestamp": timestamp, }) ], todatetime=["timestamp", "published"], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the Force is strong with this one", "timestamp": timestamp, "published": datetime.datetime(2019, 1, 11, 0, 0, 0, tzinfo=_TZ_UTC), }) ]
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"), }) ]
def test_item(testapp, frontsnippet): """Frontmatter has to be processed and removed from the content.""" stream = frontmatter.process( testapp, [ holocron.Item( { "content": textwrap.dedent( """\ --- %s --- May the Force be with you! """ ) % textwrap.dedent(frontsnippet) } ) ], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item( { "content": "May the Force be with you!\n", "author": "Yoda", "master": True, "labels": ["force", "motto"], } ) ]
def test_item(testapp): """Pipe processor has to work!""" stream = pipe.process( testapp, [holocron.Item({ "content": "the Force", "author": "skywalker" })], pipe=[{ "name": "spam" }, { "name": "eggs" }, { "name": "rice" }], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the Force #friedeggs", "author": "skywalker", "spam": 42, }), holocron.Item({"content": "rice"}), ]
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"), }) ]
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", }) ]
def test_args_save_as(testapp, save_as): """Archive processor has to respect 'save_as' argument.""" stream = archive.process( testapp, [holocron.Item({ "title": "The Force", "content": "Obi-Wan" })], save_as=str(save_as), ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "title": "The Force", "content": "Obi-Wan" }), holocron.WebSiteItem({ "source": pathlib.Path("archive://", save_as), "destination": save_as, "template": "archive.j2", "items": [holocron.Item({ "title": "The Force", "content": "Obi-Wan" })], "baseurl": testapp.metadata["url"], }), ]
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"), }) ]
def test_args_condition_positional(testapp, cond): """When processor has to respect conditions.""" stream = when.process( testapp, [ holocron.Item({ "content": "eh", "author": "yoda", "source": pathlib.Path("about", "index.md"), }), holocron.Item({ "author": "luke", "source": pathlib.Path("me.rst") }), ], {"name": "spam"}, *cond, ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "eh", "author": "yoda", "source": pathlib.Path("about", "index.md"), "spam": 42, }), holocron.Item({ "author": "luke", "source": pathlib.Path("me.rst") }), ]
def test_item_many_spam(testapp, amount): """When processor has to work with a stream.""" stream = when.process( testapp, [ holocron.Item({ "content": "the great jedi", "key": i }) for i in range(amount) ], processor={"name": "spam"}, condition=["item.key % 2 == 0"], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the great jedi", "key": i }) if i % 2 else holocron.Item({ "content": "the great jedi", "key": i, "spam": 42 }) for i in range(amount) ]
def test_item_many_eggs(testapp): """When processor has to work with complex processor.""" stream = when.process( testapp, [ holocron.Item({ "content": "the great jedi", "key": i }) for i in range(5) ], processor={"name": "eggs"}, condition=["item.key % 2 != 0"], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the great jedi", "key": 0 }), holocron.Item({ "content": "the great jedi", "key": 2 }), holocron.Item({"key": 4}), holocron.Item({ "content": "the great jedi", "key": 4 }), ]
def test_item_many_rice(testapp, amount): """When processor has to work with a processor that populates a stream.""" stream = when.process( testapp, [ holocron.Item({ "content": "the great jedi", "key": i }) for i in range(amount) ], processor={"name": "rice"}, condition=["item.key % 2 == 0"], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == list( itertools.chain( [ holocron.Item({ "content": "the great jedi", "key": i }) for i in range(amount) ], [holocron.Item({"content": "rice"})], ))
def test_args_parsearea(testapp, timestamp, parsearea): """Todatetime processor has to respect "parsearea" argument.""" stream = todatetime.process( testapp, [ holocron.Item({ "content": "the Force is strong with this one", "timestamp": timestamp, }) ], todatetime="timestamp", parsearea=parsearea, fuzzy=True, ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the Force is strong with this one", "timestamp": datetime.datetime(2019, 1, 11, tzinfo=_TZ_UTC), }) ]
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", }) ]
def test_item_many(testapp, amount): """Archive processor has to work with stream.""" stream = archive.process( testapp, [ holocron.Item({"title": "The Force (part #%d)" % i}) for i in range(amount) ], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == list( itertools.chain( [ holocron.Item({"title": "The Force (part #%d)" % i}) for i in range(amount) ], [ holocron.WebSiteItem({ "source": pathlib.Path("archive://index.html"), "destination": pathlib.Path("index.html"), "template": "archive.j2", "items": [ holocron.Item({"title": "The Force (part #%d)" % i}) for i in range(amount) ], "baseurl": testapp.metadata["url"], }) ], ))
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"), }) ]
def test_args_template(testapp): """Archive processor has respect 'template' argument.""" stream = archive.process( testapp, [holocron.Item({ "title": "The Force", "content": "Obi-Wan" })], template="foobar.txt", ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "title": "The Force", "content": "Obi-Wan" }), holocron.WebSiteItem({ "source": pathlib.Path("archive://index.html"), "destination": pathlib.Path("index.html"), "template": "foobar.txt", "items": [holocron.Item({ "title": "The Force", "content": "Obi-Wan" })], "baseurl": testapp.metadata["url"], }), ]
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"]
def test_item_many(testapp, monkeypatch, tmpdir, amount): """Save processor has to work with a stream of items.""" monkeypatch.chdir(tmpdir) stream = save.process( testapp, [ holocron.Item({ "content": "Obi-Wan", "destination": pathlib.Path(str(i)) }) for i in range(amount) ], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "Obi-Wan", "destination": pathlib.Path(str(i)) }) for i in range(amount) ] for i in range(amount): assert tmpdir.join("_site", str(i)).read_text("UTF-8") == "Obi-Wan"
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"), }) ]
def test_item_with_code(testapp): """reStructuredText processor has to highlight code with Pygments.""" stream = restructuredtext.process( testapp, [ holocron.Item( { "content": textwrap.dedent( """\ test codeblock .. code:: python lambda x: pass """ ), "destination": pathlib.Path("1.rst"), } ) ], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item( { "content": _pytest_regex( r"<p>test codeblock</p>\s*<pre.*python[^>]*>[\s\S]+</pre>" ), "destination": pathlib.Path("1.html"), } ) ]
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", }) ]
def test_args_pygmentize(testapp, rendered, pygmentize): """Commonmark processor has to pygmentize code with language.""" stream = commonmark.process( testapp, [ holocron.Item({ "content": textwrap.dedent(""" test codeblock ```python lambda x: pass ``` """), "destination": pathlib.Path("1.md"), }) ], pygmentize=pygmentize, ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": _pytest_regex(rendered), "destination": pathlib.Path("1.html"), }) ]
def test_item_many(testapp, amount): """Pipe processor has to work with stream.""" stream = pipe.process( testapp, [ holocron.Item({ "content": "the Force (%d)" % i, "author": "skywalker" }) for i in range(amount) ], pipe=[{ "name": "spam" }, { "name": "eggs" }], ) assert isinstance(stream, collections.abc.Iterable) assert list(stream) == [ holocron.Item({ "content": "the Force (%d) #friedeggs" % i, "author": "skywalker", "spam": 42, }) for i in range(amount) ]
def test_item_many(testapp, amount): """reStructuredText processor has to work with stream.""" stream = restructuredtext.process( testapp, [ holocron.Item( { "content": "the key is **%d**" % i, "destination": pathlib.Path("1.rst"), } ) 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) ]
def test_item_parsed_title_ignored(testapp): """Commonmark processor has to ignore a title if it's already set.""" stream = commonmark.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": "<p>text with <strong>bold</strong></p>", "destination": pathlib.Path("1.html"), "title": "another title", }) ]
def test_item_init_mapping_kwargs(): """Properties can be initialized.""" instance = holocron.Item({"x": "skywalker"}, y=42) assert instance["x"] == "skywalker" assert instance["y"] == 42 assert instance == holocron.Item({"x": "skywalker", "y": 42})