From 58adc35f8ecdf39e0d7dd291b37378461e763df3 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 7 Aug 2018 10:19:49 -0500 Subject: [PATCH] Fix tests --- .../rtd_tests/tests/test_doc_builder.py | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index 77caf4ec6ea..07fffeafd5e 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -30,23 +30,13 @@ def setUp(self): self.project = Project.objects.get(slug='pip') self.version = self.project.versions.first() - build_env = namedtuple('project', 'version') - build_env.project = self.project - build_env.version = self.version + self.build_env = namedtuple('project', 'version') + self.build_env.project = self.project + self.build_env.version = self.version BaseSphinx.type = 'base' BaseSphinx.sphinx_build_dir = tempfile.mkdtemp() - python_env = Virtualenv( - version=self.version, - build_env=build_env, - config=None, - ) - self.base_sphinx = BaseSphinx( - build_env=build_env, - python_env=python_env, - ) - @patch( 'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR', '/tmp/sphinx-template-dir', @@ -57,7 +47,8 @@ def setUp(self): @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run') @patch('readthedocs.builds.models.Version.get_conf_py_path') @patch('readthedocs.builds.models.Project.conf_file') - def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params, create_index, docs_dir): + @patch('readthedocs.projects.models.Project.checkout_path') + def test_create_conf_py(self, checkout_path, conf_file, get_conf_py_path, _, get_config_params, create_index, docs_dir): """ Test for a project without ``conf.py`` file. @@ -69,20 +60,35 @@ def test_create_conf_py(self, conf_file, get_conf_py_path, _, get_config_params, any kind of exception raised by ``append_conf`` (we were originally having a ``TypeError`` because of an encoding problem in Python3) """ + checkout_path.return_value = tempfile.mkdtemp() docs_dir.return_value = tempfile.mkdtemp() create_index.return_value = 'README.rst' get_config_params.return_value = {} get_conf_py_path.side_effect = ProjectConfigurationError conf_file.return_value = tempfile.mktemp() + python_env = Virtualenv( + version=self.version, + build_env=self.build_env, + config=None, + ) + base_sphinx = BaseSphinx( + build_env=self.build_env, + python_env=python_env, + ) try: - self.base_sphinx.append_conf() + 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') + generated_conf_py = os.path.join(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())