diff options
Diffstat (limited to 'test_generate_html.py')
-rw-r--r-- | test_generate_html.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test_generate_html.py b/test_generate_html.py new file mode 100644 index 0000000..eb5a0f8 --- /dev/null +++ b/test_generate_html.py @@ -0,0 +1,56 @@ +#!/usr/bin/python +# coding: utf-8 +from __future__ import absolute_import, print_function, unicode_literals + +import unittest +import generate_html +import subprocess +import lxml.etree as et + +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 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) + # Generated HTML is missing DOCTYPE, so we get some warnings + self.assertLessEqual(proc.returncode, 1) + + def test_attributes_on_articles(self): + # Every article has to have id attribute + root = et.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 = et.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") + script_element = root.xpath("//head/style") + self.assertEqual(len(script_element), 1) + meta_element = root.xpath("//head/meta[@content]") + self.assertEqual(unicode(meta_element[0].attrib["content"]), + "width=device-width, initial-scale=1.0, " + \ + " maximum-scale=2.0, user-scalable=yes") + + +if __name__ == '__main__': + unittest.main() |