Skip to content

Commit

Permalink
Use Unittest Asserts
Browse files Browse the repository at this point in the history
This patch switches to the assert statements provided by Python's unit
test framework to assure the statements are always executed and produce
proper error messages in case of test failures.
  • Loading branch information
lkiesow committed Jan 28, 2020
1 parent ffe3e4d commit 3371c28
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 175 deletions.
75 changes: 38 additions & 37 deletions tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,73 +44,73 @@ def setUp(self):
def test_setEntries(self):
fg2 = FeedGenerator()
fg2.entry(self.fg.entry())
assert len(fg2.entry()) == 3
assert self.fg.entry() == fg2.entry()
self.assertEqual(len(fg2.entry()), 3)
self.assertEqual(self.fg.entry(), fg2.entry())

def test_loadExtension(self):
fe = self.fg.add_item()
fe.id('1')
fe.title(u'…')
fe.content(u'…')
fe.load_extension('base')
assert fe.base
assert self.fg.atom_str()
self.assertTrue(fe.base)
self.assertTrue(self.fg.atom_str())

def test_checkEntryNumbers(self):
fg = self.fg
assert len(fg.entry()) == 3
self.assertEqual(len(fg.entry()), 3)

def test_TestEntryItems(self):
fe = self.fg.add_item()
fe.title('qwe')
assert fe.title() == 'qwe'
self.assertEqual(fe.title(), 'qwe')
author = fe.author(email='[email protected]')[0]
assert not author.get('name')
assert author.get('email') == '[email protected]'
self.assertFalse(author.get('name'))
self.assertEqual(author.get('email'), '[email protected]')
author = fe.author(name='John Doe', email='[email protected]',
replace=True)[0]
assert author.get('name') == 'John Doe'
assert author.get('email') == '[email protected]'
self.assertEqual(author.get('name'), 'John Doe')
self.assertEqual(author.get('email'), '[email protected]')
contributor = fe.contributor(name='John Doe', email='[email protected]')[0]
assert contributor == fe.contributor()[0]
assert contributor.get('name') == 'John Doe'
assert contributor.get('email') == '[email protected]'
self.assertEqual(contributor, fe.contributor()[0])
self.assertEqual(contributor.get('name'), 'John Doe')
self.assertEqual(contributor.get('email'), '[email protected]')
link = fe.link(href='http://lkiesow.de', rel='alternate')[0]
assert link == fe.link()[0]
assert link.get('href') == 'http://lkiesow.de'
assert link.get('rel') == 'alternate'
self.assertEqual(link, fe.link()[0])
self.assertEqual(link.get('href'), 'http://lkiesow.de')
self.assertEqual(link.get('rel'), 'alternate')
fe.guid('123')
assert fe.guid().get('guid') == '123'
self.assertEqual(fe.guid().get('guid'), '123')
fe.updated('2017-02-05 13:26:58+01:00')
assert fe.updated().year == 2017
self.assertEqual(fe.updated().year, 2017)
fe.summary('asdf')
assert fe.summary() == {'summary': 'asdf'}
self.assertEqual(fe.summary(), {'summary': 'asdf'})
fe.description('asdfx')
assert fe.description() == 'asdfx'
self.assertEqual(fe.description(), 'asdfx')
fe.pubDate('2017-02-05 13:26:58+01:00')
assert fe.pubDate().year == 2017
self.assertEqual(fe.pubDate().year, 2017)
fe.rights('asdfx')
assert fe.rights() == 'asdfx'
self.assertEqual(fe.rights(), 'asdfx')
source = fe.source(url='https://example.com', title='Test')
assert source.get('title') == 'Test'
assert source.get('url') == 'https://example.com'
self.assertEqual(source.get('title'), 'Test')
self.assertEqual(source.get('url'), 'https://example.com')
fe.comments('asdfx')
assert fe.comments() == 'asdfx'
self.assertEqual(fe.comments(), 'asdfx')
fe.enclosure(url='http://lkiesow.de', type='text/plain', length='1')
assert fe.enclosure().get('url') == 'http://lkiesow.de'
self.assertEqual(fe.enclosure().get('url'), 'http://lkiesow.de')
fe.ttl(8)
assert fe.ttl() == 8
self.assertEqual(fe.ttl(), 8)

self.fg.rss_str()
self.fg.atom_str()

def test_checkItemNumbers(self):
fg = self.fg
assert len(fg.item()) == 3
self.assertEqual(len(fg.item()), 3)

def test_checkEntryContent(self):
fg = self.fg
assert fg.entry()
self.assertTrue(fg.entry())

def test_removeEntryByIndex(self):
fg = FeedGenerator()
Expand All @@ -120,9 +120,9 @@ def test_removeEntryByIndex(self):
fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The Third Episode')
assert len(fg.entry()) == 1
self.assertEqual(len(fg.entry()), 1)
fg.remove_entry(0)
assert len(fg.entry()) == 0
self.assertEqual(len(fg.entry()), 0)

def test_removeEntryByEntry(self):
fg = FeedGenerator()
Expand All @@ -133,9 +133,9 @@ def test_removeEntryByEntry(self):
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The Third Episode')

