Ejemplo n.º 1
0
    def test_build_tools(self, load_config, build_run):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'os': 'ubuntu-20.04',
                    'tools': {
                        'python': '3.10',
                        'nodejs': '16',
                        'rust': '1.55',
                        'golang': '1.17',
                    },
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_config.return_value = config

        version = self.project.versions.first()
        build = get(
            Build,
            project=self.project,
            version=version,
        )
        with mock_api(self.repo):
            result = tasks.update_docs_task.delay(
                version.pk,
                build_pk=build.pk,
                record=False,
                intersphinx=False,
            )
        self.assertTrue(result.successful())
        self.assertEqual(build_run.call_count, 14)

        python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python']['3.10']
        nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs']['16']
        rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust']['1.55']
        golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang']['1.17']
        self.assertEqual(
            build_run.call_args_list,
            [
                mock.call('asdf', 'install', 'python', python_version),
                mock.call('asdf', 'global', 'python', python_version),
                mock.call('asdf', 'reshim', 'python', record=False),
                mock.call('python', '-mpip', 'install', '-U', 'virtualenv', 'setuptools'),
                mock.call('asdf', 'install', 'nodejs', nodejs_version),
                mock.call('asdf', 'global', 'nodejs', nodejs_version),
                mock.call('asdf', 'reshim', 'nodejs', record=False),
                mock.call('asdf', 'install', 'rust', rust_version),
                mock.call('asdf', 'global', 'rust', rust_version),
                mock.call('asdf', 'reshim', 'rust', record=False),
                mock.call('asdf', 'install', 'golang', golang_version),
                mock.call('asdf', 'global', 'golang', golang_version),
                mock.call('asdf', 'reshim', 'golang', record=False),
                mock.ANY,
            ],
        )
Ejemplo n.º 2
0
 def _config_file(self, config):
     config = BuildConfigV2(
         {},
         config,
         source_file='readthedocs.yaml',
     )
     config.validate()
     return config
Ejemplo n.º 3
0
    def test_install_apt_packages(self, load_config, run):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'apt_packages': [
                        'clangd',
                        'cmatrix',
                    ],
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_config.return_value = config

        version = self.project.versions.first()
        build = get(
            Build,
            project=self.project,
            version=version,
        )
        with mock_api(self.repo):
            result = tasks.update_docs_task.delay(
                version.pk,
                build_pk=build.pk,
                record=False,
                intersphinx=False,
            )
        self.assertTrue(result.successful())

        self.assertEqual(run.call_count, 2)
        apt_update = run.call_args_list[0]
        apt_install = run.call_args_list[1]
        self.assertEqual(
            apt_update,
            mock.call(
                'apt-get',
                'update',
                '--assume-yes',
                '--quiet',
                user='******',
            )
        )
        self.assertEqual(
            apt_install,
            mock.call(
                'apt-get',
                'install',
                '--assume-yes',
                '--quiet',
                '--',
                'clangd',
                'cmatrix',
                user='******',
            )
        )
Ejemplo n.º 4
0
    def test_build_tools(self, load_yaml_config):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'os': 'ubuntu-20.04',
                    'tools': {
                        'python': '3.10',
                        'nodejs': '16',
                        'rust': '1.55',
                        'golang': '1.17',
                    },
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_yaml_config.return_value = config

        self._trigger_update_docs_task()

        python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python'][
            '3.10']
        nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs'][
            '16']
        rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust'][
            '1.55']
        golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang'][
            '1.17']
        self.mocker.mocks['environment.run'].assert_has_calls([
            mock.call('asdf', 'install', 'python', python_version),
            mock.call('asdf', 'global', 'python', python_version),
            mock.call('asdf', 'reshim', 'python', record=False),
            mock.call('python', '-mpip', 'install', '-U', 'virtualenv',
                      'setuptools<58.3.0'),
            mock.call('asdf', 'install', 'nodejs', nodejs_version),
            mock.call('asdf', 'global', 'nodejs', nodejs_version),
            mock.call('asdf', 'reshim', 'nodejs', record=False),
            mock.call('asdf', 'install', 'rust', rust_version),
            mock.call('asdf', 'global', 'rust', rust_version),
            mock.call('asdf', 'reshim', 'rust', record=False),
            mock.call('asdf', 'install', 'golang', golang_version),
            mock.call('asdf', 'global', 'golang', golang_version),
            mock.call('asdf', 'reshim', 'golang', record=False),
            mock.ANY,
        ])
Ejemplo n.º 5
0
    def test_install_apt_packages(self, load_yaml_config):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'apt_packages': [
                        'clangd',
                        'cmatrix',
                    ],
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_yaml_config.return_value = config

        self._trigger_update_docs_task()

        self.mocker.mocks['environment.run'].assert_has_calls([
            mock.call(
                'apt-get',
                'update',
                '--assume-yes',
                '--quiet',
                user='******',
            ),
            mock.call(
                'apt-get',
                'install',
                '--assume-yes',
                '--quiet',
                '--',
                'clangd',
                'cmatrix',
                user='******',
            )
        ])
