Fixing some small test issues

This fixes some small issues with the unit tests and adding a test case
to the Makefile so that all tests can easily be invoked by running:

  make test

Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
Lars Kiesow 2014-07-20 22:55:25 +02:00
parent 858abbf79b
commit ff1f40a6cd
No known key found for this signature in database
GPG key ID: 5DAFE8D9C823CE73
3 changed files with 31 additions and 27 deletions

View file

@ -42,3 +42,8 @@ doc-latexpdf:
publish: sdist publish: sdist
python setup.py register sdist upload python setup.py register sdist upload
test:
python -m unittest feedgen.tests.test_feed
python -m unittest feedgen.tests.test_entry
python -m unittest feedgen.tests.test_extension

View file

@ -3,7 +3,7 @@
""" """
Tests for a basic entry Tests for a basic entry
These test cases contain test cases for a basic entry. These are test cases for a basic entry.
""" """
import unittest import unittest
@ -13,7 +13,7 @@ from ..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'
@ -71,12 +71,7 @@ class TestSequenceFunctions(unittest.TestCase):
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')
assert len(fg.entry()) == 1 assert len(fg.entry()) == 1
fg.remove_entry(fe) fg.remove_entry(fe)
assert len(fg.entry()) == 0 assert len(fg.entry()) == 0

View file

