aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--docs/test_suite.txt12
-rw-r--r--tests/__init__.py41
2 files changed, 26 insertions, 27 deletions
diff --git a/docs/test_suite.txt b/docs/test_suite.txt
index 44b6c5c..e10e58b 100644
--- a/docs/test_suite.txt
+++ b/docs/test_suite.txt
@@ -26,7 +26,7 @@ the report.
The test suite contains two kinds of tests: Markdown Syntax Tests and Unit
Tests.
-# Markdown Syntax Tests
+## Markdown Syntax Tests
The Syntax Tests are in the various directories contained within the 'tests'
directory of the packaged tarball. Each test consists of a matching pair of txt
@@ -105,7 +105,7 @@ Below are each of the config options available and the defaults used when they
are not explicitly set.
* `normalize`: Switches whitespace normalization of the test output on or off.
- Defaults to `0` (off). Note: This requires that [uTidylib] be installed on
+ Defaults to `0` (off). Note: This requires that [PyTidyLib] be installed on
the system. Otherwise the test will be skipped, regardless of any other
settings.
* `skip`: Switches skipping of the test on and off. Defaults to `0` (off).
@@ -113,18 +113,18 @@ are not explicitly set.
from other implementations.
* `output_ext`: Extension of output file. Defaults to `.html`. Useful for tests
from other implementations.
-* Any keyword arguement accepted my Markdown. If not set, Markdown's defaults
- are used.
+* Any keyword arguement accepted by the Markdown class. If not set, Markdown's
+ defaults are used.
## Unit Tests
Unit Tests are used as regression tests for Python-Markdown's API.
All Unit Tests shipped with Python-Markdown are standard Python Unit Tests and
-are all contained in `tests/test_apis.py` and `tests/test_extensions`.
+are all contained in `tests/test_apis.py` and `tests/test_extensions.py`.
Standard discovery methods are used to find and run the tests. Therefore, when
writing new tests, those standards and naming conventions should be followed.
[Nose]: http://somethingaboutorange.com/mrl/projects/nose/
[Perl]: http://daringfireball.net/projects/markdown/
[PHP]: http://michelf.com/projects/php-markdown/
-[uTidylib]: http://utidylib.berlios.de/
+[PyTidyLib]: http://countergram.com/open-source/pytidylib/
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')