File: test_errors.py

package info (click to toggle)
sphinxcontrib-datatemplates 0.11.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 580 kB
  • sloc: python: 828; makefile: 172; xml: 38; javascript: 1
file content (125 lines) | stat: -rw-r--r-- 4,323 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from __future__ import annotations

from typing import TYPE_CHECKING
import pytest

if TYPE_CHECKING:
    from io import StringIO
    from sphinx.testing.util import SphinxTestApp


@pytest.mark.sphinx("html", testroot="empty-source")
def test_empty_source(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: ERROR: Source file is required"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="nonexistent-source")
def test_nonexisting_source(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Source file 'sample1.json' not found"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="empty-template")
def test_empty_template(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: ERROR: Template is empty"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="nonexistent-template")
def test_nonexistent_template(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Template file 'sample1.tmpl' not found"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="nonexistent-template-filter")
def test_nonexistent_template_filter(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in template file 'sample.tmpl' line 1: "
        "No filter named 'some_filter'."
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-template-syntax")
def test_incorrect_template_syntax(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in template file 'sample.tmpl' line 1: "
        "unexpected '}'"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-json-syntax")
def test_incorrect_json_syntax(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in source 'sample.json': "
        "Invalid control character at: line 2 column 28 (char 29)"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-yaml-syntax")
def test_incorrect_yaml_syntax(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in source 'sample.yaml': "
        "while parsing a block collection\n"
        '  in "sample.yaml", line 11, column 3\n'
        "expected <block end>, but found '?'\n"
        '  in "sample.yaml", line 12, column 3'
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-xml-syntax")
def test_incorrect_xml_syntax(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in source 'sample.xml': "
        "not well-formed (invalid token): line 2, column 4"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-import-module")
def test_incorrect_import_module(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in source 'some_module': No module named 'some_module'"
    )
    assert expected_error_str in warning.getvalue()


@pytest.mark.sphinx("html", testroot="incorrect-dbm")
def test_incorrect_dbm(app: SphinxTestApp, warning: StringIO):
    app.builder.build_all()
    expected_error_str = (
        f"{app.srcdir / 'index.rst'}:1: "
        "ERROR: Error in source 'sampledbm': "
        "db type could not be determined"
    )
    assert expected_error_str in warning.getvalue()