/
test_github_issues.py
312 lines (259 loc) · 11.5 KB
/
test_github_issues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import textile
def test_github_issue_16():
result = textile.textile('"$":http://google.com "$":https://google.com "$":mailto:blackhole@sun.comet')
expect = '\t<p><a href="http://google.com">google.com</a> <a href="https://google.com">google.com</a> <a href="mailto:blackhole%40sun.comet">blackhole@sun.comet</a></p>'
assert result == expect
def test_github_issue_17():
result = textile.textile('!http://www.ox.ac.uk/favicon.ico!')
expect = '\t<p><img alt="" src="http://www.ox.ac.uk/favicon.ico" /></p>'
assert result == expect
def test_github_issue_20():
text = 'This is a link to a ["Wikipedia article about Textile":http://en.wikipedia.org/wiki/Textile_(markup_language)].'
result = textile.textile(text)
expect = '\t<p>This is a link to a <a href="http://en.wikipedia.org/wiki/Textile_%28markup_language%29">Wikipedia article about Textile</a>.</p>'
assert result == expect
def test_github_issue_21():
text = '''h1. xml example
bc.
<foo>
bar
</foo>'''
result = textile.textile(text)
expect = '\t<h1>xml example</h1>\n\n<pre><code>\n<foo>\n bar\n</foo></code></pre>'
assert result == expect
def test_github_issue_22():
text = '''_(artist-name)Ty Segall_’s'''
result = textile.textile(text)
expect = '\t<p><em class="artist-name">Ty Segall</em>’s</p>'
assert result == expect
def test_github_issue_26():
text = ''
result = textile.textile(text)
expect = ''
assert result == expect
def test_github_issue_27():
test = """* Folders with ":" in their names are displayed with a forward slash "/" instead. (Filed as "#4581709":/test/link, which was considered "normal behaviour" - quote: "Please note that Finder presents the 'Carbon filesystem' view, regardless of the underlying filesystem.")"""
result = textile.textile(test)
expect = """\t<ul>\n\t\t<li>Folders with “:” in their names are displayed with a forward slash “/” instead. (Filed as <a href="/test/link">#4581709</a>, which was considered “normal behaviour” – quote: “Please note that Finder presents the ‘Carbon filesystem’ view, regardless of the underlying filesystem.”)</li>\n\t</ul>"""
assert result == expect
def test_github_issue_28():
test = """So here I am porting my ancient "newspipe":newspipe "front-end":blog/2006/09/30/0950 to "Snakelets":Snakelets and "Python":Python, and I've just trimmed down over 20 lines of "PHP":PHP down to essentially one line of "BeautifulSoup":BeautifulSoup retrieval:
<pre>
def parseWapProfile(self, url):
result = fetch.fetchURL(url)
soup = BeautifulStoneSoup(result['data'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
try:
width, height = soup('prf:screensize')[0].contents[0].split('x')
except:
width = height = None
return {"width": width, "height": height}
</pre>
Of course there's a lot more error handling to do (and useful data to glean off the "XML":XML), but being able to cut through all the usual parsing crap is immensely gratifying."""
result = textile.textile(test)
expect = ("""\t<p>So here I am porting my ancient <a href="newspipe">newspipe</a> <a href="blog/2006/09/30/0950">front-end</a> to <a href="Snakelets">Snakelets</a> and <a href="Python">Python</a>, and I’ve just trimmed down over 20 lines of <a href="PHP"><span class="caps">PHP</span></a> down to essentially one line of <a href="BeautifulSoup">BeautifulSoup</a> retrieval:</p>
<pre>
def parseWapProfile(self, url):
result = fetch.fetchURL(url)
soup = BeautifulStoneSoup(result['data'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
try:
width, height = soup('prf:screensize')[0].contents[0].split('x')
except:
width = height = None
return {"width": width, "height": height}
</pre>
\t<p>Of course there’s a lot more error handling to do (and useful data to glean off the <a href="XML"><span class="caps">XML</span></a>), but being able to cut through all the usual parsing crap is immensely gratifying.</p>""")
assert result == expect
def test_github_issue_30():
text ='"Tëxtíle (Tëxtíle)":http://lala.com'
result = textile.textile(text)
expect = '\t<p><a href="http://lala.com" title="Tëxtíle">Tëxtíle</a></p>'
assert result == expect
def test_github_issue_36():
text = '"Chögyam Trungpa":https://www.google.com/search?q=Chögyam+Trungpa'
result = textile.textile(text)
expect = '\t<p><a href="https://www.google.com/search?q=Chögyam+Trungpa">Chögyam Trungpa</a></p>'
assert result == expect
def test_github_issue_37():
text = '# xxx\n# yyy\n*blah*'
result = textile.textile(text)
expect = '\t<p>\t<ol>\n\t\t<li>xxx</li>\n\t\t<li>yyy</li>\n\t</ol><br />\n<strong>blah</strong></p>'
assert result == expect
text = '*Highlights*\n\n* UNITEK Y-3705A Type-C Universal DockingStation Pro\n* USB3.0/RJ45/EARPHONE/MICROPHONE/HDMI 6 PORT HUB 1.2m Data Cable 5V 4A Power Adaptor\n*\n* Dimensions: 25cm x 13cm x 9cm\n* Weight: 0.7kg'
result = textile.textile(text)
expect = '''\t<p><strong>Highlights</strong></p>
\t<ul>
\t\t<li><span class="caps">UNITEK</span> Y-3705A Type-C Universal DockingStation Pro</li>
\t\t<li>USB3.0/RJ45/EARPHONE/MICROPHONE/HDMI 6 <span class="caps">PORT</span> <span class="caps">HUB</span> 1.2m Data Cable 5V 4A Power Adaptor</li>
\t</ul>
*
\t<ul>
\t\t<li>Dimensions: 25cm x 13cm x 9cm</li>
\t\t<li>Weight: 0.7kg</li>
\t</ul>'''
assert result == expect
def test_github_issue_40():
text = '\r\n'
result = textile.textile(text)
expect = '\r\n'
assert result == expect
def test_github_issue_42():
text = '!./image.png!'
result = textile.textile(text)
expect = '\t<p><img alt="" src="./image.png" /></p>'
assert result == expect
def test_github_issue_43():
text = 'pre. smart ‘quotes’ are not smart!'
result = textile.textile(text)
expect = '<pre>smart ‘quotes’ are not smart!</pre>'
assert result == expect
def test_github_issue_45():
"""Incorrect transform unicode url"""
text = '"test":https://myabstractwiki.ru/index.php/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0'
result = textile.textile(text)
expect = '\t<p><a href="https://myabstractwiki.ru/index.php/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0">test</a></p>'
assert result == expect
def test_github_issue_46():
"""Key error on mal-formed numbered lists. CAUTION: both the input and the
ouput are ugly."""
text = '# test\n### test\n## test'
expect = ('\t<ol>\n\t\t<li>test\n\t\t\t<ol>\n\t\t\t\t<li>test</li>'
'\n\t\t\t</ol></li>\n\t\t<ol>\n\t\t\t<li>test</li>'
'\n\t\t</ol></li>\n\t\t</ol>')
result = textile.textile(text)
assert result == expect
def test_github_issue_47():
"""Incorrect wrap pre-formatted value"""
text = '''pre.. word
another
word
yet anothe word'''
result = textile.textile(text)
expect = '''<pre>word
another
word
yet anothe word</pre>'''
assert result == expect
def test_github_issue_49():
"""Key error on russian hash-route link"""
s = '"link":https://ru.vuejs.org/v2/guide/components.html#Входные-параметры'
result = textile.textile(s)
expect = '\t<p><a href="https://ru.vuejs.org/v2/guide/components.html#Входные-параметры">link</a></p>'
assert result == expect
def test_github_issue_50():
"""Incorrect wrap code with Java generics in pre"""
test = ('pre.. public class Tynopet<T extends Framework> {}\n\nfinal '
'List<List<String>> multipleList = new ArrayList<>();')
result = textile.textile(test)
expect = ('<pre>public class Tynopet<T extends Framework> {}\n\n'
'final List<List<String>> multipleList = new '
'ArrayList<>();</pre>')
assert result == expect
def test_github_issue_51():
"""Link build with $ sign without "http" prefix broken."""
test = '"$":www.google.com.br'
result = textile.textile(test)
expect = '\t<p><a href="www.google.com.br">www.google.com.br</a></p>'
assert result == expect
def test_github_issue_52():
"""Table build without space after aligment raise a AttributeError."""
test = '|=.First Header |=. Second Header |'
result = textile.textile(test)
expect = ('\t<table>\n\t\t<tr>\n\t\t\t<td>=.First Header '
'</td>\n\t\t\t<td style="text-align:center;">Second Header </td>'
'\n\t\t</tr>\n\t</table>')
assert result == expect
def test_github_issue_55():
"""Incorrect handling of quote entities in extended pre block"""
test = ('pre.. this is the first line\n\nbut "quotes" in an extended pre '
'block need to be handled properly.')
result = textile.textile(test)
expect = ('<pre>this is the first line\n\nbut "quotes" in an '
'extended pre block need to be handled properly.</pre>')
assert result == expect
# supplied input
test = ('''pre.. import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.onyma.job.Context;
import ru.onyma.job.RescheduleTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @author ustits
*/
public abstract class MainService<T> extends RescheduleTask implements Context<T> {
private static final Logger log = LoggerFactory.getLogger(MainService.class);
private final ScheduledExecutorService scheduler;
private boolean isFirstRun = true;
private T configs;
public MainService(final ScheduledExecutorService scheduler) {
super(scheduler);
this.scheduler = scheduler;
}
@Override
public void setConfig(final T configs) {
this.configs = configs;
if (isFirstRun) {
scheduler.schedule(this, 0, TimeUnit.SECONDS);
isFirstRun = false;
}
}
@Override
public void stop() {
super.stop();
scheduler.shutdown();
try {
scheduler.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException ie) {
log.warn("Unable to wait for syncs termination", ie);
Thread.currentThread().interrupt();
}
}
protected final T getConfigs() {
return configs;
}
}''')
result = textile.textile(test)
expect = ('''<pre>import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.onyma.job.Context;
import ru.onyma.job.RescheduleTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @author ustits
*/
public abstract class MainService<T> extends RescheduleTask implements Context<T> {
private static final Logger log = LoggerFactory.getLogger(MainService.class);
private final ScheduledExecutorService scheduler;
private boolean isFirstRun = true;
private T configs;
public MainService(final ScheduledExecutorService scheduler) {
super(scheduler);
this.scheduler = scheduler;
}
@Override
public void setConfig(final T configs) {
this.configs = configs;
if (isFirstRun) {
scheduler.schedule(this, 0, TimeUnit.SECONDS);
isFirstRun = false;
}
}
@Override
public void stop() {
super.stop();
scheduler.shutdown();
try {
scheduler.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException ie) {
log.warn("Unable to wait for syncs termination", ie);
Thread.currentThread().interrupt();
}
}
protected final T getConfigs() {
return configs;
}
}</pre>''')
assert result == expect