Beispiel #1
0
    def test_dont_localmedia_build_pdf_epub_search_in_mkdocs(
            self, load_config):
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='mkdocs',
                      enable_pdf_build=True,
                      enable_epub_build=True,
                      versions=[fixture()])
        version = project.versions.all().first()

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)

        task.build_docs()

        # Only html for mkdocs was built
        self.mocks.html_build_mkdocs.assert_called_once()
        self.mocks.html_build.assert_not_called()
        self.mocks.localmedia_build.assert_not_called()
        self.mocks.pdf_build.assert_not_called()
        self.mocks.epub_build.assert_not_called()
Beispiel #2
0
    def test_build(self, load_config):
        '''Test full build'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])
        version = project.versions.all()[0]
        self.mocks.configure_mock('api_versions', {'return_value': [version]})
        self.mocks.configure_mock(
            'api', {'get.return_value': {
                'downloads': "no_url_here"
            }})
        self.mocks.patches['html_build'].stop()

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)
        task.build_docs()

        # Get command and check first part of command list is a call to sphinx
        self.assertEqual(self.mocks.popen.call_count, 3)
        cmd = self.mocks.popen.call_args_list[2][0]
        self.assertRegex(cmd[0][0], r'python')
        self.assertRegex(cmd[0][1], r'sphinx-build')
Beispiel #3
0
    def test_build_respects_pdf_flag(self, load_config):
        '''Build output format control'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env,
                                  project=project,
                                  python_env=python_env,
                                  version=version,
                                  config=config)

        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.pdf_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.epub_build.called)
    def test_build_respects_pdf_flag(self, load_config):
        '''Build output format control'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      enable_pdf_build=True,
                      enable_epub_build=False,
                      versions=[fixture()])
        version = project.versions.all()[0]

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)

        task.build_docs()

        # The HTML and the Epub format were built.
        self.mocks.html_build.assert_called_once_with()
        self.mocks.pdf_build.assert_called_once_with()
        # PDF however was disabled and therefore not built.
        self.assertFalse(self.mocks.epub_build.called)
    def test_dont_localmedia_build_pdf_epub_search_in_mkdocs(self, load_config):
        load_config.side_effect = create_load()
        project = get(
            Project,
            slug='project-1',
            documentation_type='mkdocs',
            enable_pdf_build=True,
            enable_epub_build=True,
            versions=[fixture()],
        )
        version = project.versions.all().first()

        build_env = LocalBuildEnvironment(
            project=project,
            version=version,
            build={},
        )
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env, project=project, python_env=python_env,
            version=version, config=config,
        )

        task.build_docs()

        # Only html for mkdocs was built
        self.mocks.html_build_mkdocs.assert_called_once()
        self.mocks.html_build.assert_not_called()
        self.mocks.localmedia_build.assert_not_called()
        self.mocks.pdf_build.assert_not_called()
        self.mocks.epub_build.assert_not_called()
    def test_build(self, load_config):
        '''Test full build'''
        load_config.side_effect = create_load()
        project = get(Project,
                      slug='project-1',
                      documentation_type='sphinx',
                      conf_py_file='test_conf.py',
                      versions=[fixture()])
        version = project.versions.all()[0]
        self.mocks.configure_mock('api_versions', {'return_value': [version]})
        self.mocks.configure_mock('api', {
            'get.return_value': {'downloads': "no_url_here"}
        })
        self.mocks.patches['html_build'].stop()

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(build_env=build_env, project=project, python_env=python_env,
                              version=version, search=False, localmedia=False, config=config)
        task.build_docs()

        # Get command and check first part of command list is a call to sphinx
        self.assertEqual(self.mocks.popen.call_count, 3)
        cmd = self.mocks.popen.call_args_list[2][0]
        self.assertRegexpMatches(cmd[0][0], r'python')
        self.assertRegexpMatches(cmd[0][1], r'sphinx-build')
    def test_use_sphinx_builders(self, load_config):
        feature = get(
            Feature,
            feature_id=Feature.USE_SPHINX_BUILDERS,
        )

        config_data = {
            'version': 2,
            'sphinx': {
                'configuration': 'docs/conf.py'
            }
        }
        load_config.side_effect = create_load(config_data)
        config = load_yaml_config(self.version)

        python_env = Virtualenv(
            version=self.version,
            build_env=self.build_env,
            config=config,
        )
        builder = HtmlBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'readthedocs')

        builder = HtmlDirBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'readthedocsdirhtml')

        builder = SingleHtmlBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'readthedocssinglehtml')

        # Add the feature to use the regular builders
        feature.projects.add(self.project)

        builder = HtmlBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'html')

        builder = HtmlDirBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'dirhtml')

        builder = SingleHtmlBuilder(
            build_env=self.build_env,
            python_env=python_env,
        )
        self.assertEqual(builder.sphinx_builder, 'singlehtml')
Beispiel #8
0
    def test_build_pdf_latex_not_failure(self, load_config):
        """Test pass during PDF builds and bad latex failure status code."""

        load_config.side_effect = create_load()
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

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

        build_env = LocalBuildEnvironment(project=project,
                                          version=version,
                                          build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env,
            project=project,
            python_env=python_env,
            version=version,
            config=config,
        )

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            ((b'', b''), 0),  # sphinx-build html
            ((b'', b''), 0),  # sphinx-build pdf
            ((b'', b''), 1),  # sphinx version check
            ((b'Output written on foo.pdf', b''), 1),  # latex
            ((b'', b''), 0),  # makeindex
            ((b'', b''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [
            output for (output, status) in returns
        ]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns], )
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 6)
        self.assertTrue(build_env.successful)
    def test_build_pdf_latex_not_failure(self, load_config):
        """Test pass during PDF builds and bad latex failure status code."""

        load_config.side_effect = create_load()
        self.mocks.patches['html_build'].stop()
        self.mocks.patches['pdf_build'].stop()

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

        build_env = LocalBuildEnvironment(project=project, version=version, build={})
        python_env = Virtualenv(version=version, build_env=build_env)
        config = load_yaml_config(version)
        task = UpdateDocsTaskStep(
            build_env=build_env, project=project, python_env=python_env,
            version=version, config=config,
        )

        # Mock out the separate calls to Popen using an iterable side_effect
        returns = [
            ((b'', b''), 0),  # sphinx-build html
            ((b'', b''), 0),  # sphinx-build pdf
            ((b'Output written on foo.pdf', b''), 1),  # latex
            ((b'', b''), 0),  # makeindex
            ((b'', b''), 0),  # latex
        ]
        mock_obj = mock.Mock()
        mock_obj.communicate.side_effect = [
            output for (output, status)
            in returns
        ]
        type(mock_obj).returncode = mock.PropertyMock(
            side_effect=[status for (output, status) in returns],
        )
        self.mocks.popen.return_value = mock_obj

        with build_env:
            task.build_docs()
        self.assertEqual(self.mocks.popen.call_count, 7)
        self.assertTrue(build_env.successful)
Beispiel #10
0
 def test_save_config_in_build_model(self, load_config, api_v2):
     load_config.side_effect = create_load()
     api_v2.build.get.return_value = {}
     project = get(
         Project,
         slug='project',
         documentation_type='sphinx',
     )
     build = get(Build)
     version = get(Version, slug='1.8', project=project)
     task = UpdateDocsTaskStep(project=project,
                               version=version,
                               build={'id': build.pk})
     task.setup_vcs = mock.Mock()
     task.run_setup()
     build_config = task.build['config']
     # For patch
     api_v2.build.assert_called_once()
     assert build_config['version'] == '1'
     assert 'sphinx' in build_config
     assert build_config['doctype'] == 'sphinx'
 def test_save_config_in_build_model(self, load_config, api_v2):
     load_config.side_effect = create_load()
     api_v2.build.get.return_value = {}
     project = get(
         Project,
         slug='project',
         documentation_type='sphinx',
     )
     build = get(Build)
     version = get(Version, slug='1.8', project=project)
     task = UpdateDocsTaskStep(
         project=project, version=version, build={'id': build.pk},
     )
     task.setup_vcs = mock.Mock()
     task.run_setup()
     build_config = task.build['config']
     # For patch
     api_v2.build.assert_called_once()
     assert build_config['version'] == '1'
     assert 'sphinx' in build_config
     assert build_config['doctype'] == 'sphinx'
Beispiel #12
0
    def test_install_core_requirements_sphinx_system_packages_caps_setuptools(
            self, checkout_path, load_config):
        config_data = {
            'python': {
                'use_system_site_packages': True,
            },
        }
        load_config.side_effect = create_load(config_data)
        config = load_yaml_config(self.version_sphinx)

        tmpdir = tempfile.mkdtemp()
        checkout_path.return_value = tmpdir
        python_env = Virtualenv(
            version=self.version_sphinx,
            build_env=self.build_env_mock,
            config=config,
        )
        python_env.install_core_requirements()
        requirements_sphinx = [
            'commonmark',
            'recommonmark',
            'sphinx',
            'sphinx-rtd-theme',
            'readthedocs-sphinx-ext',
            'setuptools<58.3.0',
        ]

        self.assertEqual(self.build_env_mock.run.call_count, 2)
        calls = self.build_env_mock.run.call_args_list

        core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0']
        self.assertArgsStartsWith(core_args, calls[0])

        requirements = self.base_requirements + requirements_sphinx
        args = self.pip_install_args + ['-I'] + requirements
        self.assertArgsStartsWith(args, calls[1])