[py-svn] r33467 - in py/dist/py/rst: . testing
guido at codespeak.net
guido at codespeak.net
Thu Oct 19 17:49:56 CEST 2006
Author: guido
Date: Thu Oct 19 17:49:54 2006
New Revision: 33467
Modified:
py/dist/py/rst/rst.py
py/dist/py/rst/testing/test_rst.py
Log:
Added some tests, removed some ugly hack (previous_paragraph stuff) to have
the blockquote :: right behind the previous item, in favour of having a less
nice looking result (\n\n:).
Modified: py/dist/py/rst/rst.py
==============================================================================
--- py/dist/py/rst/rst.py (original)
+++ py/dist/py/rst/rst.py Thu Oct 19 17:49:54 2006
@@ -90,8 +90,6 @@
def text(self):
outcome = []
for child in self.childs:
- if child.previous_paragraph and len(outcome):
- outcome[-1] += child.previous_paragraph
outcome.append(child.text())
text = self.sep.join(outcome) + "\n" # trailing newline
@@ -102,7 +100,6 @@
sep = " "
indent = ""
width = 80
- previous_paragraph = ""
def __init__(self, *args, **kwargs):
# make shortcut
@@ -146,19 +143,17 @@
class BlockQuote(Paragraph):
indent = " "
- previous_paragraph = "\n::"
sep = ""
def text(self):
all_txt = AbstractNode.text(self)
all_txts = all_txt.split("\n")
- return '%s\n' % ("\n".join([self.indent + i for i in all_txts]),)
+ return '::\n\n%s' % ("\n".join([self.indent + i for i in all_txts]),)
class Title(Paragraph):
parentclass = Rest
belowchar = ""
abovechar = ""
- previous_paragraph = None
def text(self):
txt = Paragraph.text(self)
Modified: py/dist/py/rst/testing/test_rst.py
==============================================================================
--- py/dist/py/rst/testing/test_rst.py (original)
+++ py/dist/py/rst/testing/test_rst.py Thu Oct 19 17:49:54 2006
@@ -4,37 +4,84 @@
from py.__.rst.rst import *
-def test_textgen():
- assert Rest(Paragraph(Text("dupa"))).text() == "dupa\n"
- assert Rest(Paragraph(Text("dupa"), Text("dupa"))).text() == "dupa dupa\n"
- assert Rest(Paragraph(Text("a")), Paragraph(Text("b"))).text() == "a\n\nb\n"
- assert Rest(Paragraph(Text("a"), indent=" ")).text() == " a\n"
-
-def test_join():
- txt = Rest(Paragraph(Text("a b c d e f"), width=3, indent=" ")).text()
- assert txt == ' a\n b\n c\n d\n e\n f\n'
+def test_illegal_parent():
+ Rest(Paragraph(Text('spam')))
+ py.test.raises(RestError, 'Rest(Text("spam"))')
+ py.test.raises(RestError, 'ListItem(Paragraph(Text("eggs")))')
+
+def test_text_basic():
+ assert Text("dupa").text() == "dupa"
+
+def test_text_join():
+ assert Paragraph(Text("dupa"), Text("dupa")).text() == "dupa dupa"
+
+def test_paragraph_basic():
+ assert Paragraph(Text('spam')).text() == 'spam'
+
+def test_paragraph_string():
+ assert Paragraph("eggs").text() == "eggs"
+
+def test_paragraph_join():
+ assert Rest(Paragraph(Text("a")), Paragraph(Text("b"))).text() == (
+ "a\n\nb\n")
+
+def test_paragraph_indent():
+ assert Paragraph(Text("a"), indent=" ").text() == " a"
+ assert Paragraph(Text(" a "), indent=" ").text() == " a"
+
+def test_paragraph_width():
+ txt = Paragraph(Text("a b c d e f"), width=3, indent=" ").text()
+ assert txt == ' a\n b\n c\n d\n e\n f'
+ text = """
+Lorem ipsum dolor sit amet, consectetuer
+adipiscing elit. Vestibulum malesuada
+eleifend leo. Sed faucibus commodo libero.
+Mauris elementum fringilla velit. Ut
+sem urna, aliquet sed, molestie at, viverra
+id, justo. In ornare lacinia turpis. Etiam
+et ipsum. Quisque at lacus. Etiam
+pellentesque, enim porta pulvinar viverra,
+libero elit iaculis justo, vitae convallis
+pede purus vel arcu. Morbi aliquam lacus
+et urna. Donec commodo pellentesque mi.
+"""
+ expected = """\
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum malesuada
+eleifend leo. Sed faucibus commodo libero. Mauris elementum fringilla velit. Ut
+sem urna, aliquet sed, molestie at, viverra id, justo. In ornare lacinia
+turpis. Etiam et ipsum. Quisque at lacus. Etiam pellentesque, enim porta
+pulvinar viverra, libero elit iaculis justo, vitae convallis pede purus vel
+arcu. Morbi aliquam lacus et urna. Donec commodo pellentesque mi."""
+ ret = Paragraph(text, width=80).text()
+ print repr(ret)
+ print repr(expected)
+ assert ret == expected
+
+def test_paragraph_stripping():
+ txt = Paragraph(Text('\n foo bar\t')).text()
+ assert txt == 'foo bar'
def test_blockquote():
expected = """\
Text
+
::
def fun():
some
-
Paragraph
"""
txt = Rest(Paragraph("Text"), BlockQuote("def fun():\n some"), \
- Paragraph("Paragraph")).text()
+ Paragraph("Paragraph")).text()
print repr(txt)
assert txt == expected
def test_title():
- assert Rest(Title(Text("Some title"), belowchar="=")).text() == \
- "Some title\n==========\n"
- assert Rest(Title(Text("Some title"), belowchar="#", abovechar="#")).text() \
- == "##########\nSome title\n##########\n"
+ txt = Title(Text("Some title"), belowchar="=").text()
+ assert txt == "Some title\n=========="
+ txt = Title(Text("Some title"), belowchar="#", abovechar="#").text()
+ assert txt == "##########\nSome title\n##########"
def test_link():
expected = "`some link`_\n.. _`some link`: http://codespeak.net\n"
More information about the pytest-commit
mailing list