Skip to content

Commit 4b4f056

Browse files
committed
Simplify test
1 parent f6c029a commit 4b4f056

File tree

1 file changed

+47
-50
lines changed

1 file changed

+47
-50
lines changed

test/unit/nox/_documentation_test.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,78 @@
1212
from noxconfig import PROJECT_CONFIG
1313

1414

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:
2020
21+
Test
22+
____test_docs_links
2123
22-
@pytest.fixture()
23-
def index():
24-
return """.. _Test:
24+
.. toctree::
25+
:maxdepth: 1
26+
:hidden:
2527
26-
Test
27-
____
28+
file
29+
"""
30+
index_rst.write_text(text)
2831

29-
.. toctree::
30-
:maxdepth: 1
31-
:hidden:
3232

33-
file"""
33+
@pytest.fixture
34+
def config(test_project_config_factory):
35+
config = test_project_config_factory()
3436

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")
3541

36-
@pytest.fixture()
37-
def expected1():
38-
return """filename: file.rst:2 -> uri: https://examle.invalid"""
42+
return config
3943

4044

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`")
5249

5350

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"""
5856

5957

6058
@pytest.mark.parametrize(
61-
"file2, expected2",
59+
"file_content, expected_code, expected_message",
6260
[
63-
("https://github.com/exasol/python-toolbox", (0, "")),
61+
("https://github.com/exasol/python-toolbox", 0, ""),
6462
(
6563
"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",
7066
),
7167
(
7268
"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",
7771
),
7872
(
7973
"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",
8476
),
8577
],
8678
)
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+
8983
args = MagicMock
9084
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

Comments
 (0)