|
1 | 1 | # Copyright 2019, Oath Inc. |
2 | 2 | # Licensed under the terms of the Apache 2.0 license. See the LICENSE file in the project root for terms |
| 3 | +import copy |
3 | 4 | import os |
4 | 5 | import tempfile |
5 | 6 | import unittest |
6 | 7 | from pathlib import Path |
| 8 | + |
7 | 9 | import screwdrivercd.documentation.exceptions |
8 | 10 | import screwdrivercd.documentation.plugin |
9 | 11 | import screwdrivercd.documentation.mkdocs.plugin |
|
12 | 14 | from . import ScrewdriverTestCase |
13 | 15 |
|
14 | 16 |
|
| 17 | +# Simple sphinx project directory |
| 18 | +sphinx_project = { |
| 19 | + 'doc/source/conf.py': b"""# -*- coding: utf-8 -*- |
| 20 | +import os |
| 21 | +extensions = [] |
| 22 | +templates_path = ['_templates'] |
| 23 | +source_suffix = '.rst' |
| 24 | +master_doc = 'index' |
| 25 | +project = 'foo' |
| 26 | +copyright = '' |
| 27 | +version = '0.0.0' |
| 28 | +release = version |
| 29 | +""", |
| 30 | + 'doc/source/index.rst': b"""Test file""" |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +mkdocs_project_config = { |
| 35 | + 'mkdocs.yml': b'site_name: test\nstrict: true\nnav:\n - foo: foo.md\n', |
| 36 | + 'docs/index.md': b"# Test file\n", |
| 37 | + 'docs/foo.md': b"# Test file\n", |
| 38 | +} |
| 39 | + |
| 40 | + |
15 | 41 | class PluginsTestCase(ScrewdriverTestCase): |
16 | 42 |
|
17 | 43 | def test__documentation_plugins__present(self): |
@@ -66,14 +92,22 @@ def test_documentation_base_plugin_is_present(self): |
66 | 92 | p = screwdrivercd.documentation.plugin.DocumentationPlugin() |
67 | 93 | self.assertFalse(p.documentation_is_present) |
68 | 94 |
|
69 | | - def test_documentation_base__log_message(self): |
| 95 | + def test_documentation_base__log_message__default(self): |
70 | 96 | p = self.plugin_class() |
71 | 97 | p.build_log_filename = 'foo.log' |
72 | 98 | p._log_message('foo', p.build_log_filename) |
73 | 99 | self.assertTrue(os.path.exists('foo.log')) |
74 | 100 | with open('foo.log') as log: |
75 | 101 | self.assertEqual('foo\n', log.read()) |
76 | 102 |
|
| 103 | + def test_documentation_base__log_message__log_filename(self): |
| 104 | + p = self.plugin_class() |
| 105 | + p.build_log_filename = 'foo2.log' |
| 106 | + p._log_message('foo', log_filename='foo.log') |
| 107 | + self.assertTrue(os.path.exists('foo.log')) |
| 108 | + with open('foo.log') as log: |
| 109 | + self.assertEqual('foo\n', log.read()) |
| 110 | + |
77 | 111 | def test_documentation_base__log_message__pass_end(self): |
78 | 112 | p = self.plugin_class() |
79 | 113 | p._log_message('foo', log_filename='logs/foo.log', end='\r\n') |
@@ -105,6 +139,7 @@ def test_documentation__base__run_command__error(self): |
105 | 139 |
|
106 | 140 | def test__documentation__build(self): |
107 | 141 | self._create_test_repo_contents() |
| 142 | + self.write_config_files(mkdocs_project_config) |
108 | 143 | p = self.plugin_class() |
109 | 144 | p.build_documentation() |
110 | 145 | self.assertTrue(os.path.exists(f'{p.log_dir}/{p.name}.build.log')) |
@@ -153,22 +188,32 @@ def test__copy_contents(self): |
153 | 188 | self.assertTrue(dsttestfile.exists()) |
154 | 189 | self.assertTrue(dsttestdotfile.exists()) |
155 | 190 |
|
| 191 | + def test__documentation__publish(self): |
| 192 | + instance = self.plugin_class() |
| 193 | + instance.publish_documentation(push=False) |
| 194 | + |
156 | 195 |
|
157 | 196 | class SphinxDocumentationPluginTestCase(DocumentationPluginTestCase): |
158 | 197 | plugin_class = screwdrivercd.documentation.sphinx.plugin.SphinxDocumentationPlugin |
159 | 198 |
|
160 | 199 | def _create_test_repo_contents(self): |
161 | | - os.makedirs('doc/source') |
| 200 | + pass |
162 | 201 |
|
163 | 202 | def test__documentation__build(self): |
164 | 203 | pass |
165 | 204 |
|
| 205 | + def test__documentation__publish(self): |
| 206 | + self.write_config_files(sphinx_project) |
| 207 | + super().test__documentation__publish() |
| 208 | + |
166 | 209 |
|
167 | 210 | class MkdocsDocumentationPluginTestCase(DocumentationPluginTestCase): |
168 | 211 | plugin_class = screwdrivercd.documentation.mkdocs.plugin.MkDocsDocumentationPlugin |
169 | 212 |
|
170 | 213 | def _create_test_repo_contents(self): |
171 | | - os.makedirs('docs') |
172 | | - |
173 | | - def test__documentation__build(self): |
174 | 214 | pass |
| 215 | + |
| 216 | + def test__documentation__publish(self): |
| 217 | + self._init_test_repo() |
| 218 | + self.write_config_files(mkdocs_project_config) |
| 219 | + super().test__documentation__publish() |
0 commit comments