[py-svn] r33721 - in py/dist/py/rst: . testing

guido at codespeak.net guido at codespeak.net
Wed Oct 25 15:58:16 CEST 2006


Author: guido
Date: Wed Oct 25 15:58:11 2006
New Revision: 33721

Modified:
   py/dist/py/rst/rst.py
   py/dist/py/rst/testing/test_rst.py
Log:
Checking HTML results for certain elements now, added check for duplicate link
names with different targets.


Modified: py/dist/py/rst/rst.py
==============================================================================
--- py/dist/py/rst/rst.py	(original)
+++ py/dist/py/rst/rst.py	Wed Oct 25 15:58:11 2006
@@ -291,6 +291,8 @@
     def text(self):
         if self.rest is None:
             self.rest = self.find_rest()
+        if self.rest.links.get(self._text, self.target) != self.target:
+            raise ValueError('link name already in use for a different target')
         self.rest.links[self._text] = self.target
         return AbstractText.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	Wed Oct 25 15:58:11 2006
@@ -21,37 +21,55 @@
         i += 1
     tempfile.write(rest)
     restcheck(tempfile)
+    return tempfile.new(ext='.html').read()
 
-def test_escape():
+def test_escape_text():
     txt = Paragraph('*escape* ``test``').text()
     assert txt == '\\*escape\\* \\`\\`test\\`\\`'
-    checkrest(txt)
-    txt = Paragraph(Em('*strong*')).text()
-    # docutils doesn't require escaping here (it's greedy)
-    assert txt == '*\\*strong\\**'
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '*escape* ``test``' in html
+
+def test_escape_markup_simple():
+    txt = Paragraph(Em('*em*')).text()
+    assert txt == '*\\*em\\**'
+    html = checkrest(txt)
+    assert '<em>*em*</em>' in html
+
+def test_escape_underscore():
     txt = Rest(Paragraph('foo [1]_')).text()
     assert txt == "foo [1]\\_\n"
-    checkrest(txt)
-    # hmmm...
+    html = checkrest(txt)
+    assert 'foo [1]_' in html
+
+def test_escape_markup_spaces_docutils_nastyness():
     txt = Rest(Paragraph(Em('foo *bar* baz'))).text()
     assert txt == '*foo \\*bar\\* baz*\n'
+    html = checkrest(txt)
+    assert '<em>foo *bar* baz</em>' in html
 
 def test_escape_literal():
     txt = LiteralBlock('*escape* ``test``').text()
     assert txt == '::\n\n *escape* ``test``'
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '>\n*escape* ``test``\n</pre>' in html
 
-def test_escape_markup():
+def test_escape_markup_obvious():
     txt = Em('foo*bar').text()
     assert txt == '*foo\\*bar*'
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '<em>foo*bar</em>' in html
+
+def test_escape_markup_text_1():
     txt = Paragraph(Em('foo'), "*bar").text()
     assert txt == '*foo* \\*bar'
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '<em>foo</em> *bar' in html
+
+def test_escape_markup_text_2():
     txt = Paragraph(Em('foo'), "bar*").text()
     assert txt == '*foo* bar\\*'
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '<em>foo</em> bar*' in html
 
 def test_illegal_parent():
     Rest(Paragraph(Text('spam')))
@@ -61,25 +79,22 @@
 def test_text_basic():
     txt = Text("dupa").text()
     assert txt == "dupa"
-    checkrest(txt)
 
 def test_basic_inline():
     txt = Em('foo').text()
     assert txt == '*foo*'
-    checkrest(txt)
+
+def test_basic_inline_2():
     txt = Strong('bar').text()
     assert txt == '**bar**'
-    checkrest(txt)
 
 def test_text_join():
     txt = Paragraph(Text("dupa"), Text("dupa")).text()
     assert txt == "dupa dupa"
-    checkrest(txt)
 
 def test_paragraph_basic():
     txt = Paragraph(Text('spam')).text()
     assert txt == 'spam'
-    checkrest(txt)
 
 def test_paragraph_string():
     txt = Paragraph("eggs").text()
@@ -89,7 +104,6 @@
 def test_paragraph_join():
     txt = Rest(Paragraph(Text("a")), Paragraph(Text("b"))).text()
     assert txt == "a\n\nb\n"
-    checkrest(txt)
 
 def test_paragraph_indent():
     txt = Paragraph(Text("a"), indent=" ").text()
@@ -97,7 +111,6 @@
     checkrest(txt)
     txt = Paragraph(Text("  a "), indent=" ").text()
     assert txt == " a"
-    checkrest(txt)
 
 def test_paragraph_width():
     txt = Paragraph(Text("a b c d e f"), width=3, indent=" ").text()
@@ -157,19 +170,26 @@
     checkrest(txt)
     txt =  Title(Text("Some title"), belowchar="#", abovechar="#").text()
     assert txt == "##########\nSome title\n##########"
-    checkrest(txt)
+    html = checkrest(txt)
+    assert '>Some title</h1>' in html
 
 def test_link():
     expected = "`some link`_\n\n.. _`some link`: http://codespeak.net\n\n"
     txt = Rest(Paragraph(Link("some link", "http://codespeak.net"))).text()
     assert txt == expected
-    checkrest(txt)
+    html = checkrest(txt)
+    assert ' href="http://codespeak.net">some link</a>' in html
 
-def test_text():
-    expected = "This is a test!\n"
-    txt = Rest(Paragraph("This is a test!")).text()
+def test_link_same_text_and_target():
+    txt = Rest(Paragraph(Link('some link', 'bar'), 'foo',
+                         Link('some link', 'bar'))
+                         ).text()
+    expected = '`some link`_ foo `some link`_\n\n.. _`some link`: bar\n\n'
     assert txt == expected
-    checkrest(txt)
+
+def test_link_same_text_different_target():
+    py.test.raises(ValueError, ("Rest(Paragraph(Link('some link', 'foo'),"
+                                  "Link('some link', 'bar'))).text()"))
 
 def test_text_multiline():
     expected = """\



More information about the pytest-commit mailing list