aboutsummaryrefslogtreecommitdiffstats
path: root/tests/__init__.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-03-13 12:25:03 -0400
committerWaylan Limberg <waylan@gmail.com>2013-03-13 12:25:03 -0400
commit924ea9c2aba361e157fb60d9fcb3bdc7fbd7fd64 (patch)
treea14f238e163809013e92a5075ef33bc48641aef9 /tests/__init__.py
parent37bfb734dce6402c0a0d69fa1cfecad6825928ff (diff)
downloadmarkdown-924ea9c2aba361e157fb60d9fcb3bdc7fbd7fd64.tar.gz
markdown-924ea9c2aba361e157fb60d9fcb3bdc7fbd7fd64.tar.bz2
markdown-924ea9c2aba361e157fb60d9fcb3bdc7fbd7fd64.zip
Updated testing framework to use PyTidyLib rather than uTidyLib for Python 3 support.
Diffstat (limited to 'tests/__init__.py')
-rw-r--r--tests/__init__.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index bb56bd4..a16d0e6 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -12,9 +12,9 @@ except ImportError:
from . import util
from .plugins import HtmlOutput, Markdown
try:
- import tidy
+ import tidylib
except ImportError:
- tidy = None
+ tidylib = None
test_dir = os.path.abspath(os.path.dirname(__file__))
@@ -60,20 +60,19 @@ def get_args(file, config):
return args
def normalize(text):
- """ Normalize whitespace for a string of html using tidy. """
- return str(tidy.parseString(text.encode('utf-8', 'xmlcharrefreplace'),
- drop_empty_paras=0,
- fix_backslash=0,
- fix_bad_comments=0,
- fix_uri=0,
- join_styles=0,
- lower_literals=0,
- merge_divs=0,
- output_xhtml=1,
- quote_ampersand=0,
- show_body_only=1,
- char_encoding='utf8',
- newline='LF')).decode('string-escape')
+ """ Normalize whitespace for a string of html using tidylib. """
+ output, errors = tidylib.tidy_fragment(text, options={
+ 'drop_empty_paras':0,
+ 'fix_backslash':0,
+ 'fix_bad_comments':0,
+ 'fix_uri':0,
+ 'join_styles':0,
+ 'lower_literals':0,
+ 'merge_divs':0,
+ 'output_xhtml':1,
+ 'quote_ampersand':0,
+ 'newline':'LF'})
+ return output
class CheckSyntax(object):
def __init__(self, description=None):
@@ -93,13 +92,13 @@ class CheckSyntax(object):
# Normalize line endings (on windows, git may have altered line endings).
expected_output = f.read().replace("\r\n", "\n")
output = markdown.markdown(input, **get_args(file, config))
- if tidy and config.get(cfg_section, 'normalize'):
- # Normalize whitespace with Tidy before comparing.
+ if tidylib and config.get(cfg_section, 'normalize'):
+ # Normalize whitespace with tidylib before comparing.
expected_output = normalize(expected_output)
output = normalize(output)
elif config.get(cfg_section, 'normalize'):
- # Tidy is not available. Skip this test.
- raise nose.plugins.skip.SkipTest('Test skipped. Tidy not available in system.')
+ # Tidylib is not available. Skip this test.
+ raise nose.plugins.skip.SkipTest('Test skipped. Tidylib not available on system.')
diff = [l for l in difflib.unified_diff(expected_output.splitlines(True),
output.splitlines(True),
output_file,
@@ -124,7 +123,7 @@ def TestSyntax():
def generate(file, config):
""" Write expected output file for given input. """
cfg_section = get_section(file, config)
- if config.get(cfg_section, 'skip'):
+ if config.get(cfg_section, 'skip') or config.get(cfg_section, 'normalize'):
print('Skipping:', file)
return None
input_file = file + config.get(cfg_section, 'input_ext')