aboutsummaryrefslogtreecommitdiffstats
path: root/test_generate_html.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2012-09-21 01:02:05 +0200
committerMatěj Cepl <mcepl@redhat.com>2012-09-21 01:02:09 +0200
commit2ab034b507f6d893f2553a4d9e4b2606cb8c54b9 (patch)
tree353689b14bc045f50c17435f52b59559f383b943 /test_generate_html.py
parentbeeaf134299396aac98dcace2533ea2419758aa1 (diff)
downloadhesla-2ab034b507f6d893f2553a4d9e4b2606cb8c54b9.tar.gz
The first working version of generate_html.py
Diffstat (limited to 'test_generate_html.py')
-rw-r--r--test_generate_html.py56
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()