3
3
absolute_import , division , print_function , unicode_literals )
4
4
5
5
from collections import namedtuple
6
+ import os
6
7
import tempfile
7
8
8
9
from django .test import TestCase
9
- from mock import patch
10
+ from django .test .utils import override_settings
11
+ from mock import patch , Mock
10
12
import pytest
11
13
12
14
from readthedocs .doc_builder .backends .sphinx import BaseSphinx
@@ -30,11 +32,16 @@ def setUp(self):
30
32
BaseSphinx .sphinx_build_dir = tempfile .mkdtemp ()
31
33
self .base_sphinx = BaseSphinx (build_env = build_env , python_env = None )
32
34
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' )
33
40
@patch ('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index' )
34
41
@patch ('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params' )
35
42
@patch ('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run' )
36
43
@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 ):
38
45
"""
39
46
Test for a project without ``conf.py`` file.
40
47
@@ -46,10 +53,18 @@ def test_create_conf_py(self, get_conf_py_path, run, get_config_params, create_i
46
53
any kind of exception raised by ``append_conf`` (we were originally
47
54
having a ``TypeError`` because of an encoding problem in Python3)
48
55
"""
56
+ docs_dir .return_value = tempfile .mkdtemp ()
49
57
create_index .return_value = 'README.rst'
50
58
get_config_params .return_value = {}
51
59
get_conf_py_path .side_effect = ProjectConfigurationError
52
60
try :
53
61
self .base_sphinx .append_conf ()
54
62
except Exception :
55
63
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