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
|
#!/usr/bin/python3
import unittest
import generate_html_cs as generate_html
import subprocess
import lxml.etree as et
import lxml.html
TEST_FILE = "hes12kni.tab"
test_dict = {'no': '1', 'de_name': '1.Mose',
'cs_name': '1.Mojžíšova', 'de_abbr': 'Gn',
'test': '-', 'cs_abbr': 'Gn'}
TEST_LOSUNGEN = "hes12-01.xml"
class TestProcessCSV(unittest.TestCase):
def test_generate_dict(self):
los_dict = generate_html.csv2dict(TEST_FILE)
self.assertEqual(len(los_dict), 78)
self.assertEqual(los_dict['Gn'], test_dict)
class TestMethods(unittest.TestCase):
def test_translate_book_abbrs(self):
"""
Example XML piece:
Description of bug #78:
Czech biblical references are not understood by crosswire
website. So, when I ask for J 6:39, I get a book of Joshua,
not the gospel of John.
"""
test_element_str = '''
<LOSUNG d="24" m="10">
<TL>Středa 24. října 2012</TL>
<OT>
<S b="Ez" ch="34" v="16"/>
<L>Ztracenou vypátrám, zaběhlou přivedu zpět.</L>
<SL>Ezechiel 34,16</SL>
</OT>
<NT>
<S b="J" ch="6" v="39"/>
<L>Jeho vůle jest, abych neztratil nikoho z těch, které mi dal,</L>
<L>ale vzkřísil je v poslední den.</L>
<SL>Jan 6,39</SL>
</NT>
<SR><SL>1.Mojžíšova 24,54b-67</SL></SR>
<CR><SL>2.Korintským 4,1-6</SL></CR>
</LOSUNG>
'''
test_element = et.fromstring(test_element_str)
wword = generate_html.parse_one(test_element)
self.assertEqual(wword['watchwords'][1]['int_ref_id']['book'],'John')
class TestProcessLosungen(unittest.TestCase):
def setUp(self):
self.los_elements = generate_html.parse_file(TEST_LOSUNGEN)
def test_parse_losungen(self):
proc = subprocess.Popen(["tidy", "-e", "-f", "/dev/null"],
stdin=subprocess.PIPE, bufsize=-1, close_fds=True)
proc.communicate(self.los_elements.encode("utf-8"))
self.assertEqual(proc.returncode, 0)
def test_attributes_on_articles(self):
# Every article has to have id attribute
root = lxml.html.fromstring(self.los_elements)
empty_articles = root.xpath("//article[not(@id)]")
self.assertEqual(len(empty_articles), 0)
def test_appropriate_elements(self):
# We need one <script> and one <style> elements in <head>
root = lxml.html.fromstring(self.los_elements)
script_element = root.xpath("//head/script")
self.assertEqual(len(script_element), 1)
self.assertEqual(script_element[0].attrib["src"], "hesla.js")
style_element = root.xpath("//head/link[@rel='stylesheet']")
self.assertEqual(len(style_element), 1)
meta_element = root.xpath("//head/meta[@content]")
self.assertEqual(meta_element[0].attrib["content"],
"width=device-width, initial-scale=1.0, " + \
"maximum-scale=2.0, user-scalable=yes")
if __name__ == '__main__':
unittest.main()
|