[gtk-doc] tests: add a few simple test for mkhtml2



commit 113e719918a0d6a040395b3fc909b0a5077433d8
Author: Stefan Sauer <ensonic users sf net>
Date:   Wed Apr 4 19:21:58 2018 +0200

    tests: add a few simple test for mkhtml2

 gtkdoc/mkhtml2.py |   33 ++++++++++++++++++++-------------
 tests/Makefile.am |    2 +-
 tests/mkhtml2.py  |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 14 deletions(-)
---
diff --git a/gtkdoc/mkhtml2.py b/gtkdoc/mkhtml2.py
index 2dda96d..826e05a 100644
--- a/gtkdoc/mkhtml2.py
+++ b/gtkdoc/mkhtml2.py
@@ -198,22 +198,27 @@ def get_chunk_titles(node):
     else:
         (title, subtitle) = TITLE_XPATHS[tag]
 
-    xml = title(node)[0]
     result = {
-        'title': xml.text
+        'title': None,
+        'title_tag': None,
+        'subtitle': None,
+        'subtitle_tag': None
     }
-    if xml.tag != 'title':
-        result['title_tag'] = xml.tag
-    else:
-        result['title_tag'] = tag
+    res = title(node)
+    if res:
+        xml = res[0]
+        result['title'] = xml.text
+        if xml.tag != 'title':
+            result['title_tag'] = xml.tag
+        else:
+            result['title_tag'] = tag
 
     if subtitle:
-        xml = subtitle(node)[0]
-        result['subtitle'] = xml.text
-        result['subtitle_tag'] = xml.tag
-    else:
-        result['subtitle'] = None
-        result['subtitle_tag'] = None
+        res = subtitle(node)
+        if res:
+            xml = res[0]
+            result['subtitle'] = xml.text
+            result['subtitle_tag'] = xml.tag
     return result
 
 
@@ -238,9 +243,11 @@ def chunk(xml_node, idx=0, parent=None):
         parent = Node(tag, parent=parent, xml=xml_node,
                       filename=chunk_name + '.html', **title_args)
 
+    # TODO(ensonic): add a is_terminal flag to CHUNK_PARAMS to stop recursing
+
     idx = 0
     for child in xml_node:
-        new_parent = chunk(child, idx, parent)
+        chunk(child, idx, parent)
         if child.tag in CHUNK_TAGS:
             idx += 1
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 429f2f4..9172844 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,7 +7,7 @@ SUBDIRS = annotations bugs empty fail gobject program repro .
 if BUILD_TESTS
 
 TESTS = \
-  check.py common.py mk_to_db.py \
+  check.py common.py mk_to_db.py mkhtml2.py \
   tools.sh gobject.sh bugs.sh annotations.sh fail.sh empty.sh sanity.sh \
   program.sh
 TESTS_ENVIRONMENT = \
diff --git a/tests/mkhtml2.py b/tests/mkhtml2.py
new file mode 100755
index 0000000..3d86611
--- /dev/null
+++ b/tests/mkhtml2.py
@@ -0,0 +1,53 @@
+# -*- python; coding: utf-8 -*-
+#
+# gtk-doc - GTK DocBook documentation generator.
+# Copyright (C) 2018  Stefan Sauer
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+import unittest
+
+from lxml import etree
+
+from gtkdoc import mkhtml2
+
+
+class TestChunking(unittest.TestCase):
+
+    def test_chunk_only_root_gives_single_chunk(self):
+        root = etree.XML('<book />')
+        files = mkhtml2.chunk(root)
+        self.assertEqual('book', files.name)
+        self.assertEqual(0, len(files.descendants))
+
+    def test_chunk_single_chapter_gives_two_chunks(self):
+        root = etree.XML('<book><chapter /></book>')
+        files = mkhtml2.chunk(root)
+        self.assertEqual(1, len(files.descendants))
+
+    def test_chunk_first_sect1_is_inlined(self):
+        root = etree.XML('<book><chapter><sect1 /></chapter></book>')
+        files = mkhtml2.chunk(root)
+        self.assertEqual(1, len(files.descendants))
+
+    def test_chunk_second_sect1_is_nt_inlined(self):
+        root = etree.XML('<book><chapter><sect1 /><sect1 /></chapter></book>')
+        files = mkhtml2.chunk(root)
+        self.assertEqual(2, len(files.descendants))
+
+
+if __name__ == '__main__':
+    unittest.main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]