Skip to content

Commit

Permalink
Improve test to check content of generated conf.py
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Mar 15, 2018
1 parent dd33d93 commit ff3eee4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
28 changes: 28 additions & 0 deletions readthedocs/rtd_tests/files/conf.py
Original file line number Diff line number Diff line change
@@ -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'),
]
19 changes: 17 additions & 2 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -46,10 +53,18 @@ 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
try:
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())

0 comments on commit ff3eee4

Please sign in to comment.