dosage/tests/test_dosage.py

67 lines
2.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Copyright (C) 2013 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."""
def setUp(self):
# create a temporary directory for images
self.tmpdir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.tmpdir)
def test_list_comics(self):
for option in ("-l", "--list", "--singlelist"):
run_with_options([option])
def test_version(self):
run_with_options(["--version"])
def test_help(self):
for option in ("-h", "--help"):
run_with_options([option])
# module help
run_with_options(["-m", "calvinandhobbes"])
def test_error(self):
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'])
def test_fetch_html(self):
2013-04-05 17:27:36 +00:00
run_with_options(["-n", "2", "-v", "-b", self.tmpdir, "-o", "html", "-o", "rss", "calvinandhobbes"])
def test_fetch_rss(self):
run_with_options(["--numstrips", "2", "--baseurl", "bla", "--basepath", self.tmpdir, "--output", "rss", "--output", "html", "--adult", "sexyloser"])
def test_fetch_indexed(self):
2013-04-05 17:27:36 +00:00
run_with_options(["-n", "2", "-v", "-b", self.tmpdir, "calvinandhobbes:2012/02/02"])