Skip to content

Commit

Permalink
Merge pull request #4 from msabramo/rst_tests
Browse files Browse the repository at this point in the history
Add tests for RST rendering
  • Loading branch information
dstufft committed Dec 10, 2014
2 parents b4543f1 + d6225b3 commit 08e4dca
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/fixtures/test_rst_003.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="required-packages">
<h2>Required packages</h2>
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
</div>
<div id="quick-development-setup">
<h2>Quick development setup</h2>
<p>Make sure you are sitting</p>
</div>
10 changes: 10 additions & 0 deletions tests/fixtures/test_rst_003.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Required packages
-----------------

To run the PyPI software, you need Python 2.5+ and PostgreSQL


Quick development setup
-----------------------

Make sure you are sitting
8 changes: 8 additions & 0 deletions tests/fixtures/test_rst_004.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>&lt;div id=”required-packages”&gt;
&lt;h2&gt;Required packages&lt;/h2&gt;
&lt;p&gt;To run the PyPI software, you need Python 2.5+ and PostgreSQL&lt;/p&gt;
&lt;/div&gt;
&lt;div id=”quick-development-setup”&gt;
&lt;h2&gt;Quick development setup&lt;/h2&gt;
&lt;p&gt;Make sure you are sitting&lt;/p&gt;
&lt;/div&gt;</p>
8 changes: 8 additions & 0 deletions tests/fixtures/test_rst_004.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="required-packages">
<h2>Required packages</h2>
<p>To run the PyPI software, you need Python 2.5+ and PostgreSQL</p>
</div>
<div id="quick-development-setup">
<h2>Quick development setup</h2>
<p>Make sure you are sitting</p>
</div>
1 change: 1 addition & 0 deletions tests/fixtures/test_rst_005.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&lt;a href=”<a rel="nofollow" href="http://mymalicioussite.com/">http://mymalicioussite.com/</a>”&gt;Click here&lt;/a&gt;</p>
1 change: 1 addition & 0 deletions tests/fixtures/test_rst_005.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="http://mymalicioussite.com/">Click here</a>
1 change: 1 addition & 0 deletions tests/fixtures/test_rst_006.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&lt;iframe src=”<a rel="nofollow" href="http://mymalicioussite.com/">http://mymalicioussite.com/</a>”&gt;Click here&lt;/iframe&gt;</p>
1 change: 1 addition & 0 deletions tests/fixtures/test_rst_006.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe src="http://mymalicioussite.com/">Click here</iframe>
4 changes: 4 additions & 0 deletions tests/fixtures/test_rst_007.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Something naughty this way comes
&lt;script&gt;
alert("Hello");
&lt;/script&gt;
4 changes: 4 additions & 0 deletions tests/fixtures/test_rst_007.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Something naughty this way comes
<script>
alert("Hello");
</script>
16 changes: 16 additions & 0 deletions tests/fixtures/test_rst_008.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p>Here is some Python code for a <tt>Dog</tt>:</p>
<pre><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="n">Animal</span><span class="p">):</span>
<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>
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>

<span class="k">def</span> <span class="nf">make_sound</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'Ruff!'</span><span class="p">)</span>

<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>
</pre>
<p>and then here is some bash:</p>
<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>
<span class="nb">echo</span> <span class="s2">"OK"</span>
<span class="k">fi</span>
</pre>
<p>or click <a rel="nofollow" href="http://www.surveymonkey.com">SurveyMonkey</a></p>
22 changes: 22 additions & 0 deletions tests/fixtures/test_rst_008.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Here is some Python code for a ``Dog``:

.. code-block:: python
class Dog(Animal):
def __init__(self, name):
self.name = name
def make_sound(self):
print('Ruff!')
dog = Dog('Fido')
and then here is some bash:

.. code-block:: bash
if [ "$1" = "--help" ]; then
echo "OK"
fi
or click `SurveyMonkey <http://www.surveymonkey.com>`_
55 changes: 55 additions & 0 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import codecs
import os

from readme.rst import render


def test_rst_001():
assert render('Hello') == ('<p>Hello</p>\n', True)


def test_rst_002():
assert render('http://mymalicioussite.com/') == (
('<p><a rel="nofollow" href="http://mymalicioussite.com/">' +
'http://mymalicioussite.com/</a></p>\n'),
True)


def test_rst_003():
_do_test_with_files('test_rst_003')


def test_rst_004():
_do_test_with_files('test_rst_004')


def test_rst_005():
_do_test_with_files('test_rst_005')


def test_rst_006():
_do_test_with_files('test_rst_006')


def test_rst_007():
_do_test_with_files('test_rst_007', expected_rendered=False)


def test_rst_008():
_do_test_with_files('test_rst_008')


def _do_test_with_files(test_name, expected_rendered=True):
rst_markup = read('{0}.rst'.format(test_name))
expected_html = read('{0}.html'.format(test_name))

out, rendered = render(rst_markup)

assert rendered == expected_rendered
assert out == expected_html


def read(fn):
path = os.path.join(os.path.dirname(__file__), 'fixtures', fn)
with codecs.open(path, encoding='utf-8') as f:
return f.read()

0 comments on commit 08e4dca

Please sign in to comment.