diff --git a/monkeysign/documentation.py b/monkeysign/documentation.py index 46ae0c33c5f10b78a1b6d2ca0a978dd3db761ca9..5ea678f5a90c5225f86961d60256c8f958bf8f4f 100644 --- a/monkeysign/documentation.py +++ b/monkeysign/documentation.py @@ -5,11 +5,13 @@ import os import datetime import time +from docutils import parsers, nodes from distutils.command.build import build from distutils.core import Command from distutils.errors import DistutilsOptionError import subprocess # nosec +from debian import changelog class build_slides(Command): @@ -35,6 +37,25 @@ def has_rst2s5(build): """predicate for this class: do not fail if rst2s5 is missing""" return (os.system('rst2s5 < /dev/null > /dev/null') == 0) # nosec + +class DebianChangelogParser(parsers.Parser): + def parse(self, inputstring, document): + self.setup_parse(inputstring, document) + + self.document = document + self.current_node = document + for block in changelog.Changelog(inputstring): + self.verbatim("\n".join(block.changes())) + self.finish_parse() + + def verbatim(self, text): + verbatim_node = nodes.literal_block() + text = ''.join(text) + if text.endswith('\n'): + text = text[:-1] + verbatim_node.append(nodes.Text(text, text)) + self.current_node.append(verbatim_node) + # (function, predicate), see http://docs.python.org/2/distutils/apiref.html#distutils.cmd.Command.sub_commands build.sub_commands.append(('build_slides', has_rst2s5)) build.sub_commands.append(('build_sphinx', None)) diff --git a/monkeysign/tests/test_doc.py b/monkeysign/tests/test_doc.py new file mode 100755 index 0000000000000000000000000000000000000000..15fae1edac7039971d5cdb23599254cfe04fcfad --- /dev/null +++ b/monkeysign/tests/test_doc.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import unittest + +from docutils.core import publish_parts + +from monkeysign.documentation import DebianChangelogParser + + +class TestBootstrap(unittest.TestCase): + + def test_basic_parser(self): + source = 'foo' + + ret = publish_parts(source=source, writer_name='html', + parser=DebianChangelogParser()) + self.assertIn('foo', ret['body']) + + + def test_basic_parser(self): + source = ''' +monkeysign (2.2.0) unstable; urgency=medium + + * fix tests with Debian CI + * fix FTBS errors in reproducible builds due to test suite failing in + the future + * do not STARTTLS on already secure (TLS) connexions + * enable tor support with --tor flag + * handle SMTP conversations better + + -- Antoine Beaupré <anarcat@debian.org> Tue, 11 Oct 2016 11:29:10 -0400 +''' + + ret = publish_parts(source=source, writer_name='html', + parser=DebianChangelogParser()) + self.assertIn('STARTTLS', ret['body']) + +if __name__ == '__main__': + unittest.main()