aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/test_check_failure.py
blob: 08e944753ce920d08c05f4adaa8cbf86ab67e0a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
The demo build should pass 'nikola check' and fail with missing files.

This tests the red path (failures) for the `check` command.
Green path tests (working as expected) can be found in `test_demo_build`.
"""

import io
import os

import pytest

from nikola import __main__

from .helper import cd
from .test_demo_build import prepare_demo_site
from .test_empty_build import (  # NOQA
    test_avoid_double_slash_in_rss,
    test_index_in_sitemap,
)


def test_check_links_fail(build, output_dir, target_dir):
    os.unlink(os.path.join(output_dir, "archive.html"))

    with cd(target_dir):
        result = __main__.main(["check", "-l"])
        assert result != 0


def test_check_files_fail(build, output_dir, target_dir):
    manually_added_file = os.path.join(output_dir, "foobar")
    with io.open(manually_added_file, "w+", encoding="utf8") as outf:
        outf.write("foo")

    with cd(target_dir):
        result = __main__.main(["check", "-f"])
        assert result != 0


@pytest.fixture(scope="module")
def build(target_dir):
    """Fill the site with demo content and build it."""
    prepare_demo_site(target_dir)

    with cd(target_dir):
        __main__.main(["build"])