Extended test Coverage
This patch extends the test coverage of the unit tests. It also enables python-coverage and coveralls to track unit test coverage. There are some additional minor issue fixed discovered during the test creation. Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
parent
68248e46a0
commit
4314475bfb
8 changed files with 111 additions and 17 deletions
|
@ -7,7 +7,7 @@ python:
|
||||||
- "3.5"
|
- "3.5"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- pip install flake8
|
- pip install flake8 python-coveralls coverage
|
||||||
- python setup.py bdist_wheel
|
- python setup.py bdist_wheel
|
||||||
- pip install dist/feedgen*
|
- pip install dist/feedgen*
|
||||||
|
|
||||||
|
@ -16,3 +16,6 @@ script:
|
||||||
- python -m feedgen
|
- python -m feedgen
|
||||||
- python -m feedgen atom
|
- python -m feedgen atom
|
||||||
- python -m feedgen rss
|
- python -m feedgen rss
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- coveralls
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -49,8 +49,5 @@ publish:
|
||||||
twine upload dist/*
|
twine upload dist/*
|
||||||
|
|
||||||
test:
|
test:
|
||||||
python -m unittest tests.test_feed
|
coverage run --omit='*/lib/*,tests/*' -m unittest discover -s tests
|
||||||
python -m unittest tests.test_entry
|
|
||||||
python -m unittest tests.test_extension
|
|
||||||
@rm -f tmp_Atomfeed.xml tmp_Rssfeed.xml
|
|
||||||
flake8 $$(find setup.py tests feedgen -name '*.py')
|
flake8 $$(find setup.py tests feedgen -name '*.py')
|
||||||
|
|
|
@ -464,7 +464,7 @@ class FeedEntry(object):
|
||||||
if isSummary:
|
if isSummary:
|
||||||
self.__atom_summary = description
|
self.__atom_summary = description
|
||||||
else:
|
else:
|
||||||
self.__atom_content = description
|
self.__atom_content = {'content': description}
|
||||||
return self.__rss_description
|
return self.__rss_description
|
||||||
|
|
||||||
def category(self, category=None, replace=False, **kwargs):
|
def category(self, category=None, replace=False, **kwargs):
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
Descriptions partly taken from
|
Descriptions partly taken from
|
||||||
http://dublincore.org/documents/dcmi-terms/#elements-coverage
|
http://dublincore.org/documents/dcmi-terms/#elements-coverage
|
||||||
|
|
||||||
:copyright: 2013-2016, Lars Kiesow <lkiesow@uos.de>
|
:copyright: 2013-2017, Lars Kiesow <lkiesow@uos.de>
|
||||||
|
|
||||||
:license: FreeBSD and LGPL, see license.* for more details.
|
:license: FreeBSD and LGPL, see license.* for more details.
|
||||||
'''
|
'''
|
||||||
|
@ -223,6 +223,7 @@ class DcBaseExtension(BaseExtension):
|
||||||
if replace or not self._dcelem_identifier:
|
if replace or not self._dcelem_identifier:
|
||||||
self._dcelem_identifier = []
|
self._dcelem_identifier = []
|
||||||
self._dcelem_identifier += identifier
|
self._dcelem_identifier += identifier
|
||||||
|
return self._dcelem_identifier
|
||||||
|
|
||||||
def dc_language(self, language=None, replace=True):
|
def dc_language(self, language=None, replace=True):
|
||||||
'''Get or set the dc:language which describes a language of the
|
'''Get or set the dc:language which describes a language of the
|
||||||
|
|
|
@ -130,7 +130,7 @@ class PodcastEntryExtension(BaseEntryExtension):
|
||||||
if itunes_image.endswith('.jpg') or itunes_image.endswith('.png'):
|
if itunes_image.endswith('.jpg') or itunes_image.endswith('.png'):
|
||||||
self.__itunes_image = itunes_image
|
self.__itunes_image = itunes_image
|
||||||
else:
|
else:
|
||||||
ValueError('Image file must be png or jpg')
|
raise ValueError('Image file must be png or jpg')
|
||||||
return self.__itunes_image
|
return self.__itunes_image
|
||||||
|
|
||||||
def itunes_duration(self, itunes_duration=None):
|
def itunes_duration(self, itunes_duration=None):
|
||||||
|
@ -151,9 +151,9 @@ class PodcastEntryExtension(BaseEntryExtension):
|
||||||
itunes_duration = str(itunes_duration)
|
itunes_duration = str(itunes_duration)
|
||||||
if len(itunes_duration.split(':')) > 3 or \
|
if len(itunes_duration.split(':')) > 3 or \
|
||||||
itunes_duration.lstrip('0123456789:') != '':
|
itunes_duration.lstrip('0123456789:') != '':
|
||||||
ValueError('Invalid duration format')
|
raise ValueError('Invalid duration format')
|
||||||
self.__itunes_duration = itunes_duration
|
self.__itunes_duration = itunes_duration
|
||||||
return self.itunes_duration
|
return self.__itunes_duration
|
||||||
|
|
||||||
def itunes_explicit(self, itunes_explicit=None):
|
def itunes_explicit(self, itunes_explicit=None):
|
||||||
'''Get or the the itunes:explicit value of the podcast episode. This
|
'''Get or the the itunes:explicit value of the podcast episode. This
|
||||||
|
|
|
@ -13,41 +13,79 @@ from feedgen.feed import FeedGenerator
|
||||||
class TestSequenceFunctions(unittest.TestCase):
|
class TestSequenceFunctions(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
fg = FeedGenerator()
|
fg = FeedGenerator()
|
||||||
self.feedId = 'http://example.com'
|
self.feedId = 'http://example.com'
|
||||||
self.title = 'Some Testfeed'
|
self.title = 'Some Testfeed'
|
||||||
|
|
||||||
fg.id(self.feedId)
|
fg.id(self.feedId)
|
||||||
fg.title(self.title)
|
fg.title(self.title)
|
||||||
|
fg.link(href='http://lkiesow.de', rel='alternate')[0]
|
||||||
|
fg.description('...')
|
||||||
|
|
||||||
fe = fg.add_entry()
|
fe = fg.add_entry()
|
||||||
fe.id('http://lernfunk.de/media/654321/1')
|
fe.id('http://lernfunk.de/media/654321/1')
|
||||||
fe.title('The First Episode')
|
fe.title('The First Episode')
|
||||||
|
fe.content(u'…')
|
||||||
|
|
||||||
# Use also the different name add_item
|
# Use also the different name add_item
|
||||||
fe = fg.add_item()
|
fe = fg.add_item()
|
||||||
fe.id('http://lernfunk.de/media/654321/1')
|
fe.id('http://lernfunk.de/media/654321/1')
|
||||||
fe.title('The Second Episode')
|
fe.title('The Second Episode')
|
||||||
|
fe.content(u'…')
|
||||||
|
|
||||||
fe = fg.add_entry()
|
fe = fg.add_entry()
|
||||||
fe.id('http://lernfunk.de/media/654321/1')
|
fe.id('http://lernfunk.de/media/654321/1')
|
||||||
fe.title('The Third Episode')
|
fe.title('The Third Episode')
|
||||||
|
fe.content(u'…')
|
||||||
|
|
||||||
self.fg = fg
|
self.fg = fg
|
||||||
|
|
||||||
def test_checkEntryNumbers(self):
|
def test_checkEntryNumbers(self):
|
||||||
|
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
assert len(fg.entry()) == 3
|
assert len(fg.entry()) == 3
|
||||||
|
|
||||||
def test_checkItemNumbers(self):
|
def test_TestEntryItems(self):
|
||||||
|
fe = self.fg.add_item()
|
||||||
|
fe.title('qwe')
|
||||||
|
assert fe.title() == 'qwe'
|
||||||
|
author = fe.author(name='John Doe', email='jdoe@example.com')[0]
|
||||||
|
assert author.get('name') == 'John Doe'
|
||||||
|
assert author.get('email') == 'jdoe@example.com'
|
||||||
|
contributor = fe.contributor(name='John Doe', email='jdoe@ex.com')[0]
|
||||||
|
assert contributor == fe.contributor()[0]
|
||||||
|
assert contributor.get('name') == 'John Doe'
|
||||||
|
assert contributor.get('email') == 'jdoe@ex.com'
|
||||||
|
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'
|
||||||
|
fe.guid('123')
|
||||||
|
assert fe.guid() == '123'
|
||||||
|
fe.updated('2017-02-05 13:26:58+01:00')
|
||||||
|
assert fe.updated().year == 2017
|
||||||
|
fe.summary('asdf')
|
||||||
|
assert fe.summary() == 'asdf'
|
||||||
|
fe.description('asdfx')
|
||||||
|
assert fe.description() == 'asdfx'
|
||||||
|
fe.pubdate('2017-02-05 13:26:58+01:00')
|
||||||
|
assert fe.pubdate().year == 2017
|
||||||
|
fe.rights('asdfx')
|
||||||
|
assert fe.rights() == 'asdfx'
|
||||||
|
fe.comments('asdfx')
|
||||||
|
assert fe.comments() == 'asdfx'
|
||||||
|
fe.enclosure(url='http://lkiesow.de', type='text/plain', length='1')
|
||||||
|
assert fe.enclosure().get('url') == 'http://lkiesow.de'
|
||||||
|
fe.ttl(8)
|
||||||
|
assert fe.ttl() == 8
|
||||||
|
|
||||||
|
self.fg.rss_str()
|
||||||
|
self.fg.atom_str()
|
||||||
|
|
||||||
|
def test_checkItemNumbers(self):
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
assert len(fg.item()) == 3
|
assert len(fg.item()) == 3
|
||||||
|
|
||||||
def test_checkEntryContent(self):
|
def test_checkEntryContent(self):
|
||||||
|
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
assert fg.entry()
|
assert fg.entry()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: set et ts=4 sw=4 sts=4 sta tw=80 cc=81:
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tests for extensions
|
Tests for extensions
|
||||||
|
@ -82,3 +81,56 @@ class TestExtensionPodcast(unittest.TestCase):
|
||||||
namespaces=ns)
|
namespaces=ns)
|
||||||
assert cat[0] == 'Technology'
|
assert cat[0] == 'Technology'
|
||||||
assert scat[0] == 'Podcasting'
|
assert scat[0] == 'Podcasting'
|
||||||
|
|
||||||
|
def test_podcastEntryItems(self):
|
||||||
|
fe = self.fg.add_item()
|
||||||
|
fe.title('y')
|
||||||
|
fe.podcast.itunes_author('Lars Kiesow')
|
||||||
|
fe.podcast.itunes_block('x')
|
||||||
|
fe.podcast.itunes_duration('00:01:30')
|
||||||
|
fe.podcast.itunes_explicit('no')
|
||||||
|
fe.podcast.itunes_image('x.png')
|
||||||
|
fe.podcast.itunes_is_closed_captioned('yes')
|
||||||
|
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'
|
||||||
|
|
||||||
|
# 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']
|
||||||
|
|
||||||
|
|
||||||
|
class TestExtensionDc(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.fg = FeedGenerator()
|
||||||
|
self.fg.load_extension('dc')
|
||||||
|
self.fg.title('title')
|
||||||
|
self.fg.link(href='http://example.com', rel='self')
|
||||||
|
self.fg.description('description')
|
||||||
|
|
||||||
|
def test_entryLoadExtension(self):
|
||||||
|
fe = self.fg.add_item()
|
||||||
|
try:
|
||||||
|
fe.load_extension('dc')
|
||||||
|
except ImportError:
|
||||||
|
pass # Extension already loaded
|
||||||
|
|
||||||
|
def test_elements(self):
|
||||||
|
for method in dir(self.fg.dc):
|
||||||
|
if method.startswith('dc_'):
|
||||||
|
m = getattr(self.fg.dc, method)
|
||||||
|
m(method)
|
||||||
|
assert m() == [method]
|
||||||
|
|
|
@ -7,6 +7,8 @@ These are test cases for a basic feed.
|
||||||
A basic feed does not contain entries so far.
|
A basic feed does not contain entries so far.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from feedgen.feed import FeedGenerator
|
from feedgen.feed import FeedGenerator
|
||||||
|
@ -123,13 +125,14 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||||
|
|
||||||
def test_atomFeedFile(self):
|
def test_atomFeedFile(self):
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
filename = 'tmp_Atomfeed.xml'
|
_, filename = tempfile.mkstemp()
|
||||||
fg.atom_file(filename=filename, pretty=True, xml_declaration=False)
|
fg.atom_file(filename=filename, pretty=True, xml_declaration=False)
|
||||||
|
|
||||||
with open(filename, "r") as myfile:
|
with open(filename, "r") as myfile:
|
||||||
atomString = myfile.read().replace('\n', '')
|
atomString = myfile.read().replace('\n', '')
|
||||||
|
|
||||||
self.checkAtomString(atomString)
|
self.checkAtomString(atomString)
|
||||||
|
os.remove(filename)
|
||||||
|
|
||||||
def test_atomFeedString(self):
|
def test_atomFeedString(self):
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
|
@ -243,7 +246,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||||
|
|
||||||
def test_rssFeedFile(self):
|
def test_rssFeedFile(self):
|
||||||
fg = self.fg
|
fg = self.fg
|
||||||
filename = 'tmp_Rssfeed.xml'
|
_, filename = tempfile.mkstemp()
|
||||||
fg.rss_file(filename=filename, pretty=True, xml_declaration=False)
|
fg.rss_file(filename=filename, pretty=True, xml_declaration=False)
|
||||||
|
|
||||||
with open(filename, "r") as myfile:
|
with open(filename, "r") as myfile:
|
||||||
|
|
Loading…
Reference in a new issue