Skip to content

Commit 4a96492

Browse files
committed
added tests for mkdocs file
1 parent 202ce9e commit 4a96492

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

readthedocs/rtd_tests/tests/test_doc_builder.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from readthedocs.doc_builder.python_environments import Virtualenv
1313
from readthedocs.projects.exceptions import ProjectConfigurationError
1414
from readthedocs.projects.models import Project
15+
from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs
16+
from readthedocs.doc_builder.exceptions import MkDocsYAMLParseError
1517

1618

1719
@override_settings(PRODUCTION_DOMAIN="readthedocs.org")
@@ -112,3 +114,65 @@ def test_multiple_conf_py(
112114
with pytest.raises(ProjectConfigurationError):
113115
with override_settings(DOCROOT=tmp_docs_dir):
114116
base_sphinx.show_conf()
117+
118+
119+
@override_settings(PRODUCTION_DOMAIN="readthedocs.org")
120+
class MkdocsBuilderTest(TestCase):
121+
fixtures = ["test_data", "eric"]
122+
123+
def setUp(self):
124+
self.project = Project.objects.get(slug="pip")
125+
self.version = self.project.versions.first()
126+
127+
self.build_env = mock.MagicMock()
128+
self.build_env.project = self.project
129+
self.build_env.version = self.version
130+
self.build_env.build = {
131+
"id": 123,
132+
}
133+
self.build_env.api_client = mock.MagicMock()
134+
135+
BaseMkdocs.type = "base"
136+
BaseMkdocs.mkdocs_build_dir = tempfile.mkdtemp()
137+
BaseMkdocs.relative_output_dir = "_readthedocs/"
138+
139+
140+
@patch("readthedocs.doc_builder.backends.sphinx.BaseMkdocs.docs_dir")
141+
@patch("readthedocs.doc_builder.backends.sphinx.BaseMkdocs.run")
142+
@patch("readthedocs.builds.models.Version.get_mkdocs_yaml_path")
143+
@patch("readthedocs.projects.models.Project.checkout_path")
144+
@patch("readthedocs.doc_builder.python_environments.load_yaml_config")
145+
def test_project_without_mkdocs_yaml(
146+
self,
147+
load_yaml_config,
148+
checkout_path,
149+
get_mkdocs_yaml_path,
150+
_,
151+
docs_dir,
152+
):
153+
"""
154+
Test for a project without ``conf.py`` file.
155+
156+
When this happen, the ``get_conf_py_path`` raises a
157+
``ProjectConfigurationError`` which is captured by our own code.
158+
"""
159+
tmp_dir = tempfile.mkdtemp()
160+
checkout_path.return_value = tmp_dir
161+
docs_dir.return_value = tmp_dir
162+
get_mkdocs_yaml_path.side_effect = MkDocsYAMLParseError
163+
python_env = Virtualenv(
164+
version=self.version,
165+
build_env=self.build_env,
166+
config=get_build_config({}, validate=True),
167+
)
168+
base_mkdocs = BaseMkdocs(
169+
build_env=self.build_env,
170+
python_env=python_env,
171+
)
172+
with self.assertRaises(MkDocsYAMLParseError) as e:
173+
base_mkdocs.show_conf()
174+
175+
self.assertEqual(
176+
e.exception.message_id,
177+
MkDocsYAMLParseError.NOT_FOUND,
178+
)

0 commit comments

Comments
 (0)