#!/usr/bin/python3
import unittest
import generate_html_cs as generate_html
import subprocess
import xml.etree.ElementTree 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 = '''
Středa 24. října 2012
Ztracenou vypátrám, zaběhlou přivedu zpět.
Ezechiel 34,16
Jeho vůle jest, abych neztratil nikoho z těch, které mi dal,
ale vzkřísil je v poslední den.
Jan 6,39
1.Mojžíšova 24,54b-67
2.Korintským 4,1-6
'''
test_element = et.fromstring(test_element_str)
wword = generate_html.parse_losung(test_element)
self.assertEqual(wword[1]['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())
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