diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2014-11-20 16:07:03 -0500 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2014-11-20 16:07:03 -0500 |
commit | 8f66a94eab1389d97041944ed24afd2bf7c4389c (patch) | |
tree | 10b53664076650be951468cbbb163f3d637e5891 /tests | |
parent | 0c2143819ef7de53be52f7a4d47e027ff194a9b4 (diff) | |
download | markdown-8f66a94eab1389d97041944ed24afd2bf7c4389c.tar.gz markdown-8f66a94eab1389d97041944ed24afd2bf7c4389c.tar.bz2 markdown-8f66a94eab1389d97041944ed24afd2bf7c4389c.zip |
Flake8 cleanup (mostly whitespace).
Got all but a couple files in the tests (ran out of time today).
Apparently I have been using some bad form for years (although a few
things seemed to look better before the update). Anyway, conformant now.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 67 | ||||
-rw-r--r-- | tests/plugins.py | 50 |
2 files changed, 69 insertions, 48 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index 15710ac..f759ceb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -7,7 +7,7 @@ try: except ImportError as e: msg = e.args[0] msg = msg + ". The nose testing framework is required to run the Python-" \ - "Markdown tests. Run `pip install nose` to install the latest version." + "Markdown tests. Run `pip install nose` to install the latest version." e.args = (msg,) + e.args[1:] raise from .plugins import HtmlOutput, Markdown, MarkdownSyntaxError @@ -20,12 +20,13 @@ try: except ImportError as e: msg = e.args[0] msg = msg + ". A YAML library is required to run the Python-Markdown " \ - "tests. Run `pip install pyyaml` to install the latest version." + "tests. Run `pip install pyyaml` to install the latest version." e.args = (msg,) + e.args[1:] raise test_dir = os.path.abspath(os.path.dirname(__file__)) + class YamlConfig(): def __init__(self, defaults, filename): """ Set defaults and load config file if it exists. """ @@ -73,21 +74,24 @@ def get_config(dir_name): config = YamlConfig(defaults, os.path.join(dir_name, 'test.cfg')) return config + def normalize(text): """ 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'}) + '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): if description: @@ -101,9 +105,10 @@ class CheckSyntax(object): input_file = file + config.get(cfg_section, 'input_ext') with codecs.open(input_file, encoding="utf-8") as f: input = f.read() - output_file = file + config.get(cfg_section, 'output_ext') + output_file = file + config.get(cfg_section, 'output_ext') with codecs.open(output_file, encoding="utf-8") as f: - # Normalize line endings (on windows, git may have altered line endings). + # Normalize line endings + # (on windows, git may have altered line endings). expected_output = f.read().replace("\r\n", "\n") output = markdown.markdown(input, **config.get_args(file)) if tidylib and config.get(cfg_section, 'normalize'): @@ -112,15 +117,22 @@ class CheckSyntax(object): output = normalize(output) elif config.get(cfg_section, 'normalize'): # 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, - 'actual_output.html', - n=3)] + 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, + 'actual_output.html', + n=3 + )] if diff: - raise MarkdownSyntaxError('Output from "%s" failed to match expected ' - 'output.\n\n%s' % (input_file, ''.join(diff))) + raise MarkdownSyntaxError( + 'Output from "%s" failed to match expected ' + 'output.\n\n%s' % (input_file, ''.join(diff)) + ) + def TestSyntax(): for dir_name, sub_dirs, files in os.walk(test_dir): @@ -131,9 +143,12 @@ def TestSyntax(): root, ext = os.path.splitext(file) if ext == config.get(config.get_section(file), 'input_ext'): path = os.path.join(dir_name, root) - check_syntax = CheckSyntax(description=os.path.relpath(path, test_dir)) + check_syntax = CheckSyntax( + description=os.path.relpath(path, test_dir) + ) yield check_syntax, path, config + def generate(file, config): """ Write expected output file for given input. """ cfg_section = config.get_section(file) @@ -141,15 +156,16 @@ def generate(file, config): print('Skipping:', file) return None input_file = file + config.get(cfg_section, 'input_ext') - output_file = file + config.get(cfg_section, 'output_ext') + output_file = file + config.get(cfg_section, 'output_ext') if not os.path.isfile(output_file) or \ os.path.getmtime(output_file) < os.path.getmtime(input_file): print('Generating:', file) - markdown.markdownFromFile(input=input_file, output=output_file, + markdown.markdownFromFile(input=input_file, output=output_file, encoding='utf-8', **config.get_args(file)) else: print('Already up-to-date:', file) + def generate_all(): """ Generate expected output for all outdated tests. """ for dir_name, sub_dirs, files in os.walk(test_dir): @@ -164,4 +180,3 @@ def generate_all(): def run(): nose.main(addplugins=[HtmlOutput(), Markdown()]) - diff --git a/tests/plugins.py b/tests/plugins.py index 12bac55..90c5c0d 100644 --- a/tests/plugins.py +++ b/tests/plugins.py @@ -9,9 +9,11 @@ class MarkdownSyntaxError(Exception): class Markdown(ErrorClassPlugin): """ Add MarkdownSyntaxError and ensure proper formatting. """ - mdsyntax = ErrorClass(MarkdownSyntaxError, - label='MarkdownSyntaxError', - isfailure=True) + mdsyntax = ErrorClass( + MarkdownSyntaxError, + label='MarkdownSyntaxError', + isfailure=True + ) enabled = True def configure(self, options, conf): @@ -39,28 +41,30 @@ def escape(html): class HtmlOutput(Plugin): """Output test results as ugly, unstyled html. """ - + name = 'html-output' - score = 2 # run late + score = 2 # run late enabled = True - + def __init__(self): super(HtmlOutput, self).__init__() - self.html = [ '<html><head>', - '<title>Test output</title>', - '</head><body>' ] - + self.html = [ + '<html><head>', + '<title>Test output</title>', + '</head><body>' + ] + def configure(self, options, conf): self.conf = conf def addSuccess(self, test): self.html.append('<span>ok</span>') - + def addError(self, test, err): err = self.formatErr(err) self.html.append('<span>ERROR</span>') self.html.append('<pre>%s</pre>' % escape(err)) - + def addFailure(self, test, err): err = self.formatErr(err) self.html.append('<span>FAIL</span>') @@ -68,9 +72,10 @@ class HtmlOutput(Plugin): def finalize(self, result): self.html.append('<div>') - self.html.append("Ran %d test%s" % - (result.testsRun, result.testsRun != 1 and "s" -or "")) + self.html.append( + "Ran %d test%s" % + (result.testsRun, result.testsRun != 1 and "s" or "") + ) self.html.append('</div>') self.html.append('<div>') if not result.wasSuccessful(): @@ -93,7 +98,7 @@ or "")) def formatErr(self, err): exctype, value, tb = err return ''.join(traceback.format_exception(exctype, value, tb)) - + def startContext(self, ctx): try: n = ctx.__name__ @@ -108,12 +113,13 @@ or "")) def stopContext(self, ctx): self.html.append('</fieldset>') - + def startTest(self, test): - self.html.extend([ '<div><span>', - test.shortDescription() or str(test), - '</span>' ]) - + self.html.extend([ + '<div><span>', + test.shortDescription() or str(test), + '</span>' + ]) + def stopTest(self, test): self.html.append('</div>') - |