summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-07-11 18:22:23 -0400
committerrsiddharth <s@ricketyspace.net>2020-07-11 18:22:23 -0400
commit7dbd4633d37f0976b6074fe89111d4c143d4fbfe (patch)
tree7ef37d0ee04df83b0913352808eb470a5f835b06
parent8e19751d14f5f3cf17094631e210ed4bef2c2f7f (diff)
use black for formatting
-rw-r--r--markdown_link_style/_version.py2
-rw-r--r--markdown_link_style/logging.py2
-rw-r--r--mdl_style.py153
-rw-r--r--setup.py61
-rw-r--r--tests/test_markdown_link_style/test_logging.py23
-rw-r--r--tests/test_mdl_style.py160
6 files changed, 211 insertions, 190 deletions
diff --git a/markdown_link_style/_version.py b/markdown_link_style/_version.py
index 3db7122..22c7d3a 100644
--- a/markdown_link_style/_version.py
+++ b/markdown_link_style/_version.py
@@ -18,4 +18,4 @@
# along with markdown-link-style (see COPYING). If not, see
# <http://www.gnu.org/licenses/>.
-__version__ = '0.2.1.dev1'
+__version__ = "0.2.1.dev1"
diff --git a/markdown_link_style/logging.py b/markdown_link_style/logging.py
index 2a93d7b..0415889 100644
--- a/markdown_link_style/logging.py
+++ b/markdown_link_style/logging.py
@@ -21,6 +21,7 @@
import logging
import sys
+
class MDLSLogger(object):
"""Logging utility for modules in markdown-link-style.
@@ -50,4 +51,3 @@ class MDLSLogger(object):
def critical(self, msg, *args, **kwargs):
self.logger.critical(msg, *args, **kwargs)
-
diff --git a/mdl_style.py b/mdl_style.py
index eb6ed12..86a7b0b 100644
--- a/mdl_style.py
+++ b/mdl_style.py
@@ -21,8 +21,7 @@
import argparse
import re
-from mistune import (BlockGrammar, BlockLexer, InlineLexer, Renderer,
- Markdown)
+from mistune import BlockGrammar, BlockLexer, InlineLexer, Renderer, Markdown
from markdown_link_style.logging import MDLSLogger
from markdown_link_style._version import __version__
@@ -34,38 +33,67 @@ logger = MDLSLogger(__name__)
# from mistune
_inline_tags = [
- 'a', 'em', 'strong', 'small', 's', 'cite', 'q', 'dfn', 'abbr',
- 'data', 'time', 'code', 'var', 'samp', 'kbd', 'sub', 'sup', 'i',
- 'b', 'u', 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'span', 'br',
- 'wbr', 'ins', 'del', 'img', 'font',
+ "a",
+ "em",
+ "strong",
+ "small",
+ "s",
+ "cite",
+ "q",
+ "dfn",
+ "abbr",
+ "data",
+ "time",
+ "code",
+ "var",
+ "samp",
+ "kbd",
+ "sub",
+ "sup",
+ "i",
+ "b",
+ "u",
+ "mark",
+ "ruby",
+ "rt",
+ "rp",
+ "bdi",
+ "bdo",
+ "span",
+ "br",
+ "wbr",
+ "ins",
+ "del",
+ "img",
+ "font",
]
-_valid_end = r'(?!:/|[^\w\s@]*@)\b'
-_block_tag = r'(?!(?:%s)\b)\w+%s' % ('|'.join(_inline_tags), _valid_end)
+_valid_end = r"(?!:/|[^\w\s@]*@)\b"
+_block_tag = r"(?!(?:%s)\b)\w+%s" % ("|".join(_inline_tags), _valid_end)
def _pure_pattern(regex):
"""Function from mistune."""
pattern = regex.pattern
- if pattern.startswith('^'):
+ if pattern.startswith("^"):
pattern = pattern[1:]
return pattern
class LSBlockGrammar(BlockGrammar):
-
def __init__(self):
# remove list_block and block_quote from paragraph
self.paragraph = re.compile(
- r'^((?:[^\n]+\n?(?!'
- r'%s|%s|%s|%s|%s|%s|%s'
- r'))+)\n*' % (
- _pure_pattern(self.fences).replace(r'\1', r'\2'),
+ r"^((?:[^\n]+\n?(?!"
+ r"%s|%s|%s|%s|%s|%s|%s"
+ r"))+)\n*"
+ % (
+ _pure_pattern(self.fences).replace(r"\1", r"\2"),
_pure_pattern(self.hrule),
_pure_pattern(self.heading),
_pure_pattern(self.lheading),
_pure_pattern(self.def_links),
_pure_pattern(self.def_footnotes),
- '<' + _block_tag,
+ "<" + _block_tag,
)
)
@@ -74,13 +102,14 @@ class LSBlockLexer(BlockLexer):
"""Link Style Block Lexer.
"""
+
grammar_class = LSBlockGrammar
def __init__(self, rules=None, **kwargs):
super(LSBlockLexer, self).__init__(rules, **kwargs)
# Only parse these block rules.
- self.default_rules = ['def_links', 'paragraph', 'text']
+ self.default_rules = ["def_links", "paragraph", "text"]
class LSInlineLexer(InlineLexer):
@@ -92,7 +121,7 @@ class LSInlineLexer(InlineLexer):
super(LSInlineLexer, self).__init__(renderer, rules, **kwargs)
# Only parse these inline rules
- self.default_rules = ['autolink', 'link', 'reflink', 'text']
+ self.default_rules = ["autolink", "link", "reflink", "text"]
class LSRenderer(Renderer):
@@ -104,16 +133,16 @@ class LSRenderer(Renderer):
super(LSRenderer, self).__init__(**kwargs)
# Link style is either 'inline' or 'footnote'.
- self.link_style = self.options.get('link_style')
+ self.link_style = self.options.get("link_style")
- self.fn_lnk_num = 0 # footnote style link number
- self.fn_lnk_refs = [] # footnote style link refs
+ self.fn_lnk_num = 0 # footnote style link number
+ self.fn_lnk_refs = [] # footnote style link refs
def text(self, text):
return text
def autolink(self, link, is_email=False):
- return '<{}>'.format(link)
+ return "<{}>".format(link)
def paragraph(self, text):
p = text
@@ -121,9 +150,9 @@ class LSRenderer(Renderer):
if fn_refs:
# Insert footnote refs, if any, after paragraph.
- return '\n{}\n\n{}'.format(p, fn_refs)
+ return "\n{}\n\n{}".format(p, fn_refs)
- return '\n{}\n'.format(p)
+ return "\n{}\n".format(p)
def link(self, link, title, text):
link_text = self._stylize_link(link, title, text)
@@ -132,10 +161,10 @@ class LSRenderer(Renderer):
def image(self, src, title, text):
# Markup for images are same as links, except it is prefixed
# with a bang (!).
- return '{}{}'.format('!', self.link(src, title, text))
+ return "{}{}".format("!", self.link(src, title, text))
def _stylize_link(self, link, title, text):
- if self.link_style == 'inline':
+ if self.link_style == "inline":
return self._gen_inline_link(link, title, text)
else:
return self._gen_footnote_link(link, title, text)
@@ -144,11 +173,11 @@ class LSRenderer(Renderer):
if title:
return '[{}]({} "{}")'.format(text, link, title)
else:
- return '[{}]({})'.format(text, link)
+ return "[{}]({})".format(text, link)
def _gen_footnote_link(self, link, title, text):
fn_num = self._st_fn_ref(link, title)
- return '[{}][{}]'.format(text, fn_num)
+ return "[{}][{}]".format(text, fn_num)
def _st_fn_ref(self, link, title):
"""Store footnote link reference.
@@ -157,9 +186,9 @@ class LSRenderer(Renderer):
fn_num = self._get_fn_lnk_num()
if title:
- fn_ref = '[{}]: {} ({})'.format(fn_num, link, title)
+ fn_ref = "[{}]: {} ({})".format(fn_num, link, title)
else:
- fn_ref = '[{}]: {}'.format(fn_num, link)
+ fn_ref = "[{}]: {}".format(fn_num, link)
self.fn_lnk_refs.append(fn_ref)
return fn_num
@@ -176,10 +205,10 @@ class LSRenderer(Renderer):
"""Pop all footnote refs and return them as a string.
"""
- refs = ''
+ refs = ""
for ref in self.fn_lnk_refs:
- refs += '{}\n'.format(ref)
+ refs += "{}\n".format(ref)
# Empty fn_lnk_refs
self.fn_lnk_refs = []
@@ -191,9 +220,8 @@ class LSMarkdown(Markdown):
"""Link Style Markdown parser.
"""
- def __init__(self, renderer=None, inline=None, block=None,
- **kwargs):
- link_style = kwargs.get('link_style') or 'inline'
+ def __init__(self, renderer=None, inline=None, block=None, **kwargs):
+ link_style = kwargs.get("link_style") or "inline"
if not renderer:
renderer = LSRenderer(link_style=link_style)
@@ -202,8 +230,7 @@ class LSMarkdown(Markdown):
if not block:
block = LSBlockLexer()
- super(LSMarkdown, self).__init__(renderer, inline, block,
- **kwargs)
+ super(LSMarkdown, self).__init__(renderer, inline, block, **kwargs)
def parse(self, text):
# Reset footnote link variables.
@@ -214,7 +241,7 @@ class LSMarkdown(Markdown):
out = super(LSMarkdown, self).parse(text)
# Spit out.
- return out.lstrip('\n')
+ return out.lstrip("\n")
class LinkStyler(object):
@@ -222,7 +249,7 @@ class LinkStyler(object):
"""
- def __init__(self, link_style='inline'):
+ def __init__(self, link_style="inline"):
self.style = link_style
def __call__(self, file_):
@@ -236,15 +263,15 @@ class LinkStyler(object):
def _write_to(file_, content):
- """Write `content` to `file_`.
+ """Write `content` to `file_`.
`file_` is expected to be a sub-class of `io.TextIOBase`.
- """
- file_.truncate(0)
- file_.seek(0)
- file_.write(content)
- file_.flush()
- file_.close()
+ """
+ file_.truncate(0)
+ file_.seek(0)
+ file_.write(content)
+ file_.flush()
+ file_.close()
def _mdl_stylize(args):
@@ -253,26 +280,34 @@ def _mdl_stylize(args):
if args.out_file:
args.in_file.close()
- _write_to(open(args.out_file, 'wt'), stylized_content)
+ _write_to(open(args.out_file, "wt"), stylized_content)
else:
_write_to(args.in_file, stylized_content)
def _get_args(args=None):
parser = argparse.ArgumentParser()
- parser.add_argument('--version', action='version',
- version=__version__)
- parser.add_argument('link_style', choices=['inline', 'footnote'],
- help='markdown link style.')
- parser.add_argument('in_file', type=argparse.FileType('rt+'),
- help='path to markdown file.')
- parser.add_argument('out_file', nargs='?',
- type=str,
- default=None,
- help= ' '.join(['path to output file.',
- 'if it is not given, the output is',
- 'directly written to the original',
- 'in_file.']))
+ parser.add_argument("--version", action="version", version=__version__)
+ parser.add_argument(
+ "link_style", choices=["inline", "footnote"], help="markdown link style."
+ )
+ parser.add_argument(
+ "in_file", type=argparse.FileType("rt+"), help="path to markdown file."
+ )
+ parser.add_argument(
+ "out_file",
+ nargs="?",
+ type=str,
+ default=None,
+ help=" ".join(
+ [
+ "path to output file.",
+ "if it is not given, the output is",
+ "directly written to the original",
+ "in_file.",
+ ]
+ ),
+ )
return parser.parse_args(args)
diff --git a/setup.py b/setup.py
index 91532bd..32adc2d 100644
--- a/setup.py
+++ b/setup.py
@@ -27,43 +27,42 @@ from codecs import open
from os import path
from markdown_link_style._version import __version__
+
here = path.abspath(path.dirname(__file__))
-with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
+with open(path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read()
config = {
- 'name': 'markdown-link-style',
- 'version': __version__,
- 'description': 'Switch between inline and footnote link style ' +
- 'in markdown documents.',
- 'long_description': long_description,
- 'platforms': 'GNU/Linux',
- 'url': 'https://git.ricketyspace.net/markdown-link-style',
- 'author': 'rsiddharth',
- 'author_email': 's@ricketyspace.net',
- 'license': 'GNU General Public License version 3 or later',
- 'classifiers': [
- 'Development Status :: 2 - Pre-Alpha',
- 'Environment :: Console',
- 'Intended Audience :: Developers',
- 'Intended Audience :: End Users/Desktop',
- 'License :: OSI Approved :: ' +
- 'GNU General Public License v3 or later (GPLv3+)',
- 'Operating System :: POSIX :: Linux',
- 'Programming Language :: Python :: 3.5',
- 'Programming Language :: Python :: 3 :: Only',
- 'Topic :: Documentation',
- 'Topic :: Text Processing :: General',
- 'Topic :: Utilities',
+ "name": "markdown-link-style",
+ "version": __version__,
+ "description": "Switch between inline and footnote link style "
+ + "in markdown documents.",
+ "long_description": long_description,
+ "platforms": "GNU/Linux",
+ "url": "https://git.ricketyspace.net/markdown-link-style",
+ "author": "rsiddharth",
+ "author_email": "s@ricketyspace.net",
+ "license": "GNU General Public License version 3 or later",
+ "classifiers": [
+ "Development Status :: 2 - Pre-Alpha",
+ "Environment :: Console",
+ "Intended Audience :: Developers",
+ "Intended Audience :: End Users/Desktop",
+ "License :: OSI Approved :: "
+ + "GNU General Public License v3 or later (GPLv3+)",
+ "Operating System :: POSIX :: Linux",
+ "Programming Language :: Python :: 3.5",
+ "Programming Language :: Python :: 3 :: Only",
+ "Topic :: Documentation",
+ "Topic :: Text Processing :: General",
+ "Topic :: Utilities",
],
- 'keywords': 'markdown link inline footnote style',
- 'py_modules': ['mdl_style'],
- 'packages': ['markdown_link_style'],
- 'install_requires': ['mistune>0.8,<1'],
- 'entry_points': {
- 'console_scripts': ['mdl-style = mdl_style:main']
- }
+ "keywords": "markdown link inline footnote style",
+ "py_modules": ["mdl_style"],
+ "packages": ["markdown_link_style"],
+ "install_requires": ["mistune>0.8,<1"],
+ "entry_points": {"console_scripts": ["mdl-style = mdl_style:main"]},
}
setup(**config)
diff --git a/tests/test_markdown_link_style/test_logging.py b/tests/test_markdown_link_style/test_logging.py
index d4aea87..1ce8c07 100644
--- a/tests/test_markdown_link_style/test_logging.py
+++ b/tests/test_markdown_link_style/test_logging.py
@@ -24,6 +24,7 @@ from io import StringIO
from markdown_link_style.logging import MDLSLogger
+
class TestMDLSLogger(object):
"""Test class for markdown_link_style.logging.MDLSLogger.
@@ -31,32 +32,32 @@ class TestMDLSLogger(object):
def setup(self):
self.stream = StringIO()
- self.logger = MDLSLogger('TestLogger', self.stream)
+ self.logger = MDLSLogger("TestLogger", self.stream)
def test_debug(self):
- log_msg = 'DEBUG::MSG'
+ log_msg = "DEBUG::MSG"
self.logger.debug(log_msg)
- assert self.stream.getvalue().strip('\n') == log_msg
+ assert self.stream.getvalue().strip("\n") == log_msg
def test_info(self):
- log_msg = 'DEBUG::INFO'
+ log_msg = "DEBUG::INFO"
self.logger.info(log_msg)
- assert self.stream.getvalue().strip('\n') == log_msg
+ assert self.stream.getvalue().strip("\n") == log_msg
def test_warning(self):
- log_msg = 'DEBUG::WARNING'
+ log_msg = "DEBUG::WARNING"
self.logger.warning(log_msg)
- assert self.stream.getvalue().strip('\n') == log_msg
+ assert self.stream.getvalue().strip("\n") == log_msg
def test_error(self):
- log_msg = 'DEBUG::ERROR'
+ log_msg = "DEBUG::ERROR"
self.logger.error(log_msg)
- assert self.stream.getvalue().strip('\n') == log_msg
+ assert self.stream.getvalue().strip("\n") == log_msg
def test_critical(self):
- log_msg = 'DEBUG::CRITICAL'
+ log_msg = "DEBUG::CRITICAL"
self.logger.critical(log_msg)
- assert self.stream.getvalue().strip('\n') == log_msg
+ assert self.stream.getvalue().strip("\n") == log_msg
def teardown(self):
pass
diff --git a/tests/test_mdl_style.py b/tests/test_mdl_style.py
index 23372fd..a593240 100644
--- a/tests/test_mdl_style.py
+++ b/tests/test_mdl_style.py
@@ -37,12 +37,15 @@ from markdown_link_style._version import __version__
from mdl_style import *
from mdl_style import _get_args, _mdl_stylize
+
def _get_data(f):
- rs = resource_string(__name__, '/'.join(['data', f]))
+ rs = resource_string(__name__, "/".join(["data", f]))
return rs.decode()
+
def _get_data_path(f):
- return resource_filename(__name__, '/'.join(['data', f]))
+ return resource_filename(__name__, "/".join(["data", f]))
+
class TestLSRendererIL(object):
"""Test class for mdl_style.LSRenderer inline link style.
@@ -50,59 +53,58 @@ class TestLSRendererIL(object):
"""
def setup(self):
- self.md = LSMarkdown(link_style='inline')
+ self.md = LSMarkdown(link_style="inline")
def test_autolink_00(self):
- d = _get_data('autolink_00.md')
- d_expected = _get_data('autolink_00-expected.md')
+ d = _get_data("autolink_00.md")
+ d_expected = _get_data("autolink_00-expected.md")
assert_equals(self.md(d), d_expected)
def test_link_footnote_to_inline_style_conversion_00(self):
- d = _get_data('inline_link_style_00.md')
- expected_result = _get_data('inline_link_style_00-expected.md')
+ d = _get_data("inline_link_style_00.md")
+ expected_result = _get_data("inline_link_style_00-expected.md")
assert_equal(self.md(d), expected_result)
def test_link_footnote_to_inline_style_conversion_01(self):
- d = _get_data('inline_link_style_01.md')
- expected_result = _get_data('inline_link_style_01-expected.md')
+ d = _get_data("inline_link_style_01.md")
+ expected_result = _get_data("inline_link_style_01-expected.md")
assert_equal(self.md(d), expected_result)
def test_renderer_parses_images_00(self):
- d = _get_data('inline_parses_images_00.md')
- expected_result = _get_data(
- 'inline_parses_images_00-expected.md')
+ d = _get_data("inline_parses_images_00.md")
+ expected_result = _get_data("inline_parses_images_00-expected.md")
assert_equal(self.md(d), expected_result)
def test_renderer_does_not_parse_link_breaks_00(self):
- d = _get_data('does_not_parse_link_breaks_00.md')
+ d = _get_data("does_not_parse_link_breaks_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_headers_00(self):
- d = _get_data('does_not_parse_headers_00.md')
+ d = _get_data("does_not_parse_headers_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_blockquotes_00(self):
- d = _get_data('does_not_parse_blockquotes_00.md')
+ d = _get_data("does_not_parse_blockquotes_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_lists_00(self):
- d = _get_data('does_not_parse_lists_00.md')
+ d = _get_data("does_not_parse_lists_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_codeblocks_00(self):
- d = _get_data('does_not_parse_codeblocks_00.md')
+ d = _get_data("does_not_parse_codeblocks_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_hrules_00(self):
- d = _get_data('does_not_parse_hrules_00.md')
+ d = _get_data("does_not_parse_hrules_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_emphasis_00(self):
- d = _get_data('does_not_parse_emphasis_00.md')
+ d = _get_data("does_not_parse_emphasis_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_code_00(self):
- d = _get_data('does_not_parse_code_00.md')
+ d = _get_data("does_not_parse_code_00.md")
assert_equal(self.md(d), d)
def teardown(self):
@@ -115,61 +117,58 @@ class TestLSRendererFN(object):
"""
def setup(self):
- self.md = LSMarkdown(link_style='footnote')
+ self.md = LSMarkdown(link_style="footnote")
def test_autolink_00(self):
- d = _get_data('autolink_00.md')
- d_expected = _get_data('autolink_00-expected.md')
+ d = _get_data("autolink_00.md")
+ d_expected = _get_data("autolink_00-expected.md")
assert_equals(self.md(d), d_expected)
def test_link_inline_to_footnote_style_conversion_00(self):
- d = _get_data('footnote_link_style_00.md')
- expected_result = _get_data(
- 'footnote_link_style_00-expected.md')
+ d = _get_data("footnote_link_style_00.md")
+ expected_result = _get_data("footnote_link_style_00-expected.md")
assert_equal(self.md(d), expected_result)
def test_link_inline_to_footnote_style_conversion_01(self):
- d = _get_data('footnote_link_style_01.md')
- expected_result = _get_data(
- 'footnote_link_style_01-expected.md')
+ d = _get_data("footnote_link_style_01.md")
+ expected_result = _get_data("footnote_link_style_01-expected.md")
assert_equal(self.md(d), expected_result)
def test_renderer_parses_images_00(self):
- d = _get_data('footnote_parses_images_00.md')
- expected_result = _get_data(
- 'footnote_parses_images_00-expected.md')
+ d = _get_data("footnote_parses_images_00.md")
+ expected_result = _get_data("footnote_parses_images_00-expected.md")
assert_equal(self.md(d), expected_result)
def test_renderer_does_not_parse_link_breaks_00(self):
- d = _get_data('does_not_parse_link_breaks_00.md')
+ d = _get_data("does_not_parse_link_breaks_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_headers_00(self):
- d = _get_data('does_not_parse_headers_00.md')
+ d = _get_data("does_not_parse_headers_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_blockquotes_00(self):
- d = _get_data('does_not_parse_blockquotes_00.md')
+ d = _get_data("does_not_parse_blockquotes_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_lists_00(self):
- d = _get_data('does_not_parse_lists_00.md')
+ d = _get_data("does_not_parse_lists_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_codeblocks_00(self):
- d = _get_data('does_not_parse_codeblocks_00.md')
+ d = _get_data("does_not_parse_codeblocks_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_hrules_00(self):
- d = _get_data('does_not_parse_hrules_00.md')
+ d = _get_data("does_not_parse_hrules_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_emphasis_00(self):
- d = _get_data('does_not_parse_emphasis_00.md')
+ d = _get_data("does_not_parse_emphasis_00.md")
assert_equal(self.md(d), d)
def test_renderer_does_not_parse_code_00(self):
- d = _get_data('does_not_parse_code_00.md')
+ d = _get_data("does_not_parse_code_00.md")
assert_equal(self.md(d), d)
def teardown(self):
@@ -185,46 +184,38 @@ class TestMdlStyleMdlStylize(object):
def setup_class(self):
self.test_data = {}
- self.test_data['inline'] = {}
- self.test_data['inline']['in'] = _get_data(
- 'inline_link_style_00.md')
- self.test_data['inline']['out'] = _get_data(
- 'inline_link_style_00-expected.md')
-
- self.test_data['footnote'] = {}
- self.test_data['footnote']['in'] = _get_data(
- 'footnote_link_style_00.md')
- self.test_data['footnote']['out'] = _get_data(
- 'footnote_link_style_00-expected.md')
+ self.test_data["inline"] = {}
+ self.test_data["inline"]["in"] = _get_data("inline_link_style_00.md")
+ self.test_data["inline"]["out"] = _get_data("inline_link_style_00-expected.md")
- self.in_file = 'in_file.md'
- self.out_file = 'out_file.md'
+ self.test_data["footnote"] = {}
+ self.test_data["footnote"]["in"] = _get_data("footnote_link_style_00.md")
+ self.test_data["footnote"]["out"] = _get_data(
+ "footnote_link_style_00-expected.md"
+ )
+ self.in_file = "in_file.md"
+ self.out_file = "out_file.md"
def setup(self):
- self.link_style = ['inline', 'footnote'][randint(0, 1)]
-
- with open(self.in_file, 'w') as f:
- f.write(self.test_data[self.link_style]['in'])
+ self.link_style = ["inline", "footnote"][randint(0, 1)]
+ with open(self.in_file, "w") as f:
+ f.write(self.test_data[self.link_style]["in"])
def test_mdl_stylize_infile(self):
args = _get_args([self.link_style, self.in_file])
- _mdl_stylize(args) # the test.
-
- with open(self.in_file, 'r') as f:
- assert_equal(f.read(),
- self.test_data[self.link_style]['out'])
+ _mdl_stylize(args) # the test.
+ with open(self.in_file, "r") as f:
+ assert_equal(f.read(), self.test_data[self.link_style]["out"])
def test_mdl_stylize_infile_outfile(self):
args = _get_args([self.link_style, self.in_file, self.out_file])
_mdl_stylize(args)
- with open(self.out_file, 'r') as f:
- assert_equal(f.read(),
- self.test_data[self.link_style]['out'])
-
+ with open(self.out_file, "r") as f:
+ assert_equal(f.read(), self.test_data[self.link_style]["out"])
def teardown(self):
if os.path.isfile(self.in_file):
@@ -242,58 +233,53 @@ class TestMdlStyleGetArgs(object):
def setup(self):
self.out = None
-
@raises(SystemExit)
def test_get_args_version(self):
real_exit = sys.exit
+
def mock_exit(args):
- assert_equal(sys.stdout.getvalue(),
- __version__ + '\n')
+ assert_equal(sys.stdout.getvalue(), __version__ + "\n")
real_exit(args)
- with mock.patch('sys.stdout', new_callable=StringIO) as out, \
- mock.patch('sys.exit', new=mock_exit):
- raw_args = ['--version']
+ with mock.patch("sys.stdout", new_callable=StringIO) as out, mock.patch(
+ "sys.exit", new=mock_exit
+ ):
+ raw_args = ["--version"]
_get_args(raw_args)
-
def test_get_args_inline_infile(self):
- lstyle = 'inline'
- md_file = 'autolink_00.md'
+ lstyle = "inline"
+ md_file = "autolink_00.md"
raw_args = [lstyle, _get_data_path(md_file)]
args = _get_args(raw_args)
assert_equal(args.link_style, lstyle)
assert_equal(args.in_file.read(), _get_data(md_file))
-
def test_get_args_inline_infile_outfile(self):
- lstyle = 'inline'
- md_file = 'autolink_00.md'
- raw_args = [lstyle, _get_data_path(md_file), 'outfile.md']
+ lstyle = "inline"
+ md_file = "autolink_00.md"
+ raw_args = [lstyle, _get_data_path(md_file), "outfile.md"]
args = _get_args(raw_args)
assert_equal(args.link_style, lstyle)
assert_equal(args.in_file.read(), _get_data(md_file))
assert_equal(type(args.out_file), str)
-
def test_get_args_footnote_infile(self):
- lstyle = 'footnote'
- md_file = 'autolink_00.md'
+ lstyle = "footnote"
+ md_file = "autolink_00.md"
raw_args = [lstyle, _get_data_path(md_file)]
args = _get_args(raw_args)
assert_equal(args.link_style, lstyle)
assert_equal(args.in_file.read(), _get_data(md_file))
-
def test_get_args_footnote_infile_outfile(self):
- lstyle = 'footnote'
- md_file = 'autolink_00.md'
- raw_args = [lstyle, _get_data_path(md_file), 'outfile.md']
+ lstyle = "footnote"
+ md_file = "autolink_00.md"
+ raw_args = [lstyle, _get_data_path(md_file), "outfile.md"]
args = _get_args(raw_args)
assert_equal(args.link_style, lstyle)
assert_equal(args.in_file.read(), _get_data(md_file))
assert_equal(type(args.out_file), str)
-
def teardown(self):
pass