Skip to content

Commit ec1e077

Browse files
committed
Add tests for sphinx
1 parent c4661d7 commit ec1e077

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

readthedocs/rtd_tests/tests/test_config_integration.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,109 @@ def test_system_packages(self, run, checkout_path, tmpdir):
572572

573573
assert '--system-site-packages' in args
574574
assert config.python.use_system_site_packages
575+
576+
@pytest.mark.parametrize('value,result',
577+
[('html', 'sphinx'),
578+
('htmldir', 'sphinx_htmldir'),
579+
('singlehtml', 'sphinx_singlehtml')])
580+
@patch('readthedocs.projects.tasks.get_builder_class')
581+
def test_sphinx_builder(
582+
self, get_builder_class, checkout_path, value, result, tmpdir):
583+
checkout_path.return_value = str(tmpdir)
584+
self.create_config_file(tmpdir, {'sphinx': {'builder': value}})
585+
586+
self.project.documentation_type = 'mkdocs'
587+
self.project.save()
588+
589+
update_docs = self.get_update_docs_task()
590+
update_docs.build_docs_html()
591+
592+
get_builder_class.assert_called_with(result)
593+
594+
@patch('readthedocs.projects.tasks.get_builder_class')
595+
def test_sphinx_builder_default(
596+
self, get_builder_class, checkout_path, tmpdir):
597+
checkout_path.return_value = str(tmpdir)
598+
self.create_config_file(tmpdir, {})
599+
600+
self.project.documentation_type = 'mkdocs'
601+
self.project.save()
602+
603+
update_docs = self.get_update_docs_task()
604+
update_docs.build_docs_html()
605+
606+
get_builder_class.assert_called_with('sphinx')
607+
608+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')
609+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')
610+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
611+
def test_sphinx_configuration(
612+
self, run, append_conf, move, checkout_path, tmpdir):
613+
checkout_path.return_value = str(tmpdir)
614+
apply_fs(tmpdir, {
615+
'conf.py': '',
616+
'docx': {
617+
'conf.py': '',
618+
},
619+
})
620+
self.create_config_file(
621+
tmpdir,
622+
{
623+
'sphinx': {
624+
'configuration': 'docx/conf.py',
625+
},
626+
}
627+
)
628+
629+
update_docs = self.get_update_docs_task()
630+
config = update_docs.config
631+
python_env = Virtualenv(
632+
version=self.version,
633+
build_env=update_docs.build_env,
634+
config=config
635+
)
636+
update_docs.python_env = python_env
637+
638+
update_docs.build_docs_html()
639+
640+
args, kwargs = run.call_args
641+
assert kwargs['cwd'] == path.join(str(tmpdir), 'docx')
642+
append_conf.assert_called_once()
643+
move.assert_called_once()
644+
645+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.move')
646+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf')
647+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
648+
def test_sphinx_fail_on_warning(
649+
self, run, append_conf, move, checkout_path, tmpdir):
650+
checkout_path.return_value = str(tmpdir)
651+
apply_fs(tmpdir, {
652+
'docx': {
653+
'conf.py': '',
654+
},
655+
})
656+
self.create_config_file(
657+
tmpdir,
658+
{
659+
'sphinx': {
660+
'configuration': 'docx/conf.py',
661+
'fail_on_warning': True,
662+
},
663+
}
664+
)
665+
666+
update_docs = self.get_update_docs_task()
667+
config = update_docs.config
668+
python_env = Virtualenv(
669+
version=self.version,
670+
build_env=update_docs.build_env,
671+
config=config
672+
)
673+
update_docs.python_env = python_env
674+
675+
update_docs.build_docs_html()
676+
677+
args, kwargs = run.call_args
678+
assert '-W' in args
679+
append_conf.assert_called_once()
680+
move.assert_called_once()

0 commit comments

Comments
 (0)