Skip to content

Commit ff3eee4

Browse files
committed
Improve test to check content of generated conf.py
1 parent dd33d93 commit ff3eee4

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

readthedocs/rtd_tests/files/conf.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import division, print_function, unicode_literals
4+
5+
from datetime import datetime
6+
7+
from recommonmark.parser import CommonMarkParser
8+
9+
extensions = []
10+
templates_path = ['/tmp/sphinx-template-dir', 'templates', '_templates', '.templates']
11+
source_suffix = ['.rst', '.md']
12+
source_parsers = {
13+
'.md': CommonMarkParser,
14+
}
15+
master_doc = 'index'
16+
project = u'Pip'
17+
copyright = str(datetime.now().year)
18+
version = '0.8.1'
19+
release = '0.8.1'
20+
exclude_patterns = ['_build']
21+
pygments_style = 'sphinx'
22+
htmlhelp_basename = 'pip'
23+
html_theme = 'sphinx_rtd_theme'
24+
file_insertion_enabled = False
25+
latex_documents = [
26+
('index', 'pip.tex', u'Pip Documentation',
27+
u'', 'manual'),
28+
]

readthedocs/rtd_tests/tests/test_doc_builder.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
absolute_import, division, print_function, unicode_literals)
44

55
from collections import namedtuple
6+
import os
67
import tempfile
78

89
from django.test import TestCase
9-
from mock import patch
10+
from django.test.utils import override_settings
11+
from mock import patch, Mock
1012
import pytest
1113

1214
from readthedocs.doc_builder.backends.sphinx import BaseSphinx
@@ -30,11 +32,16 @@ def setUp(self):
3032
BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
3133
self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)
3234

35+
@patch(
36+
'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
37+
'/tmp/sphinx-template-dir',
38+
)
39+
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
3340
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index')
3441
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
3542
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
3643
@patch('readthedocs.builds.models.Version.get_conf_py_path')
37-
def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_index):
44+
def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_index, docs_dir):
3845
"""
3946
Test for a project without ``conf.py`` file.
4047
@@ -46,10 +53,18 @@ def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_i
4653
any kind of exception raised by ``append_conf`` (we were originally
4754
having a ``TypeError`` because of an encoding problem in Python3)
4855
"""
56+
docs_dir.return_value = tempfile.mkdtemp()
4957
create_index.return_value = 'README.rst'
5058
get_config_params.return_value = {}
5159
get_conf_py_path.side_effect = ProjectConfigurationError
5260
try:
5361
self.base_sphinx.append_conf()
5462
except Exception:
5563
pytest.fail('Exception was generated when append_conf called.')
64+
65+
# Check the content generated by our method is the same than what we
66+
# expects from a pre-generated file
67+
generated_conf_py = os.path.join(self.base_sphinx.docs_dir(), 'conf.py')
68+
expected_conf_py = os.path.join(os.path.dirname(__file__), '..', 'files', 'conf.py')
69+
with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
70+
self.assertEqual(gf.read(), ef.read())

0 commit comments

Comments
 (0)