comparison tests/conftest.py @ 2:59fe8cb6190d

Add lots of tests, fix lots of bugs.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 03 Jan 2017 09:05:28 -0800
parents 74b83e3d921e
children ee741bbe96a8
comparison
equal deleted inserted replaced
1:74b83e3d921e 2:59fe8cb6190d
1 import re
1 import sys 2 import sys
2 import logging 3 import logging
3 import yaml 4 import yaml
4 import pytest 5 import pytest
5 from fontaine.document import ( 6 from fontaine.document import (
6 FontaineSceneElement, 7 FontaineSceneElement,
7 TYPE_ACTION, TYPE_CENTEREDACTION, TYPE_CHARACTER, TYPE_DIALOG, 8 TYPE_ACTION, TYPE_CENTEREDACTION, TYPE_CHARACTER, TYPE_DIALOG,
8 TYPE_PARENTHETICAL, TYPE_TRANSITION, TYPE_LYRICS, TYPE_PAGEBREAK, 9 TYPE_PARENTHETICAL, TYPE_TRANSITION, TYPE_LYRICS, TYPE_PAGEBREAK,
10 TYPE_EMPTYLINES,
9 _scene_element_type_str) 11 _scene_element_type_str)
10 from fontaine.parser import FontaineParser, FontaineParserError 12 from fontaine.parser import FontaineParser, FontaineParserError
11 from fontaine.renderer import BaseRenderer
12 13
13 14
14 def pytest_addoption(parser): 15 def pytest_addoption(parser):
15 parser.addoption( 16 parser.addoption(
16 '--log-debug', 17 '--log-debug',
151 else: 152 else:
152 yield ' %s: "%s"' % (_scene_element_type_str(p.type), 153 yield ' %s: "%s"' % (_scene_element_type_str(p.type),
153 p.text) 154 p.text)
154 155
155 156
157 RE_BLANK_LINE = re.compile(r"^\s+$")
158
159
156 def make_scenes(spec): 160 def make_scenes(spec):
157 if not isinstance(spec, list): 161 if not isinstance(spec, list):
158 raise Exception("Script specs must be lists.") 162 raise Exception("Script specs must be lists.")
159 163
160 out = [] 164 out = []
162 cur_paras = [] 166 cur_paras = []
163 167
164 for item in spec: 168 for item in spec:
165 if item == '<pagebreak>': 169 if item == '<pagebreak>':
166 cur_paras.append(FontaineSceneElement(TYPE_PAGEBREAK, None)) 170 cur_paras.append(FontaineSceneElement(TYPE_PAGEBREAK, None))
171 continue
172
173 if RE_BLANK_LINE.match(item):
174 text = len(item) * '\n'
175 cur_paras.append(FontaineSceneElement(TYPE_EMPTYLINES, text))
167 continue 176 continue
168 177
169 token = item[:1] 178 token = item[:1]
170 if token == '.': 179 if token == '.':
171 if cur_header or cur_paras: 180 if cur_header or cur_paras:
191 else: 200 else:
192 raise Exception("Unknown token: %s" % token) 201 raise Exception("Unknown token: %s" % token)
193 if cur_header or cur_paras: 202 if cur_header or cur_paras:
194 out.append([cur_header] + cur_paras) 203 out.append([cur_header] + cur_paras)
195 return out 204 return out
196
197
198 class TestRenderer(BaseRenderer):
199 def write_bold(self, text):
200 pass
201
202 def write_italics(self, text):
203 pass
204
205 def write_underline(self, text):
206 pass