summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-02-18 16:32:44 +0000
committerrsiddharth <s@ricketyspace.net>2018-02-18 16:35:10 +0000
commit7f6c9ef2bb7d5899aaba83446092c38e49878c55 (patch)
treeaec378748ffdf029952aea5d051fa1697918effc /tests
parent61202ae9dccdc44f50388ab03b2318df8db05808 (diff)
tests: Add test for TWRenderer.paragraph.
* tests/data/renderer-paragraphs-w.md: New file. * tests/data/renderer-paragraphs.md: New file. * tests/test_md_tw.py (TestTWRenderer)[test_render_paragraph]: Test for TWRenderer.paragraph. [setup, teardown]: Update methods. [_write_tmp, _get, _md, _validate]: New methods.
Diffstat (limited to 'tests')
-rw-r--r--tests/data/renderer-paragraphs-w.md25
-rw-r--r--tests/data/renderer-paragraphs.md18
-rw-r--r--tests/test_md_tw.py37
3 files changed, 78 insertions, 2 deletions
diff --git a/tests/data/renderer-paragraphs-w.md b/tests/data/renderer-paragraphs-w.md
new file mode 100644
index 0000000..c2078bd
--- /dev/null
+++ b/tests/data/renderer-paragraphs-w.md
@@ -0,0 +1,25 @@
+He used to say that there are only two sources of human vice—idleness
+and superstition, and only two virtues—activity and intelligence. He
+himself undertook his daughter's education, and to develop these two
+cardinal virtues in her gave her lessons in algebra and geometry till
+she was twenty, and arranged her life so that her whole time was
+occupied. He was himself always occupied: writing his memoirs, solving
+problems in higher mathematics, turning snuffboxes on a lathe, working
+in the garden, or superintending the building that was always going on
+at his estate.
+
+“Mere mobs!” repeated his new friend with a snort of scorn. “So you talk
+about mobs and the working classes as if they were the question. You’ve
+got that eternal idiotic idea that if anarchy came it would come from
+the poor. Why should it? The poor have been rebels, but they have never
+been anarchists; they have more interest than anyone else in there being
+some decent government. The poor man really has a stake in the country.
+The rich man hasn’t; he can go away to New Guinea in a yacht. The poor
+have sometimes objected to being governed badly; the rich have always
+objected to being governed at all. Aristocrats were always anarchists,
+as you can see from the barons’ wars.”
+
+Thanking You in Advance. This sounds as if the writer meant, "It will
+not be worth my while to write to you again." In making your request,
+write, "Will you please," or "I shall be obliged," and if anything
+further seems necessary write a letter of acknowledgment later.
diff --git a/tests/data/renderer-paragraphs.md b/tests/data/renderer-paragraphs.md
new file mode 100644
index 0000000..e809160
--- /dev/null
+++ b/tests/data/renderer-paragraphs.md
@@ -0,0 +1,18 @@
+He used to say that there are only two sources of human vice—idleness and superstition, and only two
+virtues—activity and intelligence. He himself undertook his daughter's education, and to develop
+these two cardinal virtues in her gave her lessons in algebra and geometry till she was twenty, and
+arranged her life so that her whole time was occupied. He was himself always occupied: writing his
+memoirs, solving problems in higher mathematics, turning snuffboxes on a lathe, working in the
+garden, or superintending the building that was always going on at his estate.
+
+“Mere mobs!” repeated his new friend with a snort of scorn. “So you talk about mobs and the working
+classes as if they were the question. You’ve got that eternal idiotic idea that if anarchy came it
+would come from the poor. Why should it? The poor have been rebels, but they have never been
+anarchists; they have more interest than anyone else in there being some decent government. The poor
+man really has a stake in the country. The rich man hasn’t; he can go away to New Guinea in a
+yacht. The poor have sometimes objected to being governed badly; the rich have always objected to
+being governed at all. Aristocrats were always anarchists, as you can see from the barons’ wars.”
+
+Thanking You in Advance. This sounds as if the writer meant, "It will not be worth my while to write
+to you again." In making your request, write, "Will you please," or "I shall be obliged," and if
+anything further seems necessary write a letter of acknowledgment later.
diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py
index ab2ca3e..780c0c7 100644
--- a/tests/test_md_tw.py
+++ b/tests/test_md_tw.py
@@ -18,6 +18,9 @@
# along with markdown-textwrap (see COPYING). If not, see
# <http://www.gnu.org/licenses/>.
+import os
+import shutil
+import tempfile
import textwrap
from mistune import Renderer
@@ -707,8 +710,32 @@ class TestTWInlineLexer(object):
class TestTWRenderer(object):
def setup(self):
- pass
+ self.md_wrap = TWMarkdown()
+
+ # temp stuff
+ self.tmp_dir = tempfile.mkdtemp(suffix='md-tw-renderer-tests')
+ self.del_tmp_dir = True
+
+ def _write_tmp(self, file_, txt):
+ with open(os.path.join(self.tmp_dir, file_), 'w') as f:
+ f.write(txt)
+
+ def _get(self, file_):
+ return _get_data(file_)
+
+ def _md(self, md_file):
+ txt = self._get(md_file)
+ wrapped = self.md_wrap(txt)
+ self._write_tmp(md_file, wrapped)
+ return wrapped
+
+ def _validate(self, txt, expected_txt):
+ txt_lines = txt.split('\n')
+ txt_lines.reverse()
+
+ for line in expected_txt.split('\n'):
+ nose_tools.assert_equal(line, txt_lines.pop())
def test_tw_obj_with_default_width(self):
renderer = TWRenderer()
@@ -765,9 +792,15 @@ class TestTWRenderer(object):
nose_tools.assert_equal(getattr(renderer.tw, 'insert_between_paragraphs',
None), None)
+ def test_render_paragraph(self):
+ txt = self._md('renderer-paragraphs.md')
+ expected_txt = self._get('renderer-paragraphs-w.md')
+
+ self._validate(txt, expected_txt)
def teardown(self):
- pass
+ if self.del_tmp_dir:
+ shutil.rmtree(self.tmp_dir)
class TestTWMarkdown(object):