dosage/tests/test_dosage.py

69 lines
2.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2014-01-05 15:50:57 +00:00
# Copyright (C) 2013-2014 Bastian Kleineidam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
import sys
import shutil
import tempfile
2013-04-02 21:01:07 +00:00
from . import dosage_cmd, run_checked
2013-03-12 20:07:32 +00:00
def run_with_options(options, cmd=dosage_cmd):
2013-04-02 21:01:07 +00:00
"""Run dosage with given options."""
2013-03-12 20:07:32 +00:00
run_checked([sys.executable, cmd] + options)
class TestDosage (unittest.TestCase):
"""Test the dosage commandline client."""
2014-01-05 13:26:46 +00:00
def test_dosage(self):
# list comics
for option in ("-l", "--list", "--singlelist"):
run_with_options([option])
2014-01-05 13:26:46 +00:00
# display version
run_with_options(["--version"])
2014-01-05 13:26:46 +00:00
# display help
for option in ("-h", "--help"):
run_with_options([option])
# module help
2015-04-18 10:34:33 +00:00
run_with_options(["-m", "xkcd"])
2013-04-12 19:22:58 +00:00
# no comics specified
self.assertRaises(OSError, run_with_options, [])
2013-04-12 19:22:58 +00:00
# unknown option
self.assertRaises(OSError, run_with_options, ['--imadoofus'])
2013-04-12 19:22:58 +00:00
# multiple comics match
2013-03-11 19:05:06 +00:00
self.assertRaises(OSError, run_with_options, ['Garfield'])
2014-01-05 13:26:46 +00:00
# create a temporary directory for images
tmpdir = tempfile.mkdtemp()
try:
# fetch html and rss
2015-04-18 10:34:33 +00:00
run_with_options(["-n", "2", "-v", "-b", tmpdir, "-o", "html", "-o", "rss", "xkcd"])
2014-01-05 13:26:46 +00:00
finally:
shutil.rmtree(tmpdir)
# create a temporary directory for images
tmpdir = tempfile.mkdtemp()
try:
# fetch html and rss 2
run_with_options(["--numstrips", "2", "--baseurl", "bla", "--basepath", tmpdir, "--output", "rss", "--output", "html", "--adult", "sexyloser"])
finally:
shutil.rmtree(tmpdir)
# create a temporary directory for images
tmpdir = tempfile.mkdtemp()
try:
# fetch indexed
2015-04-18 10:34:33 +00:00
run_with_options(["-n", "2", "-v", "-b", tmpdir, "xkcd:303"])
2014-01-05 13:26:46 +00:00
finally:
shutil.rmtree(tmpdir)