#!/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