Skip to content

Commit 08e4dca

Browse files
committed
Merge pull request #4 from msabramo/rst_tests
Add tests for RST rendering
2 parents b4543f1 + d6225b3 commit 08e4dca

13 files changed

+139
-0
lines changed

tests/fixtures/test_rst_003.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div id="required-packages">
2+
<h2>Required packages</h2>
3+
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
4+
</div>
5+
<div id="quick-development-setup">
6+
<h2>Quick development setup</h2>
7+
<p>Make sure you are sitting</p>
8+
</div>

tests/fixtures/test_rst_003.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Required packages
2+
-----------------
3+
4+
To run the PyPI software, you need Python 2.5+ and PostgreSQL
5+
6+
7+
Quick development setup
8+
-----------------------
9+
10+
Make sure you are sitting

tests/fixtures/test_rst_004.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>&lt;div id=”required-packages”&gt;
2+
&lt;h2&gt;Required packages&lt;/h2&gt;
3+
&lt;p&gt;To run the PyPI software, you need Python 2.5+ and PostgreSQL&lt;/p&gt;
4+
&lt;/div&gt;
5+
&lt;div id=”quick-development-setup”&gt;
6+
&lt;h2&gt;Quick development setup&lt;/h2&gt;
7+
&lt;p&gt;Make sure you are sitting&lt;/p&gt;
8+
&lt;/div&gt;</p>

tests/fixtures/test_rst_004.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div id="required-packages">
2+
<h2>Required packages</h2>
3+
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
4+
</div>
5+
<div id="quick-development-setup">
6+
<h2>Quick development setup</h2>
7+
<p>Make sure you are sitting</p>
8+
</div>

tests/fixtures/test_rst_005.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>&lt;a href=”<a rel="nofollow" href="http://mymalicioussite.com/">http://mymalicioussite.com/</a>”&gt;Click here&lt;/a&gt;</p>

tests/fixtures/test_rst_005.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href="http://mymalicioussite.com/">Click here</a>

tests/fixtures/test_rst_006.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>&lt;iframe src=”<a rel="nofollow" href="http://mymalicioussite.com/">http://mymalicioussite.com/</a>”&gt;Click here&lt;/iframe&gt;</p>

tests/fixtures/test_rst_006.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<iframe src="http://mymalicioussite.com/">Click here</iframe>

tests/fixtures/test_rst_007.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Something naughty this way comes
2+
&lt;script&gt;
3+
alert("Hello");
4+
&lt;/script&gt;

tests/fixtures/test_rst_007.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Something naughty this way comes
2+
<script>
3+
alert("Hello");
4+
</script>

tests/fixtures/test_rst_008.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<p>Here is some Python code for a <tt>Dog</tt>:</p>
2+
<pre><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">Animal</span><span class="p">):</span>
3+
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
4+
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
5+
6+
<span class="k">def</span> <span class="nf">make_sound</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
7+
<span class="k">print</span><span class="p">(</span><span class="s">'Ruff!'</span><span class="p">)</span>
8+
9+
<span class="n">dog</span> <span class="o">=</span> <span class="n">Dog</span><span class="p">(</span><span class="s">'Fido'</span><span class="p">)</span>
10+
</pre>
11+
<p>and then here is some bash:</p>
12+
<pre><span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"--help"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
13+
<span class="nb">echo</span> <span class="s2">"OK"</span>
14+
<span class="k">fi</span>
15+
</pre>
16+
<p>or click <a rel="nofollow" href="http://www.surveymonkey.com">SurveyMonkey</a></p>

tests/fixtures/test_rst_008.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Here is some Python code for a ``Dog``:
2+
3+
.. code-block:: python
4+
5+
class Dog(Animal):
6+
def __init__(self, name):
7+
self.name = name
8+
9+
def make_sound(self):
10+
print('Ruff!')
11+
12+
dog = Dog('Fido')
13+
14+
and then here is some bash:
15+
16+
.. code-block:: bash
17+
18+
if [ "$1" = "--help" ]; then
19+
echo "OK"
20+
fi
21+
22+
or click `SurveyMonkey <http://www.surveymonkey.com>`_

tests/test_rst.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import codecs
2+
import os
3+
4+
from readme.rst import render
5+
6+
7+
def test_rst_001():
8+
assert render('Hello') == ('<p>Hello</p>\n', True)
9+
10+
11+
def test_rst_002():
12+
assert render('http://mymalicioussite.com/') == (
13+
('<p><a rel="nofollow" href="http://mymalicioussite.com/">' +
14+
'http://mymalicioussite.com/</a></p>\n'),
15+
True)
16+
17+
18+
def test_rst_003():
19+
_do_test_with_files('test_rst_003')
20+
21+
22+
def test_rst_004():
23+
_do_test_with_files('test_rst_004')
24+
25+
26+
def test_rst_005():
27+
_do_test_with_files('test_rst_005')
28+
29+
30+
def test_rst_006():
31+
_do_test_with_files('test_rst_006')
32+
33+
34+
def test_rst_007():
35+
_do_test_with_files('test_rst_007', expected_rendered=False)
36+
37+
38+
def test_rst_008():
39+
_do_test_with_files('test_rst_008')
40+
41+
42+
def _do_test_with_files(test_name, expected_rendered=True):
43+
rst_markup = read('{0}.rst'.format(test_name))
44+
expected_html = read('{0}.html'.format(test_name))
45+
46+
out, rendered = render(rst_markup)
47+
48+
assert rendered == expected_rendered
49+
assert out == expected_html
50+
51+
52+
def read(fn):
53+
path = os.path.join(os.path.dirname(__file__), 'fixtures', fn)
54+
with codecs.open(path, encoding='utf-8') as f:
55+
return f.read()

0 commit comments

Comments
 (0)