Пример #1
0
    def test_multiple_conf_py(
        self,
        checkout_path,
        get_conf_py_path,
        _,
        get_config_params,
        create_index,
        docs_dir,
    ):
        """
        Test for a project with multiple ``conf.py`` files.

        An error should be raised to the user if we can't
        guess the correct conf.py file.
        """

        tmp_docs_dir = py.path.local(tempfile.mkdtemp())
        tmp_docs_dir.join('conf.py').write('')
        tmp_docs_dir.join('test').mkdir().join('conf.py').write('')
        docs_dir.return_value = str(tmp_docs_dir)
        checkout_path.return_value = str(tmp_docs_dir)
        create_index.return_value = 'README.rst'
        get_config_params.return_value = {}
        get_conf_py_path.side_effect = ProjectConfigurationError
        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,
        )
        with pytest.raises(ProjectConfigurationError):
            base_sphinx.append_conf()
Пример #2
0
    def test_conf_py_path(self, checkout_path, docs_dir):
        """
        Test the conf_py_path that is added to the conf.py file.

        This value is used from the theme and footer
        to build the ``View`` and ``Edit`` on link.
        """
        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        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,
        )

        for value, expected in (('conf.py', '/'), ('docs/conf.py', '/docs/')):
            base_sphinx.config_file = os.path.join(
                tmp_dir,
                value,
            )
            params = base_sphinx.get_config_params()
            self.assertEqual(
                params['conf_py_path'],
                expected,
            )
    def test_conf_py_path(self, checkout_path, docs_dir):
        """
        Test the conf_py_path that is added to the conf.py file.

        This value is used from the theme and footer
        to build the ``View`` and ``Edit`` on link.
        """
        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        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,
        )

        for value, expected in (('conf.py', '/'), ('docs/conf.py', '/docs/')):
            base_sphinx.config_file = os.path.join(
                tmp_dir, value,
            )
            params = base_sphinx.get_config_params()
            self.assertEqual(
                params['conf_py_path'],
                expected,
            )
    def test_multiple_conf_py(
            self, checkout_path, get_conf_py_path, _, get_config_params,
            create_index, docs_dir,
    ):
        """
        Test for a project with multiple ``conf.py`` files.

        An error should be raised to the user if we can't
        guess the correct conf.py file.
        """

        tmp_docs_dir = py.path.local(tempfile.mkdtemp())
        tmp_docs_dir.join('conf.py').write('')
        tmp_docs_dir.join('test').mkdir().join('conf.py').write('')
        docs_dir.return_value = str(tmp_docs_dir)
        checkout_path.return_value = str(tmp_docs_dir)
        create_index.return_value = 'README.rst'
        get_config_params.return_value = {}
        get_conf_py_path.side_effect = ProjectConfigurationError
        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,
        )
        with pytest.raises(ProjectConfigurationError):
            base_sphinx.append_conf()
Пример #5
0
class SphinxBuilderTest(TestCase):

    fixtures = ['test_data']

    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

        BaseSphinx.type = 'base'
        BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
        self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)

    @patch(
        'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
        '/tmp/sphinx-template-dir',
    )
    @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
    @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index')
    @patch(
        'readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
    @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):
        """
        Test for a project without ``conf.py`` file.

        When this happen, the ``get_conf_py_path`` raises a
        ``ProjectConfigurationError`` which is captured by our own code and
        generates a conf.py file based using our own template.

        This template should be properly rendered in Python2 and Python3 without
        any kind of exception raised by ``append_conf`` (we were originally
        having a ``TypeError`` because of an encoding problem in Python3)
        """
        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()
        try:
            self.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')
        with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
            self.assertEqual(gf.read(), ef.read())
