import os
import pickle

import pytest

from sigal.gallery import Gallery
from sigal.plugins import extended_caching

CURRENT_DIR = os.path.dirname(__file__)


@pytest.fixture()
def remove_cache(settings):
    yield
    cachepath = os.path.join(settings['destination'], ".exif_cache")
    os.remove(cachepath)


def test_save_cache(settings, remove_cache):
    gal = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal)

    cachePath = os.path.join(settings['destination'], ".exif_cache")

    assert os.path.isfile(cachePath)

    with open(cachePath, "rb") as cacheFile:
        cache = pickle.load(cacheFile)

    assert cache["exifTest/21.jpg"] == gal.albums["exifTest"].medias[0].exif
    assert cache["exifTest/22.jpg"] == gal.albums["exifTest"].medias[1].exif
    assert cache["exifTest/noexif.png"] == gal.albums["exifTest"].medias[2].exif


def test_restore_cache(settings, remove_cache):
    gal1 = Gallery(settings, ncpu=1)
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching._restore_cache(gal2)
    assert gal1.exifCache == gal2.exifCache


def test_load_exif(settings, remove_cache):
    gal1 = Gallery(settings, ncpu=1)
    gal1.albums["exifTest"].medias[2].exif = "blafoo"
    gal1.exifCache = {"exifTest/21.jpg": "Foo",
                      "exifTest/22.jpg": "Bar"}

    extended_caching.load_exif(gal1.albums["exifTest"])

    assert gal1.albums["exifTest"].medias[0].exif == "Foo"
    assert gal1.albums["exifTest"].medias[1].exif == "Bar"
    assert gal1.albums["exifTest"].medias[2].exif == "blafoo"

    # check if setting gallery.exifCache works
    gal2 = Gallery(settings, ncpu=1)
    extended_caching.save_cache(gal1)
    extended_caching.load_exif(gal2.albums["exifTest"])

@@ -22,23 +22,8 @@
 le%0A%0A
-import pytest%0A%0A
 from
@@ -142,204 +142,88 @@
 )%0A%0A%0A
-@pytest.fixture()%0Adef remove_cache(settings):%0A    yield%0A    cachepath = os.path.join(settings%5B'destination'%5D, %22.exif_cache%22)%0A    os.remove(cachepath)%0A%0A%0Adef test_save_cache(settings, remove_cache):
+def test_save_cache(settings, tmpdir):%0A    settings%5B'destination'%5D = str(tmpdir)
 %0A   
@@ -752,38 +752,74 @@
 e(settings, 
-remove_cache):
+tmpdir):%0A    settings%5B'destination'%5D = str(tmpdir)
 %0A    gal1 = 
@@ -1040,22 +1040,58 @@
 gs, 
-remove_cache):
+tmpdir):%0A    settings%5B'destination'%5D = str(tmpdir)
 %0A   

Use tmpdir instead of custom fixture