示例#1
0
    def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = ProjectFactory(allow_comments=True)

        version = project.versions.all()[0]
        mock_api_versions.return_value = [version]

        mock_apiv2_downloads.get.return_value = {'downloads': "no_url_here"}

        conf_path = os.path.join(
            project.checkout_path(version.slug),
            project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(version,
                                        False,
                                        False,
                                        False,
                                        )

        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1])
                      )
示例#2
0
    def test_build_respects_epub_flag(self,
                                      EpubBuilder_build,
                                      PdfBuilder_build,
                                      HtmlBuilder_build,
                                      mock_NonBlockingLock_enter,
                                      mock_Popen,
                                      mock_chdir,
                                      mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        conf_path = os.path.join(project.checkout_path(version.slug), project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(version,
                                        False,
                                        False,
                                        False,
                                        )

        # The HTML and the Epub format were built.
        self.assertEqual(HtmlBuilder_build.call_count, 1)
        self.assertEqual(EpubBuilder_build.call_count, 1)
        # PDF however was disabled and therefore not built.
        self.assertEqual(PdfBuilder_build.call_count, 0)
示例#3
0
    def test_build_respects_epub_flag(self, EpubBuilder_build,
                                      PdfBuilder_build, HtmlBuilder_build,
                                      mock_NonBlockingLock_enter, mock_Popen,
                                      mock_chdir, mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-2',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=False,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all()[0]

        conf_path = os.path.join(project.checkout_path(version.slug),
                                 project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(
                    version,
                    False,
                    False,
                    False,
                )

        # The HTML and the Epub format were built.
        self.assertEqual(HtmlBuilder_build.call_count, 1)
        self.assertEqual(EpubBuilder_build.call_count, 1)
        # PDF however was disabled and therefore not built.
        self.assertEqual(PdfBuilder_build.call_count, 0)
示例#4
0
    def test_build(self, mock_Popen, mock_NonBlockingLock_enter,
                   mock_api_versions, mock_chdir, mock_apiv2_downloads):

        # subprocess mock logic

        mock_process = mock.Mock()
        process_return_dict = {'communicate.return_value': ('SOMEGITHASH', '')}
        mock_process.configure_mock(**process_return_dict)
        mock_Popen.return_value = mock_process
        mock_Popen.side_effect = build_subprocess_side_effect

        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])

        version = project.versions.all()[0]
        mock_api_versions.return_value = [version]

        mock_apiv2_downloads.get.return_value = {'downloads': "no_url_here"}

        conf_path = os.path.join(project.checkout_path(version.slug),
                                 project.conf_py_file)

        # Mock open to simulate existing conf.py file
        with mock.patch('codecs.open', mock.mock_open(), create=True):
            with fake_paths_lookup({conf_path: True}):
                built_docs = build_docs(
                    version,
                    False,
                    False,
                    False,
                )

        builder_class = get_builder_class(project.documentation_type)
        builder = builder_class(version)
        self.assertIn(builder.sphinx_builder,
                      str(mock_Popen.call_args_list[1]))
示例#5
0
    def test_install_user_requirements(self):
        """
        If a projects does not specify a requirements file,
        RTD will choose one automatically.

        First by searching under the docs/ directory and then under the root.
        The files can be named as:

        - ``pip_requirements.txt``
        - ``requirements.txt``
        """
        self.build_env_mock.project = self.project_sphinx
        self.build_env_mock.version = self.version_sphinx
        python_env = Virtualenv(
            version=self.version_sphinx,
            build_env=self.build_env_mock
        )

        checkout_path = python_env.checkout_path
        docs_requirements = os.path.join(
            checkout_path, 'docs', 'requirements.txt'
        )
        root_requirements = os.path.join(
            checkout_path, 'requirements.txt'
        )
        paths = {
            os.path.join(checkout_path, 'docs'): True,
        }
        args = [
            'python',
            mock.ANY,  # pip path
            'install',
            '--exists-action=w',
            '--cache-dir',
            mock.ANY,  # cache path
            'requirements_file'
        ]

        # One requirements file on the docs/ dir
        # should be installed
        paths[docs_requirements] = True
        paths[root_requirements] = False
        with fake_paths_lookup(paths):
            python_env.install_user_requirements()
        args[-1] = '-r{}'.format(docs_requirements)
        self.build_env_mock.run.assert_called_with(
            *args, cwd=mock.ANY, bin_path=mock.ANY
        )

        # One requirements file on the root dir
        # should be installed
        paths[docs_requirements] = False
        paths[root_requirements] = True
        with fake_paths_lookup(paths):
            python_env.install_user_requirements()
        args[-1] = '-r{}'.format(root_requirements)
        self.build_env_mock.run.assert_called_with(
            *args, cwd=mock.ANY, bin_path=mock.ANY
        )

        # Two requirements files on the root and  docs/ dirs
        # the one on docs/ should be installed
        paths[docs_requirements] = True
        paths[root_requirements] = True
        with fake_paths_lookup(paths):
            python_env.install_user_requirements()
        args[-1] = '-r{}'.format(docs_requirements)
        self.build_env_mock.run.assert_called_with(
            *args, cwd=mock.ANY, bin_path=mock.ANY
        )

        # No requirements file
        # no requirements should be installed
        self.build_env_mock.run.reset_mock()
        paths[docs_requirements] = False
        paths[root_requirements] = False
        with fake_paths_lookup(paths):
            python_env.install_user_requirements()
        self.build_env_mock.run.assert_not_called()