2013-03-04 18:10:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-05-05 21:33:48 +00:00
|
|
|
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
|
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
|
|
|
# Copyright (C) 2015-2016 Tobias Gruetzmacher
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
import pytest
|
2013-03-04 18:10:27 +00:00
|
|
|
import sys
|
2016-05-05 21:33:48 +00:00
|
|
|
|
2016-03-28 14:29:57 +00:00
|
|
|
from . import dosage_cmd, run_checked
|
2013-03-04 18:10:27 +00:00
|
|
|
|
|
|
|
|
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."""
|
2016-03-07 00:08:57 +00:00
|
|
|
run_checked([sys.executable, cmd, '--allow-multiple'] + options)
|
2013-03-04 18:10:27 +00:00
|
|
|
|
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
class TestDosage(object):
|
2013-03-04 18:10:27 +00:00
|
|
|
"""Test the dosage commandline client."""
|
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
def test_list_comics(self):
|
2013-03-04 18:10:27 +00:00
|
|
|
for option in ("-l", "--list", "--singlelist"):
|
|
|
|
run_with_options([option])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_display_version(self):
|
2013-03-04 18:10:27 +00:00
|
|
|
run_with_options(["--version"])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_display_help(self):
|
2013-03-04 18:10:27 +00:00
|
|
|
for option in ("-h", "--help"):
|
|
|
|
run_with_options([option])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_module_help(self):
|
2015-04-18 10:34:33 +00:00
|
|
|
run_with_options(["-m", "xkcd"])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_no_comics_specified(self):
|
|
|
|
with pytest.raises(OSError):
|
|
|
|
run_with_options([])
|
|
|
|
|
|
|
|
def test_unknown_option(self):
|
|
|
|
with pytest.raises(OSError):
|
|
|
|
run_with_options(['--imadoofus'])
|
|
|
|
|
|
|
|
def test_multiple_comics_match(self):
|
|
|
|
with pytest.raises(OSError):
|
|
|
|
run_with_options(['Garfield'])
|
|
|
|
|
2016-05-05 21:33:48 +00:00
|
|
|
def test_fetch_html_and_rss_json(self, tmpdir):
|
2016-03-28 14:29:57 +00:00
|
|
|
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "-o", "html",
|
2016-05-05 21:33:48 +00:00
|
|
|
"-o", "rss", "-o", "json", "xkcd"])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
2016-03-28 14:29:57 +00:00
|
|
|
def test_fetch_html_and_rss_2(self, tmpdir):
|
2016-03-07 00:08:57 +00:00
|
|
|
run_with_options(["--numstrips", "2", "--baseurl", "bla",
|
2016-03-28 14:29:57 +00:00
|
|
|
"--basepath", str(tmpdir), "--output", "rss",
|
2016-05-21 14:16:02 +00:00
|
|
|
"--output", "html", "--adult", "TheThinHLine"])
|
2016-03-07 00:08:57 +00:00
|
|
|
|
2016-03-28 14:29:57 +00:00
|
|
|
def test_fetch_indexed(self, tmpdir):
|
|
|
|
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "xkcd:303"])
|