def test_build_formats_default_empty( self, append_conf, html_build, checkout_path, config, tmpdir, ): """ The default value for formats is [], which means no extra formats are build. """ checkout_path.return_value = str(tmpdir) self.create_config_file(tmpdir, config) update_docs = self.get_update_docs_task() python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=update_docs.config, ) update_docs.python_env = python_env outcomes = update_docs.build_docs() # No extra formats were triggered assert outcomes['html'] assert not outcomes['localmedia'] assert not outcomes['pdf'] assert not outcomes['epub']
def test_append_conf_existing_yaml_on_root_with_invalid_setting(self, checkout_path, run): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) # We can't use ``@pytest.mark.parametrize`` on a Django test case yaml_contents = [ {'docs_dir': ['docs']}, {'extra_css': 'a string here'}, {'extra_javascript': None}, ] for content in yaml_contents: yaml.safe_dump( content, open(yaml_file, 'w'), ) with self.assertRaises(MkDocsYAMLParseError): self.searchbuilder.append_conf()
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()
def test_get_theme_name_with_feature_flag(self, checkout_path, run): tmpdir = tempfile.mkdtemp() checkout_path.return_value = tmpdir feature = get( Feature, feature_id=Feature.MKDOCS_THEME_RTD, ) feature.projects.add(self.project) python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) builder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.assertEqual(builder.get_theme_name({}), 'readthedocs') with patch('readthedocs.doc_builder.backends.mkdocs.yaml') as mock_yaml: with patch('readthedocs.doc_builder.backends.mkdocs.MkdocsHTML.load_yaml_config') as mock_load_yaml_config: mock_load_yaml_config.return_value = {'site_name': self.project.name} builder.append_conf() mock_yaml.safe_dump.assert_called_once_with( { 'site_name': mock.ANY, 'docs_dir': mock.ANY, 'extra_javascript': mock.ANY, 'extra_css': mock.ANY, 'google_analytics': mock.ANY, 'theme': 'readthedocs', }, mock.ANY, ) mock_yaml.reset_mock() config = { 'theme': 'customtheme', } self.assertEqual(builder.get_theme_name(config), 'customtheme') with patch('readthedocs.doc_builder.backends.mkdocs.MkdocsHTML.load_yaml_config') as mock_load_yaml_config: mock_load_yaml_config.return_value = { 'site_name': self.project.name, 'theme': 'customtheme', } builder.append_conf() mock_yaml.safe_dump.assert_called_once_with( { 'site_name': mock.ANY, 'docs_dir': mock.ANY, 'extra_javascript': mock.ANY, 'extra_css': mock.ANY, 'google_analytics': mock.ANY, 'theme': 'customtheme', }, mock.ANY, )
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_epub_flag(self): '''Test build with epub enabled''' project = get(Project, slug='project-1', documentation_type='sphinx', conf_py_file='test_conf.py', enable_pdf_build=False, enable_epub_build=True, versions=[fixture()]) version = project.versions.all()[0] build_env = LocalEnvironment(project=project, version=version, build={}) python_env = Virtualenv(version=version, build_env=build_env) yaml_config = get_build_config({}) config = ConfigWrapper(version=version, yaml_config=yaml_config) task = UpdateDocsTask(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.epub_build.assert_called_once_with() # PDF however was disabled and therefore not built. self.assertFalse(self.mocks.pdf_build.called)
def test_append_conf_create_yaml(self, checkout_path, run): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.searchbuilder.append_conf() run.assert_called_with('cat', 'mkdocs.yml', cwd=mock.ANY) # There is a mkdocs.yml file created generated_yaml = os.path.join(tmpdir, 'mkdocs.yml') self.assertTrue(os.path.exists(generated_yaml)) config = yaml.safe_load(open(generated_yaml)) self.assertEqual(config['docs_dir'], os.path.join(tmpdir, 'docs')) self.assertEqual(config['extra_css'], [ 'http://readthedocs.org/static/css/badge_only.css', 'http://readthedocs.org/static/css/readthedocs-doc-embed.css' ]) self.assertEqual(config['extra_javascript'], [ 'readthedocs-data.js', 'http://readthedocs.org/static/core/js/readthedocs-doc-embed.js', 'http://readthedocs.org/static/javascript/readthedocs-analytics.js', ]) self.assertIsNone(config['google_analytics'], ) self.assertEqual(config['site_name'], 'mkdocs')
def test_override_theme_new_style(self, checkout_path, run): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') yaml.safe_dump( { 'theme': { 'name': 'readthedocs', }, 'site_name': 'mkdocs', 'docs_dir': 'docs', }, open(yaml_file, 'w')) checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.searchbuilder.append_conf() run.assert_called_with('cat', 'mkdocs.yml', cwd=mock.ANY) config = yaml.safe_load(open(yaml_file)) self.assertEqual( config['theme'], { 'name': 'readthedocs', 'custom_dir': BaseMkdocs.READTHEDOCS_TEMPLATE_OVERRIDE_DIR })
def test_system_packages(self, run, checkout_path, tmpdir): checkout_path.return_value = str(tmpdir) self.create_config_file( tmpdir, { 'python': { 'system_packages': True, }, }, ) update_docs = self.get_update_docs_task() config = update_docs.config python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=config, ) update_docs.python_env = python_env update_docs.python_env.setup_base() args, kwargs = run.call_args assert '--system-site-packages' in args assert config.python.use_system_site_packages
def test_sphinx_configuration_default( self, run, append_conf, move, checkout_path, tmpdir, ): """Should be default to find a conf.py file.""" checkout_path.return_value = str(tmpdir) apply_fs(tmpdir, {'conf.py': ''}) self.create_config_file(tmpdir, {}) self.project.conf_py_file = '' self.project.save() update_docs = self.get_update_docs_task() config = update_docs.config python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=config, ) update_docs.python_env = python_env update_docs.build_docs_html() args, kwargs = run.call_args assert kwargs['cwd'] == str(tmpdir) append_conf.assert_called_once() move.assert_called_once()
def test_python_install_extra_requirements(self, run, checkout_path, tmpdir): checkout_path.return_value = str(tmpdir) self.create_config_file( tmpdir, { 'python': { 'install': [{ 'path': '.', 'method': 'pip', 'extra_requirements': ['docs'], }], }, }) update_docs = self.get_update_docs_task() config = update_docs.config python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=config, ) update_docs.python_env = python_env update_docs.python_env.install_requirements() args, kwargs = run.call_args assert 'install' in args assert '.[docs]' in args install = config.python.install assert len(install) == 1 assert install[0].method == PIP
def test_python_install_requirements(self, run, checkout_path, tmpdir): checkout_path.return_value = str(tmpdir) requirements_file = 'requirements.txt' apply_fs(tmpdir, {requirements_file: ''}) base_path = self.create_config_file( tmpdir, { 'python': { 'install': [{ 'requirements': requirements_file, }], }, }, ) update_docs = self.get_update_docs_task() config = update_docs.config python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=config, ) update_docs.python_env = python_env update_docs.python_env.install_requirements() args, kwargs = run.call_args install = config.python.install assert len(install) == 1 assert install[0].requirements == requirements_file assert requirements_file in args
def test_build_formats_only_pdf( self, append_conf, html_build, build_docs_class, checkout_path, tmpdir, ): """Only the pdf format is build.""" checkout_path.return_value = str(tmpdir) self.create_config_file(tmpdir, {'formats': ['pdf']}) update_docs = self.get_update_docs_task() python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=update_docs.config, ) update_docs.python_env = python_env outcomes = update_docs.build_docs() # Only pdf extra format was triggered assert outcomes['html'] build_docs_class.assert_called_with('sphinx_pdf') assert outcomes['pdf'] assert not outcomes['localmedia'] assert not outcomes['epub']
def test_write_js_data_docs_dir(self, checkout_path, run, generate_rtd_data): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') yaml.safe_dump( { 'site_name': 'mkdocs', 'docs_dir': 'docs', }, open(yaml_file, 'w'), ) checkout_path.return_value = tmpdir generate_rtd_data.return_value = '' python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.searchbuilder.append_conf() generate_rtd_data.assert_called_with( docs_dir='docs', mkdocs_config=mock.ANY, )
def test_build(self): '''Test full build''' 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 = LocalEnvironment(project=project, version=version, build={}) python_env = Virtualenv(version=version, build_env=build_env) yaml_config = get_build_config({}) config = ConfigWrapper(version=version, yaml_config=yaml_config) task = UpdateDocsTask(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_write_js_data_on_invalid_docs_dir(self, checkout_path, generate_rtd_data): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') yaml.safe_dump( { 'site_name': 'mkdocs', 'google_analytics': ['UA-1234-5', 'mkdocs.org'], 'docs_dir': 'invalid_docs_dir', 'extra_css': [ 'http://readthedocs.org/static/css/badge_only.css' ], 'extra_javascript': ['readthedocs-data.js'], }, open(yaml_file, 'w'), ) checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) with self.assertRaises(MkDocsYAMLParseError): self.searchbuilder.append_conf()
def test_dont_override_theme(self, checkout_path, run): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') yaml.safe_dump( { 'theme': 'not-readthedocs', 'theme_dir': 'not-readthedocs', 'site_name': 'mkdocs', 'docs_dir': 'docs', }, open(yaml_file, 'w'), ) checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.searchbuilder.append_conf() run.assert_called_with('cat', 'mkdocs.yml', cwd=mock.ANY) config = yaml.safe_load(open(yaml_file)) self.assertEqual( config['theme_dir'], 'not-readthedocs', )
def test_build_formats_only_html_for_external_versions( self, append_conf, html_build, build_docs_class, checkout_path, tmpdir, ): # Convert to external Version self.version.type = EXTERNAL self.version.save() checkout_path.return_value = str(tmpdir) self.create_config_file(tmpdir, {'formats': ['pdf', 'htmlzip', 'epub']}) update_docs = self.get_update_docs_task() python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=update_docs.config, ) update_docs.python_env = python_env outcomes = update_docs.build_docs() assert outcomes['html'] assert not outcomes['pdf'] assert not outcomes['localmedia'] assert not outcomes['epub']
def test_is_obsolete_with_json_missing_build_hash(self): config_data = { 'build': { 'image': '2.0', 'hash': 'a1b2c3', }, 'python': { 'version': 2.7, }, } yaml_config = create_load(config_data)()[0] config = ConfigWrapper(version=self.version, yaml_config=yaml_config) # Set container_image manually self.pip.container_image = 'readthedocs/build:2.0' self.pip.save() python_env = Virtualenv( version=self.version, build_env=self.build_env, config=config, ) env_json_data = '{"build": {"image": "readthedocs/build:2.0"}, "python": {"version": 2.7}}' # noqa with patch('os.path.exists') as exists, patch( 'readthedocs.doc_builder.python_environments.open', mock_open(read_data=env_json_data)) as _open: # noqa exists.return_value = True self.assertTrue(python_env.is_obsolete)
def test_install_core_requirements_sphinx(self): python_env = Virtualenv( version=self.version_sphinx, build_env=self.build_env_mock, ) python_env.install_core_requirements() requirements_sphinx = [ 'commonmark==0.5.4', 'recommonmark==0.4.0', 'sphinx==1.7.4', 'sphinx-rtd-theme<0.4', 'readthedocs-sphinx-ext<0.6', ] requirements = self.base_requirements + requirements_sphinx args = self.pip_install_args + requirements self.build_env_mock.run.assert_called_once_with(*args, bin_path=mock.ANY)
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')
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], )
def test_append_conf_existing_yaml_on_root(self, checkout_path, run): tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(tmpdir, 'docs')) yaml_file = os.path.join(tmpdir, 'mkdocs.yml') yaml.safe_dump( { 'site_name': 'mkdocs', 'google_analytics': ['UA-1234-5', 'mkdocs.org'], 'docs_dir': 'docs', }, open(yaml_file, 'w') ) checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version, build_env=self.build_env, config=None, ) self.searchbuilder = MkdocsHTML( build_env=self.build_env, python_env=python_env, ) self.searchbuilder.append_conf() run.assert_called_with('cat', 'mkdocs.yml', cwd=mock.ANY) config = yaml.safe_load(open(yaml_file)) self.assertEqual( config['docs_dir'], 'docs' ) self.assertEqual( config['extra_css'], [ 'http://readthedocs.org/static/css/badge_only.css', 'http://readthedocs.org/static/css/readthedocs-doc-embed.css' ] ) self.assertEqual( config['extra_javascript'], [ 'readthedocs-data.js', 'http://readthedocs.org/static/core/js/readthedocs-doc-embed.js', 'http://readthedocs.org/static/javascript/readthedocs-analytics.js', ] ) self.assertIsNone( config['google_analytics'], ) self.assertEqual( config['site_name'], 'mkdocs' )
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_python_install_several_options(self, run, checkout_path, tmpdir): checkout_path.return_value = str(tmpdir) apply_fs(tmpdir, { 'one': {}, 'two': {}, 'three.txt': '', }) self.create_config_file( tmpdir, { 'python': { 'install': [{ 'path': 'one', 'method': 'pip', 'extra_requirements': ['docs'], }, { 'path': 'two', 'method': 'setuptools', }, { 'requirements': 'three.txt', }], }, } ) update_docs = self.get_update_docs_task() config = update_docs.config python_env = Virtualenv( version=self.version, build_env=update_docs.build_env, config=config, ) update_docs.python_env = python_env update_docs.python_env.install_requirements() install = config.python.install assert len(install) == 3 args, kwargs = run.call_args_list[0] assert 'install' in args assert './one[docs]' in args assert install[0].method == PIP args, kwargs = run.call_args_list[1] assert 'two/setup.py' in args assert 'install' in args assert install[1].method == SETUPTOOLS args, kwargs = run.call_args_list[2] assert 'install' in args assert '-r' in args assert 'three.txt' in args
def test_builder_comments(self): '''Normal build with comments''' project = get(Project, documentation_type='sphinx', allow_comments=True, versions=[fixture()]) version = project.versions.all()[0] build_env = LocalEnvironment(version=version, project=project, build={}) python_env = Virtualenv(version=version, build_env=build_env) builder_class = get_builder_class(project.documentation_type) builder = builder_class(build_env, python_env) self.assertEqual(builder.sphinx_builder, 'readthedocs-comments')
def test_is_obsolete_with_invalid_env_json_file(self): yaml_config = create_load()()[0] config = ConfigWrapper(version=self.version, yaml_config=yaml_config) with patch('os.path.exists') as exists: exists.return_value = True python_env = Virtualenv( version=self.version, build_env=self.build_env, config=config, ) self.assertFalse(python_env.is_obsolete)
def test_install_core_requirements_mkdocs(self, checkout_path): tmpdir = tempfile.mkdtemp() checkout_path.return_value = tmpdir python_env = Virtualenv( version=self.version_mkdocs, build_env=self.build_env_mock, ) python_env.install_core_requirements() requirements_mkdocs = [ 'commonmark', 'recommonmark', 'mkdocs', ] 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_mkdocs args = self.pip_install_args + requirements self.assertArgsStartsWith(args, calls[1])
def test_build_pdf_latex_failures(self): '''Build failure if latex fails''' self.mocks.patches['html_build'].stop() self.mocks.patches['pdf_build'].stop() 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] assert project.conf_dir() == '/tmp/rtd' build_env = LocalEnvironment(project=project, version=version, build={}) python_env = Virtualenv(version=version, build_env=build_env) yaml_config = get_build_config({}) config = ConfigWrapper(version=version, yaml_config=yaml_config) task = UpdateDocsTask(build_env=build_env, project=project, python_env=python_env, version=version, search=False, localmedia=False, config=config) # Mock out the separate calls to Popen using an iterable side_effect returns = [ (('', ''), 0), # sphinx-build html (('', ''), 0), # sphinx-build pdf (('', ''), 1), # latex (('', ''), 0), # makeindex (('', ''), 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, 5) self.assertTrue(build_env.failed)