예제 #1
0
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"
예제 #2
0
def test_item_destination(testapp, monkeypatch, tmpdir, destination):
    """Save processor has to respect any destination value."""

    monkeypatch.chdir(tmpdir)

    stream = save.process(
        testapp,
        [holocron.Item({
            "content": "Obi-Wan",
            "destination": destination
        })],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": "Obi-Wan",
            "destination": destination
        })
    ]
    assert tmpdir.join("_site", destination).read_text("UTF-8") == "Obi-Wan"
예제 #3
0
def test_item_content_types(testapp, monkeypatch, tmpdir, data, loader):
    """Save processor has to save content of bytes and string types."""

    monkeypatch.chdir(tmpdir)

    stream = save.process(
        testapp,
        [
            holocron.Item({
                "content": data,
                "destination": pathlib.Path("1.dat")
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": data,
            "destination": pathlib.Path("1.dat")
        })
    ]
    assert loader(tmpdir.join("_site", "1.dat")) == data
예제 #4
0
def test_item(testapp, monkeypatch, tmpdir):
    """Save processor has to work!"""

    monkeypatch.chdir(tmpdir)

    stream = save.process(
        testapp,
        [
            holocron.Item({
                "content": "Obi-Wan",
                "destination": pathlib.Path("1.html")
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": "Obi-Wan",
            "destination": pathlib.Path("1.html")
        })
    ]
    assert tmpdir.join("_site", "1.html").read_text("UTF-8") == "Obi-Wan"
예제 #5
0
def test_args_to(testapp, monkeypatch, tmpdir, to):
    """Save processor has to respect 'to' argument."""

    monkeypatch.chdir(tmpdir)

    stream = save.process(
        testapp,
        [
            holocron.Item({
                "content": "Obi-Wan",
                "destination": pathlib.Path("1.html")
            })
        ],
        to=to,
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": "Obi-Wan",
            "destination": pathlib.Path("1.html")
        })
    ]
    assert tmpdir.join(to, "1.html").read_text("UTF-8") == "Obi-Wan"
예제 #6
0
def test_args_encoding_fallback(testapp, monkeypatch, tmpdir, encoding):
    """Save processor has to respect 'encoding' argument (fallback)."""

    monkeypatch.chdir(tmpdir)
    testapp.metadata.update({"encoding": encoding})

    stream = save.process(
        testapp,
        [
            holocron.Item({
                "content": "Обі-Ван",
                "destination": pathlib.Path("1.html")
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.Item({
            "content": "Обі-Ван",
            "destination": pathlib.Path("1.html")
        })
    ]
    assert tmpdir.join("_site", "1.html").read_text(encoding) == "Обі-Ван"
예제 #7
0
def test_args_bad_value(testapp, args, error):
    """Save processor has to validate input arguments."""

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