Skip to content

Commit 80e3904

Browse files
committed
Validate same doctype (web and config file)
1 parent 6ad9ffd commit 80e3904

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

readthedocs/config/config.py

+19
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ def validate(self):
573573
self.validate_doc_types()
574574
self._config['mkdocs'] = self.validate_mkdocs()
575575
self._config['sphinx'] = self.validate_sphinx()
576+
# TODO: remove later
577+
self.validate_final_doc_type()
576578
self._config['submodules'] = self.validate_submodules()
577579

578580
def validate_formats(self):
@@ -813,6 +815,23 @@ def validate_sphinx(self):
813815

814816
return sphinx
815817

818+
def validate_final_doc_type(self):
819+
"""
820+
Validates that the doctype is the same as the admin panel.
821+
822+
This a temporal validation, as the configuration file
823+
should support per version doctype, but we need to
824+
adapt the rtd code for that.
825+
"""
826+
if self.doctype != self.defaults.get('doctype', 'sphinx'):
827+
key = 'mkdocs' if self.doctype == 'mkdocs' else 'sphinx'
828+
self.error(
829+
key,
830+
'Your documentation type should match '
831+
'the one from the admin panel of your project.',
832+
code=INVALID_KEYS_COMBINATION,
833+
)
834+
816835
def validate_submodules(self):
817836
"""
818837
Validates the submodules key.

readthedocs/config/tests/test_config.py

+39-7
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,10 @@ def test_sphinx_is_default_doc_type(self):
13161316
('htmldir', 'sphinx_htmldir'),
13171317
('singlehtml', 'sphinx_singlehtml')])
13181318
def test_sphinx_builder_check_valid(self, value, expected):
1319-
build = self.get_build_config({'sphinx': {'builder': value}})
1319+
build = self.get_build_config(
1320+
{'sphinx': {'builder': value}},
1321+
{'defaults': {'doctype': expected}},
1322+
)
13201323
build.validate()
13211324
assert build.sphinx.builder == expected
13221325
assert build.doctype == expected
@@ -1333,6 +1336,7 @@ def test_sphinx_builder_default(self):
13331336
build.validate()
13341337
build.sphinx.builder == 'sphinx'
13351338

1339+
@pytest.mark.skip
13361340
def test_sphinx_builder_ignores_default(self):
13371341
build = self.get_build_config(
13381342
{},
@@ -1454,6 +1458,7 @@ def test_mkdocs_configuration_check_valid(self, tmpdir):
14541458
apply_fs(tmpdir, {'mkdocs.yml': ''})
14551459
build = self.get_build_config(
14561460
{'mkdocs': {'configuration': 'mkdocs.yml'}},
1461+
{'defaults': {'doctype': 'mkdocs'}},
14571462
source_file=str(tmpdir.join('readthedocs.yml')),
14581463
)
14591464
build.validate()
@@ -1472,40 +1477,67 @@ def test_mkdocs_configuration_check_invalid(self, tmpdir):
14721477
assert excinfo.value.key == 'mkdocs.configuration'
14731478

14741479
def test_mkdocs_configuration_allow_null(self):
1475-
build = self.get_build_config({'mkdocs': {'configuration': None}},)
1480+
build = self.get_build_config(
1481+
{'mkdocs': {'configuration': None}},
1482+
{'defaults': {'doctype': 'mkdocs'}},
1483+
)
14761484
build.validate()
14771485
assert build.mkdocs.configuration is None
14781486

14791487
def test_mkdocs_configuration_check_default(self):
1480-
build = self.get_build_config({'mkdocs': {}})
1488+
build = self.get_build_config(
1489+
{'mkdocs': {}},
1490+
{'defaults': {'doctype': 'mkdocs'}},
1491+
)
14811492
build.validate()
14821493
assert build.mkdocs.configuration is None
14831494

14841495
@pytest.mark.parametrize('value', [[], True, 0, {}])
14851496
def test_mkdocs_configuration_validate_type(self, value):
1486-
build = self.get_build_config({'mkdocs': {'configuration': value}},)
1497+
build = self.get_build_config(
1498+
{'mkdocs': {'configuration': value}},
1499+
{'defaults': {'doctype': 'mkdocs'}},
1500+
)
14871501
with raises(InvalidConfig) as excinfo:
14881502
build.validate()
14891503
assert excinfo.value.key == 'mkdocs.configuration'
14901504

14911505
@pytest.mark.parametrize('value', [True, False])
14921506
def test_mkdocs_fail_on_warning_check_valid(self, value):
1493-
build = self.get_build_config({'mkdocs': {'fail_on_warning': value}})
1507+
build = self.get_build_config(
1508+
{'mkdocs': {'fail_on_warning': value}},
1509+
{'defaults': {'doctype': 'mkdocs'}},
1510+
)
14941511
build.validate()
14951512
assert build.mkdocs.fail_on_warning is value
14961513

14971514
@pytest.mark.parametrize('value', [[], 'invalid', 5])
14981515
def test_mkdocs_fail_on_warning_check_invalid(self, value):
1499-
build = self.get_build_config({'mkdocs': {'fail_on_warning': value}})
1516+
build = self.get_build_config(
1517+
{'mkdocs': {'fail_on_warning': value}},
1518+
{'defaults': {'doctype': 'mkdocs'}},
1519+
)
15001520
with raises(InvalidConfig) as excinfo:
15011521
build.validate()
15021522
assert excinfo.value.key == 'mkdocs.fail_on_warning'
15031523

15041524
def test_mkdocs_fail_on_warning_check_default(self):
1505-
build = self.get_build_config({'mkdocs': {}})
1525+
build = self.get_build_config(
1526+
{'mkdocs': {}},
1527+
{'defaults': {'doctype': 'mkdocs'}},
1528+
)
15061529
build.validate()
15071530
assert build.mkdocs.fail_on_warning is False
15081531

1532+
def test_validates_different_filetype(self):
1533+
build = self.get_build_config(
1534+
{'mkdocs': {}},
1535+
{'defaults': {'doctype': 'sphinx'}},
1536+
)
1537+
with raises(InvalidConfig) as excinfo:
1538+
build.validate()
1539+
assert excinfo.value.key == 'mkdocs'
1540+
15091541
@pytest.mark.parametrize('value', [[], 'invalid', 0])
15101542
def test_submodules_check_invalid_type(self, value):
15111543
build = self.get_build_config({'submodules': value})

readthedocs/rtd_tests/tests/test_config_integration.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,15 @@ def test_sphinx_builder(
597597
checkout_path.return_value = str(tmpdir)
598598
self.create_config_file(tmpdir, {'sphinx': {'builder': value}})
599599

600-
self.project.documentation_type = 'mkdocs'
600+
self.project.documentation_type = result
601601
self.project.save()
602602

603603
update_docs = self.get_update_docs_task()
604604
update_docs.build_docs_html()
605605

606606
get_builder_class.assert_called_with(result)
607607

608+
@pytest.mark.skip
608609
@patch('readthedocs.projects.tasks.get_builder_class')
609610
def test_sphinx_builder_default(
610611
self, get_builder_class, checkout_path, tmpdir):
@@ -771,6 +772,8 @@ def test_mkdocs_configuration(
771772
},
772773
}
773774
)
775+
self.project.documentation_type = 'mkdocs'
776+
self.project.save()
774777

775778
update_docs = self.get_update_docs_task()
776779
config = update_docs.config
@@ -809,6 +812,8 @@ def test_mkdocs_fail_on_warning(
809812
},
810813
}
811814
)
815+
self.project.documentation_type = 'mkdocs'
816+
self.project.save()
812817

813818
update_docs = self.get_update_docs_task()
814819
config = update_docs.config

readthedocs/rtd_tests/tests/test_doc_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from mock import patch
1717

1818
from readthedocs.builds.models import Version
19-
from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs, MkdocsHTML
19+
from readthedocs.doc_builder.backends.mkdocs import MkdocsHTML
2020
from readthedocs.doc_builder.backends.sphinx import BaseSphinx
2121
from readthedocs.doc_builder.python_environments import Virtualenv
2222
from readthedocs.projects.exceptions import ProjectConfigurationError

0 commit comments

Comments
 (0)