forked from dag/vlasisku
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.py
82 lines (65 loc) · 2.7 KB
/
tests.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
#-*- coding:utf-8 -*-
from nose.tools import istest as test, \
assert_equal as same, \
assert_not_equal as differ
from vlasisku import app
from vlasisku.extensions import database
from vlasisku.utils import compound2affixes, parse_query
from vlasisku.database import tex2html, braces2links
app.debug = False
client = app.test_client()
def something(value):
assert value is not None, '%s is None' % value
def nothing(value):
assert value is None, '%s is not None' % value
@test
def sets_etag():
"""Sets an ETag header for index and query pages"""
something(client.get('/').get_etag()[0])
something(client.get('/coi').get_etag()[0])
@test
def sensitive_to_if_none_match_header():
"""Sends a 304 if ETags match"""
index = client.get('/', headers={'If-None-Match': app.config['ETAG']})
query = client.get('/coi', headers={'If-None-Match': app.config['ETAG']})
same(index.status_code, 304)
same(query.status_code, 304)
@test
def compound2affixes_splits_compounds():
"""The compound2affixes util splits compounds into affixes"""
same(compound2affixes('jbobau'), ['jbo', 'bau'])
same(compound2affixes('lobybau'), ['lob', 'y', 'bau'])
same(compound2affixes('jbobangu'), ['jbo', 'bangu'])
same(compound2affixes('lojbybau'), ['lojb', 'y', 'bau'])
same(compound2affixes('lobybangu'), ['lob', 'y', 'bangu'])
same(compound2affixes('lojbybangu'), ['lojb', 'y', 'bangu'])
same(compound2affixes("ro'inre'o"), ["ro'i", 'n', "re'o"])
@test
def tex2html_does_math():
"""The tex2html util handles basic math"""
same(tex2html('$x_1$'), 'x<sub>1</sub>')
same(tex2html('$10^2$'), '10<sup>2</sup>')
same(tex2html('$1*10$'), u'1×10')
@test
def tex2html_does_typography():
"""The tex2html util handles basic typography"""
same(tex2html(r'\emph{coi}'), '<em>coi</em>')
same(tex2html(r'\textbf{coi}'), '<strong>coi</strong>')
@test
def braces2links_does_known_words():
"""The braces2links util handles known words"""
same(braces2links('{coi}', database.root.entries),
'<a href="coi" title="vocative: greetings/hello.">coi</a>')
@test
def braces2links_does_unknown_words():
"""The braces2links util links jbovlaste for unknown words"""
same(braces2links('{unknown}', database.root.entries),
'<a href='
'"http://jbovlaste.lojban.org/dict/addvalsi.html?valsi=unknown" '
'title="This word is missing, please add it!" class="missing">'
'unknown</a>')
@test
def parse_query_splits_queries():
"""The parse_query util links fields to lists of tokens"""
same(parse_query('class:BAI event affix:bau'),
{'class': ['BAI'], 'all': ['event'], 'affix': ['bau']})