summaryrefslogtreecommitdiffstats
path: root/tests/test_md_tw.py
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-07-24 00:40:01 +0000
committerrsiddharth <s@ricketyspace.net>2017-07-24 00:40:01 +0000
commitb5bc0fc9cbe3df899a12ec1bfe90bd8fa21ddd74 (patch)
tree87223c1645ba9c9f4c40a61ce152a79a57dd4af7 /tests/test_md_tw.py
parent40861fcbc949bf1f1835399f76e096192bccb319 (diff)
md_tw.py: Add Text Wrap classes (derived from mistune' classes).
* md_tw.py (TWBlockLexer, TWInlineLexer, TWRenderer) (TWMarkdown): New classes. * tests/data/paragraphs-with-inline-wrapped.md: New file. * tests/data/paragraphs-with-inline.md: New file. * tests/data/paragraphs-wrapped.md: New file. * tests/data/paragraphs.md: New file. * tests/test_md_tw.py (TestTWBlockLexer, TestTWInlineLexer, TestTWRenderer, TestTWMarkdown) (TestTextWrapParagraphs): New test classes.
Diffstat (limited to 'tests/test_md_tw.py')
-rw-r--r--tests/test_md_tw.py150
1 files changed, 149 insertions, 1 deletions
diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py
index 7d9e4d9..d8a7f92 100644
--- a/tests/test_md_tw.py
+++ b/tests/test_md_tw.py
@@ -18,9 +18,13 @@
# along with markdown-textwrap (see COPYING). If not, see
# <http://www.gnu.org/licenses/>.
-from nose.tools import *
+import textwrap
+
+from mistune import Renderer
+from nose.tools import assert_equal
from pkg_resources import resource_string, resource_filename
+from md_tw import TWBlockLexer, TWInlineLexer, TWRenderer, TWMarkdown
def _get_data(f):
rs = resource_string(__name__, '/'.join(['data', f]))
@@ -29,3 +33,147 @@ def _get_data(f):
def _get_data_path(f):
return resource_filename(__name__, '/'.join(['data', f]))
+
+
+class TestTWBlockLexer(object):
+
+ def setup(self):
+ self.bl = TWBlockLexer()
+
+
+ def test_default_rules_contents(self):
+ assert_equal(self.bl.default_rules, ['paragraph', 'text'])
+
+
+ def teardown(self):
+ pass
+
+
+class TestTWInlineLexer(object):
+
+ def setup(self):
+ renderer = Renderer()
+ self.il = TWInlineLexer(renderer)
+
+
+ def test_default_rules_contents(self):
+ assert_equal(self.il.default_rules, [])
+
+
+ def teardown(self):
+ pass
+
+
+class TestTWRenderer(object):
+
+ def setup(self):
+ pass
+
+
+ def test_tw_obj_with_default_width(self):
+ renderer = TWRenderer()
+
+ # Check existence of textwrap.TexWrapper object.
+ assert isinstance(renderer.tw, textwrap.TextWrapper)
+
+ # Check its width
+ assert_equal(renderer.tw.width, 72)
+
+
+ def test_tw_obj_with_custom_width(self):
+ renderer = TWRenderer(tw_width=80)
+
+ # Check existence of textwrap.TexWrapper object.
+ assert isinstance(renderer.tw, textwrap.TextWrapper)
+
+ # Check its width
+ assert_equal(renderer.tw.width, 80)
+
+
+ def test_tw_set_options_with_valid_opts(self):
+ renderer = TWRenderer()
+
+ # Set valid options
+ renderer._tw_set_options(
+ width=80,
+ initial_indent='> ',
+ subsequent_indent=' ',
+ drop_whitespace=False)
+
+ # Confirm options are set.
+ assert_equal(renderer.tw.width, 80)
+ assert_equal(renderer.tw.initial_indent, '> ')
+ assert_equal(renderer.tw.subsequent_indent, ' ')
+ assert_equal(renderer.tw.drop_whitespace, False)
+
+
+ def test_tw_set_options_with_invalid_opts(self):
+ renderer = TWRenderer()
+
+ # Set invalid options
+ renderer._tw_set_options(
+ erase_bumps=True,
+ destroy_ampersands=False,
+ end_width='வருகிறேன்',
+ insert_between_paragraphs='time bombs')
+
+ # Confirm options are not set.
+ assert_equal(getattr(renderer.tw, 'erase_bumps', None), None)
+ assert_equal(getattr(renderer.tw, 'destroy_ampersands',
+ None), None)
+ assert_equal(getattr(renderer.tw, 'end_width', None), None)
+ assert_equal(getattr(renderer.tw, 'insert_between_paragraphs',
+ None), None)
+
+
+ def teardown(self):
+ pass
+
+
+class TestTWMarkdown(object):
+
+ def setup(self):
+ self.md = TWMarkdown()
+
+
+ def test_renderer_obj(self):
+ assert isinstance(self.md.renderer, TWRenderer)
+
+
+ def test_inline_obj(self):
+ assert isinstance(self.md.inline, TWInlineLexer)
+
+
+ def test_block_obj(self):
+ assert isinstance(self.md.block, TWBlockLexer)
+
+
+ def teardown(self):
+ pass
+
+
+class TestTextWrapParagraphs(object):
+
+ def setup(self):
+ self.md = TWMarkdown()
+
+
+ def test_tw_plain_paragraphs(self):
+ txt = _get_data('paragraphs.md')
+ expected_wrapped_txt = _get_data('paragraphs-wrapped.md')
+
+ wrapped_txt = self.md(txt)
+ assert_equal(wrapped_txt, expected_wrapped_txt)
+
+
+ def test_tw_paragraphs_with_inline(self):
+ txt = _get_data('paragraphs-with-inline.md')
+ expected_wrapped_txt = _get_data(
+ 'paragraphs-with-inline-wrapped.md')
+
+ wrapped_txt = self.md(txt)
+ assert_equal(wrapped_txt, expected_wrapped_txt)
+
+
+ def teardown(self):
+ pass