Switch to pytest

This commit is contained in:
Matthew Tretter
2013-07-31 16:54:37 -04:00
parent b92428466d
commit c2f32b8049
9 changed files with 147 additions and 131 deletions

0
tests/__init__.py Normal file
View File

6
tests/test_advanced.py Normal file
View File

@@ -0,0 +1,6 @@
from markdownify import markdownify as md
def test_nested():
text = md('<p>This is an <a href="http://example.com/">example link</a>.</p>')
assert text == 'This is an [example link](http://example.com/).\n\n'

25
tests/test_args.py Normal file
View File

@@ -0,0 +1,25 @@
"""
Test whitelisting/blacklisting of specific tags.
"""
from markdownify import markdownify as md
def test_strip():
text = md('<a href="https://github.com/matthewwithanm">Some Text</a>', strip=['a'])
assert text == 'Some Text'
def test_do_not_strip():
text = md('<a href="https://github.com/matthewwithanm">Some Text</a>', strip=[])
assert text == '[Some Text](https://github.com/matthewwithanm)'
def test_convert():
text = md('<a href="https://github.com/matthewwithanm">Some Text</a>', convert=['a'])
assert text == '[Some Text](https://github.com/matthewwithanm)'
def test_do_not_convert():
text = md('<a href="https://github.com/matthewwithanm">Some Text</a>', convert=[])
assert text == 'Some Text'

13
tests/test_basic.py Normal file
View File

@@ -0,0 +1,13 @@
from markdownify import markdownify as md
def test_single_tag():
assert md('<span>Hello</span>') == 'Hello'
def test_soup():
assert md('<div><span>Hello</div></span>') == 'Hello'
def test_whitespace():
assert md(' a b \n\n c ') == ' a b c '

64
tests/test_conversions.py Normal file
View File

@@ -0,0 +1,64 @@
from markdownify import markdownify as md
def test_a():
assert md('<a href="http://google.com">Google</a>') == '[Google](http://google.com)'
def test_a_with_title():
text = md('<a href="http://google.com" title="The &quot;Goog&quot;">Google</a>')
assert text == r'[Google](http://google.com "The \"Goog\"")'
def test_b():
assert md('<b>Hello</b>') == '**Hello**'
def test_blockquote():
assert md('<blockquote>Hello</blockquote>').strip() == '> Hello'
def test_nested_blockquote():
text = md('<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>').strip()
assert text == '> And she was like \n> > Hello'
def test_br():
assert md('a<br />b<br />c') == 'a \nb \nc'
def test_em():
assert md('<em>Hello</em>') == '*Hello*'
def test_h1():
assert md('<h1>Hello</h1>') == 'Hello\n=====\n\n'
def test_h2():
assert md('<h2>Hello</h2>') == 'Hello\n-----\n\n'
def test_hn():
assert md('<h3>Hello</h3>') == '### Hello\n\n'
assert md('<h6>Hello</h6>') == '###### Hello\n\n'
def test_i():
assert md('<i>Hello</i>') == '*Hello*'
def test_ol():
assert md('<ol><li>a</li><li>b</li></ol>') == '1. a\n2. b\n'
def test_p():
assert md('<p>hello</p>') == 'hello\n\n'
def test_strong():
assert md('<strong>Hello</strong>') == '**Hello**'
def test_ul():
assert md('<ul><li>a</li><li>b</li></ul>') == '* a\n* b\n'

22
tests/test_escaping.py Normal file
View File

@@ -0,0 +1,22 @@
from markdownify import markdownify as md
def test_underscore():
assert md('_hey_dude_') == '\_hey\_dude\_'
def test_xml_entities():
assert md('&amp;') == '&'
def test_named_entities():
assert md('&raquo;') == u'\xbb'
def test_hexadecimal_entities():
# This looks to be a bug in BeautifulSoup (fixed in bs4) that we have to work around.
assert md('&#x27;') == '\x27'
def test_single_escaping_entities():
assert md('&amp;amp;') == '&amp;'