assert len(fg.entry()) == 1
self.assertEqual(len(fg.entry()), 1)
fg.remove_entry(fe)
assert len(fg.entry()) == 0
self.assertEqual(len(fg.entry()), 0)

def test_categoryHasDomain(self):
fg = FeedGenerator()
Expand All @@ -147,12 +147,12 @@ def test_categoryHasDomain(self):
fe.title('some title')
fe.category([
{'term': 'category',
'scheme': 'http://www.somedomain.com/category',
'scheme': 'http://somedomain.com/category',
'label': 'Category',
}])

result = fg.rss_str()
assert b'domain="http://www.somedomain.com/category"' in result
self.assertIn(b'domain="http://somedomain.com/category"', result)

def test_content_cdata_type(self):
fg = FeedGenerator()
Expand All @@ -163,7 +163,8 @@ def test_content_cdata_type(self):
fe.title('some title')
fe.content('content', type='CDATA')
result = fg.atom_str()
assert b'<content type="CDATA"><![CDATA[content]]></content>' in result
expected = b'<content type="CDATA"><![CDATA[content]]></content>'
self.assertIn(expected, result)

def test_summary_html_type(self):
fg = FeedGenerator()
Expand All @@ -176,4 +177,4 @@ def test_summary_html_type(self):
fe.summary('<p>summary</p>', type='html')
result = fg.atom_str()
expected = b'<summary type="html">&lt;p&gt;summary&lt;/p&gt;</summary>'
assert expected in result
self.assertIn(expected, result)
6 changes: 3 additions & 3 deletions tests/test_extensions/test_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_elements(self):
if method.startswith('dc_'):
m = getattr(self.fg.dc, method)
m(method)
assert m() == [method]
self.assertEqual(m(), [method])

self.fg.id('123')
assert self.fg.atom_str()
assert self.fg.rss_str()
self.assertTrue(self.fg.atom_str())
self.assertTrue(self.fg.rss_str())
5 changes: 3 additions & 2 deletions tests/test_extensions/test_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ def test_geom_from_geointerface_warn_poly_interior(self):
# Trigger a warning.
fe.geo.geom_from_geo_interface(self.polygon_with_interior)
# Verify some things
assert len(w) == 1
assert issubclass(w[-1].category, GeoRSSPolygonInteriorWarning)
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category,
GeoRSSPolygonInteriorWarning))

self.assertEqual(fe.geo.polygon(), str(self.polygon_with_interior))