@ -3,7 +3,8 @@
""" """
Tests for a basic feed Tests for a basic feed
These test cases contain test cases for a basic feed. A basic feed does not contain entries so far. These are test cases for a basic feed.
A basic feed does not contain entries so far.
""" """
import unittest import unittest
@ -21,7 +22,7 @@ class TestSequenceFunctions(unittest.TestCase):
self.feedId = 'http://lernfunk.de/media/654321' self.feedId = 'http://lernfunk.de/media/654321'
self.title = 'Some Testfeed' self.title = 'Some Testfeed'
self.authorName = 'John Doe' self.authorName = 'John Doe'
self.authorMail = 'john@example.de' self.authorMail = 'john@example.de'
self.author = {'name': self.authorName,'email': self.authorMail} self.author = {'name': self.authorName,'email': self.authorMail}
@ -36,7 +37,7 @@ class TestSequenceFunctions(unittest.TestCase):
self.link2Rel = 'self' self.link2Rel = 'self'
self.language = 'en' self.language = 'en'
self.categoryTerm = 'This category term' self.categoryTerm = 'This category term'
self.categoryScheme = 'This category scheme' self.categoryScheme = 'This category scheme'
self.categoryLabel = 'This category label' self.categoryLabel = 'This category label'
@ -48,7 +49,8 @@ class TestSequenceFunctions(unittest.TestCase):
self.cloudProtocol = 'SOAP 1.1' self.cloudProtocol = 'SOAP 1.1'
self.icon = "http://example.com/icon.png" self.icon = "http://example.com/icon.png"
self.contributor = {'name':"Contributor Name", 'uri':"Contributor Uri", 'email': 'Contributor email'} self.contributor = {'name':"Contributor Name", 'uri':"Contributor Uri",
'email': 'Contributor email'}
self.copyright = "The copyright notice" self.copyright = "The copyright notice"
self.docs = 'http://www.rssboard.org/rss-specification' self.docs = 'http://www.rssboard.org/rss-specification'
self.managingEditor = 'mail@example.com' self.managingEditor = 'mail@example.com'
@ -73,9 +75,12 @@ class TestSequenceFunctions(unittest.TestCase):
fg.subtitle(self.subtitle) fg.subtitle(self.subtitle)
fg.link( href=self.link2Href, rel=self.link2Rel ) fg.link( href=self.link2Href, rel=self.link2Rel )
fg.language(self.language) fg.language(self.language)
fg.cloud(domain=self.cloudDomain, port=self.cloudPort, path=self.cloudPath, registerProcedure=self.cloudRegisterProcedure, protocol=self.cloudProtocol) fg.cloud(domain=self.cloudDomain, port=self.cloudPort,
path=self.cloudPath, registerProcedure=self.cloudRegisterProcedure,
protocol=self.cloudProtocol)
fg.icon(self.icon) fg.icon(self.icon)
fg.category(term=self.categoryTerm, scheme=self.categoryScheme, label=self.categoryLabel) fg.category(term=self.categoryTerm, scheme=self.categoryScheme,
label=self.categoryLabel)
fg.contributor(self.contributor) fg.contributor(self.contributor)
fg.copyright(self.copyright) fg.copyright(self.copyright)
fg.docs(docs=self.docs) fg.docs(docs=self.docs)
@ -83,7 +88,9 @@ class TestSequenceFunctions(unittest.TestCase):
fg.rating(self.rating) fg.rating(self.rating)
fg.skipDays(self.skipDays) fg.skipDays(self.skipDays)
fg.skipHours(self.skipHours) fg.skipHours(self.skipHours)
fg.textInput(title=self.textInputTitle, description=self.textInputDescription, name=self.textInputName, link=self.textInputLink) fg.textInput(title=self.textInputTitle,
description=self.textInputDescription, name=self.textInputName,
link=self.textInputLink)
fg.ttl(self.ttl) fg.ttl(self.ttl)
fg.webMaster(self.webMaster) fg.webMaster(self.webMaster)
@ -114,15 +121,15 @@ class TestSequenceFunctions(unittest.TestCase):
fg = self.fg fg = self.fg
filename = 'tmp_Atomfeed.xml' filename = 'tmp_Atomfeed.xml'
fg.atom_file(filename=filename, pretty=True) fg.atom_file(filename=filename, pretty=True)
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)
def test_atomFeedString(self): def test_atomFeedString(self):
fg = self.fg fg = self.fg
atomString = fg.atom_str(pretty=True) atomString = fg.atom_str(pretty=True)
self.checkAtomString(atomString) self.checkAtomString(atomString)
@ -131,7 +138,6 @@ class TestSequenceFunctions(unittest.TestCase):
feed = etree.fromstring(atomString) feed = etree.fromstring(atomString)
print (atomString)
nsAtom = self.nsAtom nsAtom = self.nsAtom
assert feed.find("{%s}title" % nsAtom).text == self.title assert feed.find("{%s}title" % nsAtom).text == self.title
@ -157,10 +163,10 @@ class TestSequenceFunctions(unittest.TestCase):
fg = self.fg fg = self.fg
filename = 'tmp_Rssfeed.xml' filename = 'tmp_Rssfeed.xml'
fg.rss_file(filename=filename, pretty=True) fg.rss_file(filename=filename, pretty=True)
with open (filename, "r") as myfile: with open (filename, "r") as myfile:
rssString=myfile.read().replace('\n', '') rssString=myfile.read().replace('\n', '')
self.checkRssString(rssString) self.checkRssString(rssString)
def test_rssFeedString(self): def test_rssFeedString(self):
@ -175,15 +181,13 @@ class TestSequenceFunctions(unittest.TestCase):
def test_loadDcExtension(self): def test_loadDcExtension(self):
fg = self.fg fg = self.fg
fg.load_extension('dc', atom=True, rss=True) fg.load_extension('dc', atom=True, rss=True)
def checkRssString(self, rssString): def checkRssString(self, rssString):
feed = etree.fromstring(rssString) feed = etree.fromstring(rssString)
nsAtom = self.nsAtom nsAtom = self.nsAtom
nsRss = self.nsRss nsRss = self.nsRss
print (rssString)
channel = feed.find("channel") channel = feed.find("channel")
assert channel != None assert channel != None
@ -217,4 +221,4 @@ class TestSequenceFunctions(unittest.TestCase):
assert channel.find("webMaster").text == self.webMaster assert channel.find("webMaster").text == self.webMaster
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()