Add tests for feedgen:main

This patch adds some tests for the main routine of feedgen.

Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
Lars Kiesow 2017-03-13 20:57:52 +01:00
parent fee00f3337
commit c633fd4d64
No known key found for this signature in database
GPG key ID: 5DAFE8D9C823CE73
2 changed files with 45 additions and 1 deletions

View file

@ -44,7 +44,7 @@ def print_enc(s):
print(s)
if __name__ == '__main__':
def main():
if len(sys.argv) != 2 or not (
sys.argv[1].endswith('rss') or
sys.argv[1].endswith('atom') or
@ -138,3 +138,7 @@ if __name__ == '__main__':
elif arg.endswith('rss'):
fg.rss_file(arg)
if __name__ == '__main__':
main()

40
tests/test_main.py Normal file
View file

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
'''
Tests for feedgen main
'''
import os
import sys
import tempfile
import unittest
from feedgen import __main__
class TestSequenceFunctions(unittest.TestCase):
def test_usage(self):
sys.argv = ['feedgen']
try:
__main__.main()
except BaseException as e:
assert e.code is None
def test_feed(self):
for ftype in 'rss', 'atom', 'podcast', 'torrent', 'dc.rss', 'dc.atom',\
'syndication.rss', 'syndication.atom':
sys.argv = ['feedgen', ftype]
try:
__main__.main()
except:
assert False
def test_file(self):
for extemsion in '.atom', '.rss':
_, filename = tempfile.mkstemp(extemsion)
sys.argv = ['feedgen', filename]
try:
__main__.main()
except:
assert False
os.remove(filename)