|
12 | 12 | from noxconfig import PROJECT_CONFIG |
13 | 13 |
|
14 | 14 |
|
15 | | -@pytest.fixture() |
16 | | -def file1(): |
17 | | - return """ |
18 | | -https://examle.invalid |
19 | | -:ref:`Test`""" |
| 15 | +@pytest.fixture |
| 16 | +def index(config): |
| 17 | + index_rst = config.documentation_path / "index.rst" |
| 18 | + text = """ |
| 19 | + .. _Test: |
20 | 20 |
|
| 21 | + Test |
| 22 | + ____test_docs_links |
21 | 23 |
|
22 | | -@pytest.fixture() |
23 | | -def index(): |
24 | | - return """.. _Test: |
| 24 | + .. toctree:: |
| 25 | + :maxdepth: 1 |
| 26 | + :hidden: |
25 | 27 |
|
26 | | -Test |
27 | | -____ |
| 28 | + file |
| 29 | + """ |
| 30 | + index_rst.write_text(text) |
28 | 31 |
|
29 | | -.. toctree:: |
30 | | - :maxdepth: 1 |
31 | | - :hidden: |
32 | 32 |
|
33 | | - file""" |
| 33 | +@pytest.fixture |
| 34 | +def config(test_project_config_factory): |
| 35 | + config = test_project_config_factory() |
34 | 36 |
|
| 37 | + # set up required file for Sphinx |
| 38 | + doc_path = config.documentation_path |
| 39 | + doc_path.mkdir(parents=True, exist_ok=True) |
| 40 | + shutil.copyfile(PROJECT_CONFIG.documentation_path / "conf.py", doc_path / "conf.py") |
35 | 41 |
|
36 | | -@pytest.fixture() |
37 | | -def expected1(): |
38 | | - return """filename: file.rst:2 -> uri: https://examle.invalid""" |
| 42 | + return config |
39 | 43 |
|
40 | 44 |
|
41 | | -def config(index, file, tmp_path): |
42 | | - test_doc = tmp_path / "doc" |
43 | | - test_doc.mkdir() |
44 | | - (test_doc / "_static").mkdir() |
45 | | - shutil.copyfile(PROJECT_CONFIG.documentation_path / "conf.py", test_doc / "conf.py") |
46 | | - rst_index = test_doc / "index.rst" |
47 | | - rst_file1 = test_doc / "file.rst" |
48 | | - rst_index.touch() |
49 | | - rst_file1.touch() |
50 | | - rst_index.write_text(index) |
51 | | - rst_file1.write_text(file) |
| 45 | +@pytest.fixture |
| 46 | +def set_up_doc_with_link(config, index): |
| 47 | + dummy_rst = config.documentation_path / "dummy.rst" |
| 48 | + dummy_rst.write_text("https://examle.invalid\n:ref:`Test`") |
52 | 49 |
|
53 | 50 |
|
54 | | -def test_docs_links(index, file1, expected1, tmp_path): |
55 | | - config(index, file1, tmp_path) |
56 | | - r_code, text = _docs_list_links(tmp_path / "doc") |
57 | | - assert (text == expected1) and not r_code |
| 51 | +def test_docs_links(config, set_up_doc_with_link): |
| 52 | + r_code, text = _docs_list_links(config.documentation_path) |
| 53 | + |
| 54 | + assert not r_code |
| 55 | + assert text == """filename: dummy.rst:1 -> uri: https://examle.invalid""" |
58 | 56 |
|
59 | 57 |
|
60 | 58 | @pytest.mark.parametrize( |
61 | | - "file2, expected2", |
| 59 | + "file_content, expected_code, expected_message", |
62 | 60 | [ |
63 | | - ("https://github.com/exasol/python-toolbox", (0, "")), |
| 61 | + ("https://github.com/exasol/python-toolbox", 0, ""), |
64 | 62 | ( |
65 | 63 | "http://nox.thea.codes/en/stable/", |
66 | | - ( |
67 | | - 0, |
68 | | - "file.rst:1: [redirected with Found] http://nox.thea.codes/en/stable/ to https://nox.thea.codes/en/stable/\n", |
69 | | - ), |
| 64 | + 0, |
| 65 | + "[redirected with Found] http://nox.thea.codes/en/stable/ to https://nox.thea.codes/en/stable/\n", |
70 | 66 | ), |
71 | 67 | ( |
72 | 68 | "https://github.com/exasol/python-toolbox/pull", |
73 | | - ( |
74 | | - 0, |
75 | | - "file.rst:1: [redirected permanently] https://github.com/exasol/python-toolbox/pull to https://github.com/exasol/python-toolbox/pulls\n", |
76 | | - ), |
| 69 | + 0, |
| 70 | + "[redirected permanently] https://github.com/exasol/python-toolbox/pull to https://github.com/exasol/python-toolbox/pulls\n", |
77 | 71 | ), |
78 | 72 | ( |
79 | 73 | "https://github.com/exasol/python-toolbox/asdf", |
80 | | - ( |
81 | | - 1, |
82 | | - "file.rst:1: [broken] https://github.com/exasol/python-toolbox/asdf: 404 Client Error: Not Found for url: https://github.com/exasol/python-toolbox/asdf\n", |
83 | | - ), |
| 74 | + 1, |
| 75 | + "[broken] https://github.com/exasol/python-toolbox/asdf: 404 Client Error: Not Found for url: https://github.com/exasol/python-toolbox/asdf\n", |
84 | 76 | ), |
85 | 77 | ], |
86 | 78 | ) |
87 | | -def test_docs_links_check(index, file2, expected2, tmp_path): |
88 | | - config(index, file2, tmp_path) |
| 79 | +def test_docs_links_check(config, index, file_content, expected_code, expected_message): |
| 80 | + dummy_rst = config.documentation_path / "dummy.rst" |
| 81 | + dummy_rst.write_text(file_content) |
| 82 | + |
89 | 83 | args = MagicMock |
90 | 84 | args.output = None |
91 | | - actual = _docs_links_check(tmp_path / "doc", args) |
92 | | - assert actual == expected2 |
| 85 | + |
| 86 | + code, message = _docs_links_check(config.documentation_path, args) |
| 87 | + |
| 88 | + assert code == expected_code |
| 89 | + assert expected_message in message |
0 commit comments