diff options
author | Stefan Sauer <ensonic@users.sf.net> | 2019-02-05 07:58:37 +0100 |
---|---|---|
committer | Stefan Sauer <ensonic@users.sf.net> | 2019-02-06 07:43:15 +0100 |
commit | 358ace6513a43a38d3e93ad0b653cd296e623b74 (patch) | |
tree | 5652a4e208f835ddd4944c76d7cd31aeb1ddeaf3 /tests | |
parent | d0ca9459c2459680494683c253a9b52d5d464ace (diff) | |
download | gtk-doc-358ace6513a43a38d3e93ad0b653cd296e623b74.tar.gz |
tests: add more tests for mkhtml2
Add tests for id/titile and glossary extraction.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/mkhtml2.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/mkhtml2.py b/tests/mkhtml2.py index c65df80..ba4d96c 100755 --- a/tests/mkhtml2.py +++ b/tests/mkhtml2.py @@ -19,8 +19,10 @@ # import logging +import textwrap import unittest +from anytree import PreOrderIter from lxml import etree from gtkdoc import mkhtml2 @@ -61,5 +63,48 @@ class TestChunking(unittest.TestCase): self.assertEqual(2, len(descendants)) +class TestXrefs(unittest.TestCase): + + def setUp(self): + logging.basicConfig( + level=logging.INFO, + format='%(asctime)s:%(filename)s:%(funcName)s:%(lineno)d:%(levelname)s:%(message)s') + + def chunk_db(self, xml): + root = etree.XML(xml) + files = mkhtml2.chunk(root, 'test') + return [f for f in PreOrderIter(files) if f.anchor is None] + + def test_extract_ids(self): + files = self.chunk_db('<book><chapter id="chap1"></chapter></book>') + links = {} + mkhtml2.add_id_links_and_titles(files, links) + self.assertIn('chap1', links) + + def test_extract_titles(self): + files = self.chunk_db('<book><chapter id="chap1"><title>Intro</title></chapter></book>') + links = {} + mkhtml2.add_id_links_and_titles(files, links) + self.assertIn('chap1', mkhtml2.titles) + self.assertEqual('Intro', mkhtml2.titles['chap1']['title']) + self.assertEqual('chapter', mkhtml2.titles['chap1']['tag']) + + def test_extract_glossaries(self): + files = self.chunk_db(textwrap.dedent("""\ + <book> + <glossary id="glossary"> + <glossentry> + <glossterm><anchor id="glossterm-API"/>API</glossterm> + <glossdef> + <para>Application Programming Interface</para> + </glossdef> + </glossentry> + </glossary> + </book>""")) + mkhtml2.build_glossary(files) + self.assertIn('API', mkhtml2.glossary) + self.assertEquals('Application Programming Interface', mkhtml2.glossary['API']) + + if __name__ == '__main__': unittest.main() |