From dda920f3530307b72d8d903af824fabe7930715c Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Mon, 28 Mar 2016 16:29:57 +0200 Subject: [PATCH] Use py.test's tmpdir fixture. --- tests/__init__.py | 10 ---------- tests/test_comics.py | 7 +++---- tests/test_dosage.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index bf613f61b..b5047bb27 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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) diff --git a/tests/test_comics.py b/tests/test_comics.py index 0f0d2e0dc..28fafcdd6 100644 --- a/tests/test_comics.py +++ b/tests/test_comics.py @@ -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): diff --git a/tests/test_dosage.py b/tests/test_dosage.py index c7aef02f8..4c9ed5760 100644 --- a/tests/test_dosage.py +++ b/tests/test_dosage.py @@ -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"])