Use py.test's tmpdir fixture.
This commit is contained in:
parent
d6db1d0b81
commit
dda920f353
3 changed files with 12 additions and 23 deletions
|
@ -3,10 +3,7 @@
|
||||||
# Copyright (C) 2016 Tobias Gruetzmacher
|
# Copyright (C) 2016 Tobias Gruetzmacher
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pytest
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
|
|
||||||
basedir = os.path.dirname(__file__)
|
basedir = os.path.dirname(__file__)
|
||||||
dosage_cmd = os.path.join(os.path.dirname(basedir), "dosage")
|
dosage_cmd = os.path.join(os.path.dirname(basedir), "dosage")
|
||||||
|
@ -28,10 +25,3 @@ def run_checked(cmd, ret_ok=(0,), **kwargs):
|
||||||
msg = "Command `%s' returned non-zero exit status %d" % (cmd, retcode)
|
msg = "Command `%s' returned non-zero exit status %d" % (cmd, retcode)
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
return retcode
|
return retcode
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
|
||||||
def tmpdir():
|
|
||||||
tmpdir = tempfile.mkdtemp()
|
|
||||||
yield tmpdir
|
|
||||||
shutil.rmtree(tmpdir)
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlsplit
|
from urlparse import urlsplit
|
||||||
from dosagelib import scraper
|
from dosagelib import scraper
|
||||||
from . import tmpdir # noqa
|
|
||||||
|
|
||||||
|
|
||||||
def get_host(url):
|
def get_host(url):
|
||||||
|
@ -42,7 +41,7 @@ def _get_saved_images(outdir, scraper):
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
def test_comicmodule(tmpdir, scraperclass): # noqa
|
def test_comicmodule(tmpdir, scraperclass):
|
||||||
'''Test a scraper. It must be able to traverse backward for at least 5
|
'''Test a scraper. It must be able to traverse backward for at least 5
|
||||||
strips from the start, and find strip images on at least 4 pages.'''
|
strips from the start, and find strip images on at least 4 pages.'''
|
||||||
scraperobj = scraperclass()
|
scraperobj = scraperclass()
|
||||||
|
@ -50,10 +49,10 @@ def test_comicmodule(tmpdir, scraperclass): # noqa
|
||||||
host = get_host(scraperobj.url)
|
host = get_host(scraperobj.url)
|
||||||
try:
|
try:
|
||||||
with get_lock(host):
|
with get_lock(host):
|
||||||
_test_comic(tmpdir, scraperobj)
|
_test_comic(str(tmpdir), scraperobj)
|
||||||
except OSError:
|
except OSError:
|
||||||
# interprocess lock not supported
|
# interprocess lock not supported
|
||||||
_test_comic(tmpdir, scraperobj)
|
_test_comic(str(tmpdir), scraperobj)
|
||||||
|
|
||||||
|
|
||||||
def _test_comic(outdir, scraperobj):
|
def _test_comic(outdir, scraperobj):
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
from . import dosage_cmd, run_checked, tmpdir # noqa
|
from . import dosage_cmd, run_checked
|
||||||
|
|
||||||
|
|
||||||
def run_with_options(options, cmd=dosage_cmd):
|
def run_with_options(options, cmd=dosage_cmd):
|
||||||
|
@ -41,14 +41,14 @@ class TestDosage(object):
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError):
|
||||||
run_with_options(['Garfield'])
|
run_with_options(['Garfield'])
|
||||||
|
|
||||||
def test_fetch_html_and_rss(self, tmpdir): # noqa
|
def test_fetch_html_and_rss(self, tmpdir):
|
||||||
run_with_options(["-n", "2", "-v", "-b", tmpdir, "-o", "html", "-o",
|
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "-o", "html",
|
||||||
"rss", "xkcd"])
|
"-o", "rss", "xkcd"])
|
||||||
|
|
||||||
def test_fetch_html_and_rss_2(self, tmpdir): # noqa
|
def test_fetch_html_and_rss_2(self, tmpdir):
|
||||||
run_with_options(["--numstrips", "2", "--baseurl", "bla",
|
run_with_options(["--numstrips", "2", "--baseurl", "bla",
|
||||||
"--basepath", tmpdir, "--output", "rss", "--output",
|
"--basepath", str(tmpdir), "--output", "rss",
|
||||||
"html", "--adult", "oglaf"])
|
"--output", "html", "--adult", "oglaf"])
|
||||||
|
|
||||||
def test_fetch_indexed(self, tmpdir): # noqa
|
def test_fetch_indexed(self, tmpdir):
|
||||||
run_with_options(["-n", "2", "-v", "-b", tmpdir, "xkcd:303"])
|
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "xkcd:303"])
|
||||||
|
|
Loading…
Reference in a new issue