aboutsummaryrefslogtreecommitdiffstats
path: root/tests/__init__.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2009-05-30 22:29:56 -0400
committerWaylan Limberg <waylan@gmail.com>2009-06-05 22:25:51 -0400
commitcc452998dc1af441cf3f9c5d0c7287cb5de48c4a (patch)
treef138bb00542b47bf382d4ba8f10f0d2a9470ccfe /tests/__init__.py
parent0ae9951f49eb75c8a9fb9f841673b889763c1811 (diff)
downloadmarkdown-cc452998dc1af441cf3f9c5d0c7287cb5de48c4a.tar.gz
markdown-cc452998dc1af441cf3f9c5d0c7287cb5de48c4a.tar.bz2
markdown-cc452998dc1af441cf3f9c5d0c7287cb5de48c4a.zip
Initial implementation of nose testing. Still some cleanup to do, but this shows the differances between the old and the new. Also left one test failing (unsignificant white space only) to demonstrate what a failing test looks like.
Diffstat (limited to 'tests/__init__.py')
-rw-r--r--tests/__init__.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..63ddf5b
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,44 @@
+import os
+import markdown
+import codecs
+import difflib
+import nose
+import util
+from plugins import MdSyntaxError, HtmlOutput, MdSyntaxErrorPlugin
+from test_apis import *
+
+test_dir = os.path.abspath(os.path.dirname(__file__))
+
+def normalize(text):
+ return ['%s\n' % l for l in text.strip().split('\n')]
+
+def check_syntax(file, config):
+ input_file = file + ".txt"
+ input = codecs.open(input_file, encoding="utf-8").read()
+ output_file = file + ".html"
+ expected_output = codecs.open(output_file, encoding="utf-8").read()
+ output = normalize(markdown.markdown(input,
+ config.get('DEFAULT', 'extensions'),
+ config.get('DEFAULT', 'safe_mode'),
+ config.get('DEFAULT', 'output_format')))
+ diff = [l for l in difflib.unified_diff(normalize(expected_output),
+ output, output_file,
+ 'actual_output.html', n=3)]
+ if diff:
+ raise util.MdSyntaxError('Output from "%s" failed to match expected '
+ 'output.\n\n%s' % (input_file, ''.join(diff)))
+
+def test_markdown_syntax():
+ for dir_name, sub_dirs, files in os.walk(test_dir):
+ # Get dir specific config settings.
+ config = util.CustomConfigParser({'extensions': '',
+ 'safe_mode': False,
+ 'output_format': 'xhtml1'})
+ config.read(os.path.join(dir_name, 'test.cfg'))
+ # Loop through files and generate tests.
+ for file in files:
+ root, ext = os.path.splitext(file)
+ if ext == '.txt':
+ yield check_syntax, os.path.join(dir_name, root), config
+
+nose.main(addplugins=[HtmlOutput(), MdSyntaxErrorPlugin()])