diff --git a/readthedocs/rtd_tests/files/conf.py b/readthedocs/rtd_tests/files/conf.py new file mode 100644 index 00000000000..1b65e7b52cb --- /dev/null +++ b/readthedocs/rtd_tests/files/conf.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +from __future__ import division, print_function, unicode_literals + +from datetime import datetime + +from recommonmark.parser import CommonMarkParser + +extensions = [] +templates_path = ['/tmp/sphinx-template-dir', 'templates', '_templates', '.templates'] +source_suffix = ['.rst', '.md'] +source_parsers = { + '.md': CommonMarkParser, + } +master_doc = 'index' +project = u'Pip' +copyright = str(datetime.now().year) +version = '0.8.1' +release = '0.8.1' +exclude_patterns = ['_build'] +pygments_style = 'sphinx' +htmlhelp_basename = 'pip' +html_theme = 'sphinx_rtd_theme' +file_insertion_enabled = False +latex_documents = [ + ('index', 'pip.tex', u'Pip Documentation', + u'', 'manual'), +] diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index ef802b043ac..4541dcac204 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -3,10 +3,12 @@ absolute_import, division, print_function, unicode_literals) from collections import namedtuple +import os import tempfile from django.test import TestCase -from mock import patch +from django.test.utils import override_settings +from mock import patch, Mock import pytest from readthedocs.doc_builder.backends.sphinx import BaseSphinx @@ -30,11 +32,16 @@ def setUp(self): BaseSphinx.sphinx_build_dir = tempfile.mkdtemp() self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None) + @patch( + 'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR', + '/tmp/sphinx-template-dir', + ) + @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir') @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index') @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params') @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run') @patch('readthedocs.builds.models.Version.get_conf_py_path') - def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_index): + def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_index, docs_dir): """ Test for a project without ``conf.py`` file. @@ -46,6 +53,7 @@ def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_i any kind of exception raised by ``append_conf`` (we were originally having a ``TypeError`` because of an encoding problem in Python3) """ + docs_dir.return_value = tempfile.mkdtemp() create_index.return_value = 'README.rst' get_config_params.return_value = {} get_conf_py_path.side_effect = ProjectConfigurationError @@ -53,3 +61,10 @@ def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_i self.base_sphinx.append_conf() except Exception: pytest.fail('Exception was generated when append_conf called.') + + # Check the content generated by our method is the same than what we + # expects from a pre-generated file + generated_conf_py = os.path.join(self.base_sphinx.docs_dir(), 'conf.py') + expected_conf_py = os.path.join(os.path.dirname(__file__), '..', 'files', 'conf.py') + with open(generated_conf_py) as gf, open(expected_conf_py) as ef: + self.assertEqual(gf.read(), ef.read())