| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Tests for the S5/HTML writer. |
| 9 |
""" |
| 10 |
|
| 11 |
import os |
| 12 |
import platform |
| 13 |
from pathlib import Path |
| 14 |
import sys |
| 15 |
import unittest |
| 16 |
|
| 17 |
if __name__ == '__main__': |
| 18 |
|
| 19 |
|
| 20 |
sys.path.insert(0, str(Path(__file__).resolve().parents[2])) |
| 21 |
|
| 22 |
import docutils |
| 23 |
from docutils.core import publish_string |
| 24 |
from docutils.writers import s5_html |
| 25 |
|
| 26 |
|
| 27 |
class WriterPublishTestCase(unittest.TestCase): |
| 28 |
def test_publish(self): |
| 29 |
settings = { |
| 30 |
'_disable_config': True, |
| 31 |
'strict_visitor': True, |
| 32 |
'stylesheet_path': '/test.css', |
| 33 |
'embed_stylesheet': False, |
| 34 |
'report_level': 3, |
| 35 |
} |
| 36 |
for name, cases in totest_1.items(): |
| 37 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 38 |
with self.subTest(id=f'totest_1[{name!r}][{casenum}]'): |
| 39 |
output = publish_string( |
| 40 |
source=case_input, |
| 41 |
writer=s5_html.Writer(), |
| 42 |
settings_overrides=settings.copy() |
| 43 |
).decode() |
| 44 |
self.assertEqual(case_expected, output) |
| 45 |
|
| 46 |
settings['hidden_controls'] = False |
| 47 |
settings['view_mode'] = 'outline' |
| 48 |
for name, cases in totest_2.items(): |
| 49 |
for casenum, (case_input, case_expected) in enumerate(cases): |
| 50 |
with self.subTest(id=f'totest_2[{name!r}][{casenum}]'): |
| 51 |
output = publish_string( |
| 52 |
source=case_input, |
| 53 |
writer=s5_html.Writer(), |
| 54 |
settings_overrides=settings.copy() |
| 55 |
).decode() |
| 56 |
self.assertEqual(case_expected, output) |
| 57 |
|
| 58 |
|
| 59 |
if platform.system() == "Windows": |
| 60 |
drive_prefix = os.path.splitdrive(os.getcwd())[0] |
| 61 |
else: |
| 62 |
drive_prefix = "" |
| 63 |
|
| 64 |
|
| 65 |
totest_1 = {} |
| 66 |
totest_2 = {} |
| 67 |
|
| 68 |
totest_1['basics'] = [ |
| 69 |
["""\ |
| 70 |
============ |
| 71 |
Show Title |
| 72 |
============ |
| 73 |
|
| 74 |
Title slide |
| 75 |
|
| 76 |
First Slide |
| 77 |
=========== |
| 78 |
|
| 79 |
Slide text. |
| 80 |
""", |
| 81 |
f"""\ |
| 82 |
<?xml version="1.0" encoding="utf-8"?> |
| 83 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 84 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 85 |
<head> |
| 86 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 87 |
<meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> |
| 88 |
<meta name="version" content="S5 1.1" /> |
| 89 |
<title>Show Title</title> |
| 90 |
<link rel="stylesheet" href="{drive_prefix}/test.css" type="text/css" /> |
| 91 |
<!-- configuration parameters --> |
| 92 |
<meta name="defaultView" content="slideshow" /> |
| 93 |
<meta name="controlVis" content="hidden" /> |
| 94 |
<!-- style sheet links --> |
| 95 |
<script src="ui/default/slides.js" type="text/javascript"></script> |
| 96 |
<link rel="stylesheet" href="ui/default/slides.css" |
| 97 |
type="text/css" media="projection" id="slideProj" /> |
| 98 |
<link rel="stylesheet" href="ui/default/outline.css" |
| 99 |
type="text/css" media="screen" id="outlineStyle" /> |
| 100 |
<link rel="stylesheet" href="ui/default/print.css" |
| 101 |
type="text/css" media="print" id="slidePrint" /> |
| 102 |
<link rel="stylesheet" href="ui/default/opera.css" |
| 103 |
type="text/css" media="projection" id="operaFix" /> |
| 104 |
|
| 105 |
<style type="text/css"> |
| 106 |
#currentSlide {{display: none;}} |
| 107 |
</style> |
| 108 |
</head> |
| 109 |
<body> |
| 110 |
<div class="layout"> |
| 111 |
<div id="controls"></div> |
| 112 |
<div id="currentSlide"></div> |
| 113 |
<div id="header"> |
| 114 |
|
| 115 |
</div> |
| 116 |
<div id="footer"> |
| 117 |
<h1>Show Title</h1> |
| 118 |
|
| 119 |
</div> |
| 120 |
</div> |
| 121 |
<div class="presentation"> |
| 122 |
<div class="slide" id="slide0"> |
| 123 |
<h1 class="title">Show Title</h1> |
| 124 |
|
| 125 |
<p>Title slide</p> |
| 126 |
|
| 127 |
</div> |
| 128 |
<div class="slide" id="first-slide"> |
| 129 |
<h1>First Slide</h1> |
| 130 |
<p>Slide text.</p> |
| 131 |
</div> |
| 132 |
</div> |
| 133 |
</body> |
| 134 |
</html> |
| 135 |
"""] |
| 136 |
] |
| 137 |
|
| 138 |
totest_2['settings'] = [ |
| 139 |
["""\ |
| 140 |
================== |
| 141 |
Bogus Slide Show |
| 142 |
================== |
| 143 |
|
| 144 |
We're just checking the settings |
| 145 |
""", |
| 146 |
f"""\ |
| 147 |
<?xml version="1.0" encoding="utf-8"?> |
| 148 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 149 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 150 |
<head> |
| 151 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 152 |
<meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> |
| 153 |
<meta name="version" content="S5 1.1" /> |
| 154 |
<title>Bogus Slide Show</title> |
| 155 |
<link rel="stylesheet" href="{drive_prefix}/test.css" type="text/css" /> |
| 156 |
<!-- configuration parameters --> |
| 157 |
<meta name="defaultView" content="outline" /> |
| 158 |
<meta name="controlVis" content="visible" /> |
| 159 |
<!-- style sheet links --> |
| 160 |
<script src="ui/default/slides.js" type="text/javascript"></script> |
| 161 |
<link rel="stylesheet" href="ui/default/slides.css" |
| 162 |
type="text/css" media="projection" id="slideProj" /> |
| 163 |
<link rel="stylesheet" href="ui/default/outline.css" |
| 164 |
type="text/css" media="screen" id="outlineStyle" /> |
| 165 |
<link rel="stylesheet" href="ui/default/print.css" |
| 166 |
type="text/css" media="print" id="slidePrint" /> |
| 167 |
<link rel="stylesheet" href="ui/default/opera.css" |
| 168 |
type="text/css" media="projection" id="operaFix" /> |
| 169 |
|
| 170 |
<style type="text/css"> |
| 171 |
#currentSlide {{display: none;}} |
| 172 |
</style> |
| 173 |
</head> |
| 174 |
<body> |
| 175 |
<div class="layout"> |
| 176 |
<div id="controls"></div> |
| 177 |
<div id="currentSlide"></div> |
| 178 |
<div id="header"> |
| 179 |
|
| 180 |
</div> |
| 181 |
<div id="footer"> |
| 182 |
<h1>Bogus Slide Show</h1> |
| 183 |
|
| 184 |
</div> |
| 185 |
</div> |
| 186 |
<div class="presentation"> |
| 187 |
<div class="slide" id="slide0"> |
| 188 |
<h1 class="title">Bogus Slide Show</h1> |
| 189 |
|
| 190 |
<p>We're just checking the settings</p> |
| 191 |
</div> |
| 192 |
</div> |
| 193 |
</body> |
| 194 |
</html> |
| 195 |
"""] |
| 196 |
] |
| 197 |
|
| 198 |
if __name__ == '__main__': |
| 199 |
unittest.main() |