Пример #6
0
    def test_create_conf_py(
        self,
        checkout_path,
        get_conf_py_path,
        _,
        get_config_params,
        create_index,
        docs_dir,
    ):
        """
        Test for a project without ``conf.py`` file.

        When this happen, the ``get_conf_py_path`` raises a
        ``ProjectConfigurationError`` which is captured by our own code and
        generates a conf.py file based using our own template.

        This template should be properly rendered in Python2 and Python3 without
        any kind of exception raised by ``append_conf`` (we were originally
        having a ``TypeError`` because of an encoding problem in Python3)
        """
        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        create_index.return_value = 'README.rst'
        get_config_params.return_value = {}
        get_conf_py_path.side_effect = ProjectConfigurationError
        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:
            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(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:
            autogenerated_confpy_lines = 28
            self.assertEqual(
                gf.readlines()[:autogenerated_confpy_lines],
                ef.readlines()[:autogenerated_confpy_lines],
            )
class SphinxBuilderTest(TestCase):

    fixtures = ['test_data']

    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

        BaseSphinx.type = 'base'
        BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
        self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)

    @patch(
        'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
        '/tmp/sphinx-template-dir',
    )
    @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
    @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.create_index')
    @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
    @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):
        """
        Test for a project without ``conf.py`` file.

        When this happen, the ``get_conf_py_path`` raises a
        ``ProjectConfigurationError`` which is captured by our own code and
        generates a conf.py file based using our own template.

        This template should be properly rendered in Python2 and Python3 without
        any kind of exception raised by ``append_conf`` (we were originally
        having a ``TypeError`` because of an encoding problem in Python3)
        """
        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()
        try:
            self.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')
        with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
            self.assertEqual(gf.read(), ef.read())
Пример #8
0
    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

        BaseSphinx.type = 'base'
        BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
        self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)
    def test_create_conf_py(
            self, checkout_path, get_conf_py_path, _,
            get_config_params, create_index, docs_dir,
    ):
        """
        Test for a project without ``conf.py`` file.

        When this happen, the ``get_conf_py_path`` raises a
        ``ProjectConfigurationError`` which is captured by our own code and
        generates a conf.py file based using our own template.

        This template should be properly rendered in Python2 and Python3 without
        any kind of exception raised by ``append_conf`` (we were originally
        having a ``TypeError`` because of an encoding problem in Python3)
        """
        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        create_index.return_value = 'README.rst'
        get_config_params.return_value = {}
        get_conf_py_path.side_effect = ProjectConfigurationError
        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:
            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(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:
            autogenerated_confpy_lines = 28
            self.assertEqual(
                gf.readlines()[:autogenerated_confpy_lines],
                ef.readlines()[:autogenerated_confpy_lines],
            )
Пример #10
0
    def test_html_context_only_has_public_versions(
        self,
        checkout_path,
        get_conf_py_path,
        docs_dir,
        api_project,
        api_version,
    ):
        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        get_conf_py_path.side_effect = ProjectConfigurationError

        api_version.version().get.return_value = {'downloads': []}
        api_project.project().active_versions.get.return_value = {
            'versions': [
                {
                    'slug': 'v1',
                    'privacy_level': PUBLIC,
                },
                {
                    'slug': 'v2',
                    'privacy_level': PUBLIC,
                },
                {
                    'slug': 'v3',
                    'privacy_level': PRIVATE,
                },
                {
                    'slug': 'latest',
                    'privacy_level': PRIVATE,
                },
            ],
        }

        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,
        )
        base_sphinx.config_file = tempfile.mktemp()
        context = base_sphinx.get_config_params()
        versions = {v.slug for v in context['versions']}
        self.assertEqual(versions, {'v1', 'v2'})
    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

        BaseSphinx.type = 'base'
        BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
        self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)
Пример #12
0
    def test_conf_py_external_version(self, checkout_path, docs_dir):
        self.version.type = EXTERNAL
        self.version.verbose_name = '123'
        self.version.save()

        tmp_dir = tempfile.mkdtemp()
        checkout_path.return_value = tmp_dir
        docs_dir.return_value = tmp_dir
        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,
        )

        base_sphinx.config_file = os.path.join(tmp_dir, 'config.py')
        params = base_sphinx.get_config_params()
        self.assertEqual(params['current_version'], '123')
        self.assertEqual(params['version'], self.version)
        self.assertEqual(params['build_url'],
                         'https://readthedocs.org/projects/pip/builds/123/')