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
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
basedir = os.path.dirname(__file__)
|
||||
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)
|
||||
raise OSError(msg)
|
||||
return retcode
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def tmpdir():
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
yield tmpdir
|
||||
shutil.rmtree(tmpdir)
|
||||
|
|
|
@ -11,7 +11,6 @@ try:
|
|||
except ImportError:
|
||||
from urlparse import urlsplit
|
||||
from dosagelib import scraper
|
||||
from . import tmpdir # noqa
|
||||
|
||||
|
||||
def get_host(url):
|
||||
|
@ -42,7 +41,7 @@ def _get_saved_images(outdir, scraper):
|
|||
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
|
||||
strips from the start, and find strip images on at least 4 pages.'''
|
||||
scraperobj = scraperclass()
|
||||
|
@ -50,10 +49,10 @@ def test_comicmodule(tmpdir, scraperclass): # noqa
|
|||
host = get_host(scraperobj.url)
|
||||
try:
|
||||
with get_lock(host):
|
||||
_test_comic(tmpdir, scraperobj)
|
||||
_test_comic(str(tmpdir), scraperobj)
|
||||
except OSError:
|
||||
# interprocess lock not supported
|
||||
_test_comic(tmpdir, scraperobj)
|
||||
_test_comic(str(tmpdir), scraperobj)
|
||||
|
||||
|
||||
def _test_comic(outdir, scraperobj):
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import pytest
|
||||
import sys
|
||||
from . import dosage_cmd, run_checked, tmpdir # noqa
|
||||
from . import dosage_cmd, run_checked
|
||||
|
||||
|
||||
def run_with_options(options, cmd=dosage_cmd):
|
||||
|
@ -41,14 +41,14 @@ class TestDosage(object):
|
|||
with pytest.raises(OSError):
|
||||
run_with_options(['Garfield'])
|
||||
|
||||
def test_fetch_html_and_rss(self, tmpdir): # noqa
|
||||
run_with_options(["-n", "2", "-v", "-b", tmpdir, "-o", "html", "-o",
|
||||
"rss", "xkcd"])
|
||||
def test_fetch_html_and_rss(self, tmpdir):
|
||||
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "-o", "html",
|
||||
"-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",
|
||||
"--basepath", tmpdir, "--output", "rss", "--output",
|
||||
"html", "--adult", "oglaf"])
|
||||
"--basepath", str(tmpdir), "--output", "rss",
|
||||
"--output", "html", "--adult", "oglaf"])
|
||||
|
||||
def test_fetch_indexed(self, tmpdir): # noqa
|
||||
run_with_options(["-n", "2", "-v", "-b", tmpdir, "xkcd:303"])
|
||||
def test_fetch_indexed(self, tmpdir):
|
||||
run_with_options(["-n", "2", "-v", "-b", str(tmpdir), "xkcd:303"])
|
||||
|
|
Loading…
Reference in a new issue