diff options
author | JensDiemer <git@jensdiemer.de> | 2020-01-19 00:00:01 +0100 |
---|---|---|
committer | JensDiemer <git@jensdiemer.de> | 2020-01-19 00:00:01 +0100 |
commit | ffa17afcdf04339562c27211e1e5f2e5356d22d4 (patch) | |
tree | a407fd4e8c3a89d0bcc084bfb52a5b02147dd568 /creole | |
parent | 671afb0e294d7a18740933b2aba8dbd58fb1da2c (diff) | |
download | creole-ffa17afcdf04339562c27211e1e5f2e5356d22d4.tar.gz |
more default verbose in tests
Diffstat (limited to 'creole')
-rw-r--r-- | creole/__init__.py | 5 | ||||
-rw-r--r-- | creole/parser/creol2html_parser.py | 28 | ||||
-rw-r--r-- | creole/tests/test_creole2html.py | 8 | ||||
-rw-r--r-- | creole/tests/utils/base_unittest.py | 40 |
4 files changed, 38 insertions, 43 deletions
diff --git a/creole/__init__.py b/creole/__init__.py index f720b9f..3c6a113 100644 --- a/creole/__init__.py +++ b/creole/__init__.py @@ -14,7 +14,7 @@ :PyPi: http://pypi.python.org/pypi/python-creole/ - :copyleft: 2008-2015 by python-creole team, see AUTHORS for more details. + :copyleft: 2008-2020 by python-creole team, see AUTHORS for more details. :license: GNU GPL v3 or above, see LICENSE for more details. """ @@ -31,7 +31,7 @@ from creole.parser.html_parser import HtmlParser from creole.py3compat import TEXT_TYPE -__version__ = "1.3.2" +__version__ = "1.4.0" __api__ = "1.0" # Creole 1.0 spec - http://wikicreole.org/ VERSION_STRING = __version__ # remove in future @@ -57,6 +57,7 @@ def creole2html(markup_string, debug=False, parser_kwargs2 = { "block_rules": block_rules, "blog_line_breaks": blog_line_breaks, + "debug": debug, } if parser_kwargs is not None: warnings.warn("parser_kwargs argument in creole2html would be removed in the future!", PendingDeprecationWarning) diff --git a/creole/parser/creol2html_parser.py b/creole/parser/creol2html_parser.py index 5e7f664..63f3b14 100644 --- a/creole/parser/creol2html_parser.py +++ b/creole/parser/creol2html_parser.py @@ -25,6 +25,7 @@ import re +from pprint import pformat from creole.parser.creol2html_rules import BlockRules, INLINE_FLAGS, INLINE_RULES, \ SpecialRules, InlineRules @@ -59,18 +60,19 @@ class CreoleParser(object): inline_re = re.compile('|'.join(INLINE_RULES), INLINE_FLAGS) - def __init__(self, raw, block_rules=None, blog_line_breaks=True): + def __init__(self, raw, block_rules=None, blog_line_breaks=True, debug=False): assert isinstance(raw, TEXT_TYPE) self.raw = raw if block_rules is None: block_rules = BlockRules(blog_line_breaks=blog_line_breaks) + self.blog_line_breaks = blog_line_breaks + self.debug = debug # TODO: use logging + # setup block element rules: self.block_re = re.compile('|'.join(block_rules.rules), block_rules.re_flags) - self.blog_line_breaks = blog_line_breaks - self.root = DocNode('document', None) self.cur = self.root # The most recent document node self.text = None # The node to add inline characters to @@ -423,17 +425,18 @@ class CreoleParser(object): def _replace(self, match): """Invoke appropriate _*_repl method. Called for every matched group.""" -# def debug(groups): -# from pprint import pformat -# data = dict([ -# group for group in groups.items() if group[1] is not None -# ]) -# print("%s\n" % pformat(data)) + def debug(groups): + data = dict([ + group for group in groups.items() if group[1] is not None + ]) + print(pformat(data)) groups = match.groupdict() for name, text in groups.items(): if text is not None: - #if name != "char": debug(groups) + if self.debug and name != "char": + # TODO: use logging + debug(groups) replace_method = getattr(self, '_%s_repl' % name) replace_method(groups) return @@ -450,12 +453,15 @@ class CreoleParser(object): """Parse the text given as self.raw and return DOM tree.""" # convert all lineendings to \n text = self.raw.replace("\r\n", "\n").replace("\r", "\n") + if self.debug: + # TODO: use logging + print(repr(text)) self.parse_block(text) return self.root #-------------------------------------------------------------------------- - def debug(self, start_node=None): + def debug_tree(self, start_node=None): """ Display the current document tree """ diff --git a/creole/tests/test_creole2html.py b/creole/tests/test_creole2html.py index da7ca02..b75435d 100644 --- a/creole/tests/test_creole2html.py +++ b/creole/tests/test_creole2html.py @@ -809,7 +809,8 @@ class TestCreole2htmlMarkup(BaseCreoleTest): ...and not blog styled. """), - parser_kwargs={"blog_line_breaks":False}, + blog_line_breaks=False, + debug=True, verbose=True ) self.assertEqual(html, self._prepare_text(""" <p>wiki style linebreaks</p> @@ -826,7 +827,8 @@ class TestCreole2htmlMarkup(BaseCreoleTest): * one * two """), - parser_kwargs={"blog_line_breaks":False}, + blog_line_breaks=False, + debug=True, verbose=True ) self.assertEqual(html, self._prepare_text(""" <p><strong>one</strong> <i>two</i></p> @@ -853,7 +855,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest): end """), - parser_kwargs={"blog_line_breaks":False}, + blog_line_breaks=False, ) self.assertEqual(html, self._prepare_text(""" <p>with blog line breaks, every line break would be convertet into<br /> with wiki style not.</p> diff --git a/creole/tests/utils/base_unittest.py b/creole/tests/utils/base_unittest.py index 1ad768d..fb21245 100644 --- a/creole/tests/utils/base_unittest.py +++ b/creole/tests/utils/base_unittest.py @@ -86,29 +86,17 @@ class BaseCreoleTest(MarkupTest): text = text.replace("\n", "\\n\n") text = text.replace("\t", "\\t") - print + print() print("_" * 79) - print(" Debug Text: %s" % msg) + print(" Debug Text: %s:" % msg) print(text) print("-" * 79) - def assertIn(self, member, container, *args, **kwargs): - """ - Assert member in container. - assertIn is new in Python 2.7 - """ - try: - f = super(BaseCreoleTest, self).assertIn - except AttributeError: - self.assertTrue(member in container, *args, **kwargs) - else: - f(member, container, *args, **kwargs) - def assert_creole2html( self, raw_creole, raw_html, - strip_lines=False, debug=False, + strip_lines=False, debug=True, parser_kwargs={}, emitter_kwargs={}, - block_rules=None, blog_line_breaks=True, macros=None, verbose=None, stderr=None, + block_rules=None, blog_line_breaks=True, macros=None, verbose=True, stderr=None, strict=False, ): """ @@ -127,18 +115,16 @@ class BaseCreoleTest(MarkupTest): assert isinstance(html_string, TEXT_TYPE) if strip_lines: html_string = strip_html_lines(html_string, strip_lines) - if debug: - self._debug_text("assert_creole2html() html_string", html_string) + self._debug_text("assert_creole2html() html_string reference", html_string) # convert creole markup into html code out_string = creole2html( - markup_string, debug, + markup_string, debug=debug, block_rules=block_rules, blog_line_breaks=blog_line_breaks, macros=macros, verbose=verbose, stderr=stderr, strict=strict, ) - if debug: - self._debug_text("assert_creole2html() creole2html", out_string) + self._debug_text("assert_creole2html() creole2html output", out_string) if strip_lines: out_string = strip_html_lines(out_string, strip_lines) @@ -149,7 +135,7 @@ class BaseCreoleTest(MarkupTest): self.assertEqual(out_string, html_string, msg="creole2html") def assert_html2creole2(self, creole, html, - debug=False, + debug=True, unknown_emit=None, strict=False, ): @@ -157,8 +143,7 @@ class BaseCreoleTest(MarkupTest): out_string = html2creole( html, debug, unknown_emit=unknown_emit, strict=strict ) - if debug: - self._debug_text("assert_html2creole() html2creole", out_string) + self._debug_text("assert_html2creole() html2creole", out_string) # compare self.assertEqual(out_string, creole, msg="html2creole") @@ -195,7 +180,7 @@ class BaseCreoleTest(MarkupTest): self.assert_html2creole2(creole, html, debug, unknown_emit, strict) def cross_compare_creole(self, creole_string, html_string, - strip_lines=False, debug=False, + strip_lines=False, debug=True, # creole2html old API: creole_parser_kwargs={}, html_emitter_kwargs={}, # html2creole old API: @@ -221,13 +206,14 @@ class BaseCreoleTest(MarkupTest): self.assertNotEqual(creole_string, html_string) self.assert_creole2html( - creole_string, html_string, strip_lines, debug, + raw_creole=creole_string, raw_html=html_string, + strip_lines=strip_lines, block_rules=block_rules, blog_line_breaks=blog_line_breaks, macros=macros, stderr=stderr, ) self.assert_html2creole( - creole_string, html_string, strip_lines, debug, + raw_creole=creole_string, raw_html=html_string, strip_lines=strip_lines, unknown_emit=unknown_emit, ) |