Expand Down
16 changes: 8 additions & 8 deletions tests/test_extensions/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ def test_media_content(self):
root = etree.fromstring(self.fg.rss_str())
url = root.xpath('/rss/channel/item/media:group/media:content[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
self.assertEqual(url, ['file1.xy', 'file1.xy'])

# There is one without a group
url = root.xpath('/rss/channel/item/media:content[1]/@url',
namespaces=ns)
assert url == ['file.xy']
self.assertEqual(url, ['file.xy'])

# Check that we have the item in the resulting Atom feed
root = etree.fromstring(self.fg.atom_str())
url = root.xpath('/a:feed/a:entry/media:group/media:content[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
self.assertEqual(url, ['file1.xy', 'file1.xy'])

fe.media.content(content=[], replace=True)
assert fe.media.content() == []
self.assertEqual(fe.media.content(), [])

def test_media_thumbnail(self):
fe = self.fg.add_item()
Expand All @@ -66,18 +66,18 @@ def test_media_thumbnail(self):
url = root.xpath(
'/rss/channel/item/media:group/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
self.assertEqual(url, ['file1.xy', 'file1.xy'])

# There is one without a group
url = root.xpath('/rss/channel/item/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file.xy']
self.assertEqual(url, ['file.xy'])

# Check that we have the item in the resulting Atom feed
root = etree.fromstring(self.fg.atom_str())
url = root.xpath('/a:feed/a:entry/media:group/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
self.assertEqual(url, ['file1.xy', 'file1.xy'])

fe.media.thumbnail(thumbnail=[], replace=True)
assert fe.media.thumbnail() == []
self.assertEqual(fe.media.thumbnail(), [])
44 changes: 22 additions & 22 deletions tests/test_extensions/test_podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_category_new(self):
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
namespaces=ns)
assert cat[0] == 'Technology'
assert scat[0] == 'Podcasting'
self.assertEqual(cat[0], 'Technology')
self.assertEqual(scat[0], 'Podcasting')

def test_category(self):
self.fg.podcast.itunes_category('Technology', 'Podcasting')
Expand All @@ -40,8 +40,8 @@ def test_category(self):
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
namespaces=ns)
assert cat[0] == 'Technology'
assert scat[0] == 'Podcasting'
self.assertEqual(cat[0], 'Technology')
self.assertEqual(scat[0], 'Podcasting')

def test_podcastItems(self):
fg = self.fg
Expand All @@ -52,19 +52,19 @@ def test_podcastItems(self):
fg.podcast.itunes_image('x.png')
fg.podcast.itunes_subtitle('x')
fg.podcast.itunes_summary('x')
assert fg.podcast.itunes_author() == 'Lars Kiesow'
assert fg.podcast.itunes_block() == 'x'
assert fg.podcast.itunes_complete() == 'no'
assert fg.podcast.itunes_explicit() == 'no'
assert fg.podcast.itunes_image() == 'x.png'
assert fg.podcast.itunes_subtitle() == 'x'
assert fg.podcast.itunes_summary() == 'x'
self.assertEqual(fg.podcast.itunes_author(), 'Lars Kiesow')
self.assertEqual(fg.podcast.itunes_block(), 'x')
self.assertEqual(fg.podcast.itunes_complete(), 'no')
self.assertEqual(fg.podcast.itunes_explicit(), 'no')
self.assertEqual(fg.podcast.itunes_image(), 'x.png')
self.assertEqual(fg.podcast.itunes_subtitle(), 'x')
self.assertEqual(fg.podcast.itunes_summary(), 'x')

# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
author = root.xpath('/rss/channel/itunes:author/text()', namespaces=ns)
assert author == ['Lars Kiesow']
self.assertEqual(author, ['Lars Kiesow'])

def test_podcastEntryItems(self):
fe = self.fg.add_item()
Expand All @@ -78,19 +78,19 @@ def test_podcastEntryItems(self):
fe.podcast.itunes_order(1)
fe.podcast.itunes_subtitle('x')
fe.podcast.itunes_summary('x')
assert fe.podcast.itunes_author() == 'Lars Kiesow'
assert fe.podcast.itunes_block() == 'x'
assert fe.podcast.itunes_duration() == '00:01:30'
assert fe.podcast.itunes_explicit() == 'no'
assert fe.podcast.itunes_image() == 'x.png'
assert fe.podcast.itunes_is_closed_captioned()
assert fe.podcast.itunes_order() == 1
assert fe.podcast.itunes_subtitle() == 'x'
assert fe.podcast.itunes_summary() == 'x'
self.assertEqual(fe.podcast.itunes_author(), 'Lars Kiesow')
self.assertEqual(fe.podcast.itunes_block(), 'x')
self.assertEqual(fe.podcast.itunes_duration(), '00:01:30')
self.assertEqual(fe.podcast.itunes_explicit(), 'no')
self.assertEqual(fe.podcast.itunes_image(), 'x.png')
self.assertTrue(fe.podcast.itunes_is_closed_captioned())
self.assertEqual(fe.podcast.itunes_order(), 1)
self.assertEqual(fe.podcast.itunes_subtitle(), 'x')
self.assertEqual(fe.podcast.itunes_summary(), 'x')

# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
author = root.xpath('/rss/channel/item/itunes:author/text()',
namespaces=ns)
assert author == ['Lars Kiesow']
self.assertEqual(author, ['Lars Kiesow'])
6 changes: 3 additions & 3 deletions tests/test_extensions/test_syndication.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ def test_update_period(self):
root = etree.fromstring(self.fg.rss_str())
a = root.xpath('/rss/channel/sy:UpdatePeriod',
namespaces=self.SYN_NS)
assert a[0].text == period_type
self.assertEqual(a[0].text, period_type)

def test_update_frequency(self):
for frequency in (1, 100, 2000, 100000):
self.fg.syndication.update_frequency(frequency)
root = etree.fromstring(self.fg.rss_str())
a = root.xpath('/rss/channel/sy:UpdateFrequency',
namespaces=self.SYN_NS)
assert a[0].text == str(frequency)
self.assertEqual(a[0].text, str(frequency))

def test_update_base(self):
base = '2000-01-01T12:00+00:00'
self.fg.syndication.update_base(base)
root = etree.fromstring(self.fg.rss_str())
a = root.xpath('/rss/channel/sy:UpdateBase', namespaces=self.SYN_NS)
assert a[0].text == base
self.assertEqual(a[0].text, base)
14 changes: 7 additions & 7 deletions tests/test_extensions/test_torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def test_podcastEntryItems(self):
fe.torrent.seeds('1')
fe.torrent.peers('2')
fe.torrent.verified('1')
assert fe.torrent.filename() == 'file.xy'
assert fe.torrent.infohash() == '123'
assert fe.torrent.contentlength() == '23'
assert fe.torrent.seeds() == '1'
assert fe.torrent.peers() == '2'
assert fe.torrent.verified() == '1'
self.assertEqual(fe.torrent.filename(), 'file.xy')
self.assertEqual(fe.torrent.infohash(), '123')
self.assertEqual(fe.torrent.contentlength(), '23')
self.assertEqual(fe.torrent.seeds(), '1')
self.assertEqual(fe.torrent.peers(), '2')
self.assertEqual(fe.torrent.verified(), '1')

# Check that we have the item in the resulting XML
ns = {'torrent': 'http://xmlns.ezrss.it/0.1/dtd/'}
root = etree.fromstring(self.fg.rss_str())
filename = root.xpath('/rss/channel/item/torrent:filename/text()',
namespaces=ns)
assert filename == ['file.xy']
self.assertEqual(filename, ['file.xy'])
Loading

0 comments on commit 3371c28

Please sign in to comment.