Ejemplo n.º 6
0
    def test_build_tools_cached(self, load_config, build_run, build_tools_storage, tarfile):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'os': 'ubuntu-20.04',
                    'tools': {
                        'python': '3.10',
                        'nodejs': '16',
                        'rust': '1.55',
                        'golang': '1.17',
                    },
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_config.return_value = config

        build_tools_storage.open.return_value = b''
        build_tools_storage.exists.return_value = True
        tarfile.open.return_value.__enter__.return_value.extract_all.return_value = None

        version = self.project.versions.first()
        build = get(
            Build,
            project=self.project,
            version=version,
        )
        with mock_api(self.repo):
            result = tasks.update_docs_task.delay(
                version.pk,
                build_pk=build.pk,
                record=False,
                intersphinx=False,
            )
        self.assertTrue(result.successful())
        self.assertEqual(build_run.call_count, 13)

        python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python']['3.10']
        nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs']['16']
        rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust']['1.55']
        golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang']['1.17']
        self.assertEqual(
            # NOTE: casting the first argument as `list()` shows a better diff
            # explaining where the problem is
            list(build_run.call_args_list),
            [
                mock.call(
                    'mv',
                    # Use mock.ANY here because path differs when ran locally
                    # and on CircleCI
                    mock.ANY,
                    f'/home/docs/.asdf/installs/python/{python_version}',
                    record=False,
                ),
                mock.call('asdf', 'global', 'python', python_version),
                mock.call('asdf', 'reshim', 'python', record=False),
                mock.call(
                    'mv',
                    mock.ANY,
                    f'/home/docs/.asdf/installs/nodejs/{nodejs_version}',
                    record=False,
                ),
                mock.call('asdf', 'global', 'nodejs', nodejs_version),
                mock.call('asdf', 'reshim', 'nodejs', record=False),
                mock.call(
                    'mv',
                    mock.ANY,
                    f'/home/docs/.asdf/installs/rust/{rust_version}',
                    record=False,
                ),
                mock.call('asdf', 'global', 'rust', rust_version),
                mock.call('asdf', 'reshim', 'rust', record=False),
                mock.call(
                    'mv',
                    mock.ANY,
                    f'/home/docs/.asdf/installs/golang/{golang_version}',
                    record=False,
                ),
                mock.call('asdf', 'global', 'golang', golang_version),
                mock.call('asdf', 'reshim', 'golang', record=False),
                mock.ANY,
            ],
        )
Ejemplo n.º 7
0
    def test_build_tools_cached(self, load_yaml_config, build_tools_storage,
                                tarfile):
        config = BuildConfigV2(
            {},
            {
                'version': 2,
                'build': {
                    'os': 'ubuntu-20.04',
                    'tools': {
                        'python': '3.10',
                        'nodejs': '16',
                        'rust': '1.55',
                        'golang': '1.17',
                    },
                },
            },
            source_file='readthedocs.yml',
        )
        config.validate()
        load_yaml_config.return_value = config

        build_tools_storage.open.return_value = b''
        build_tools_storage.exists.return_value = True
        tarfile.open.return_value.__enter__.return_value.extract_all.return_value = None

        self._trigger_update_docs_task()

        python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python'][
            '3.10']
        nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs'][
            '16']
        rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust'][
            '1.55']
        golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang'][
            '1.17']
        self.mocker.mocks['environment.run'].assert_has_calls([
            mock.call(
                'mv',
                # Use mock.ANY here because path differs when ran locally
                # and on CircleCI
                mock.ANY,
                f'/home/docs/.asdf/installs/python/{python_version}',
                record=False,
            ),
            mock.call('asdf', 'global', 'python', python_version),
            mock.call('asdf', 'reshim', 'python', record=False),
            mock.call(
                'mv',
                mock.ANY,
                f'/home/docs/.asdf/installs/nodejs/{nodejs_version}',
                record=False,
            ),
            mock.call('asdf', 'global', 'nodejs', nodejs_version),
            mock.call('asdf', 'reshim', 'nodejs', record=False),
            mock.call(
                'mv',
                mock.ANY,
                f'/home/docs/.asdf/installs/rust/{rust_version}',
                record=False,
            ),
            mock.call('asdf', 'global', 'rust', rust_version),
            mock.call('asdf', 'reshim', 'rust', record=False),
            mock.call(
                'mv',
                mock.ANY,
                f'/home/docs/.asdf/installs/golang/{golang_version}',
                record=False,
            ),
            mock.call('asdf', 'global', 'golang', golang_version),
            mock.call('asdf', 'reshim', 'golang', record=False),
            mock.ANY,
        ])