[diffoscope] 01/01: tests: use tempdir rather than ./cache for guestfs cache
Ximin Luo
infinity0 at debian.org
Tue Jul 11 15:03:46 CEST 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit c9a0c6c5d5dd8ef81f86be509b89701e56e123ff
Author: Ximin Luo <infinity0 at debian.org>
Date: Tue Jul 11 15:02:35 2017 +0200
tests: use tempdir rather than ./cache for guestfs cache
---
tests/comparators/test_fsimage.py | 41 +++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index e2a5b7c..3a2b3af 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -19,6 +19,7 @@
import pytest
import os
+import tempfile
from diffoscope.config import Config
from diffoscope.comparators.missing_file import MissingFile
@@ -30,29 +31,29 @@ from ..utils.tools import skip_unless_tools_exist, skip_unless_module_exists
img1 = load_fixture('test1.ext4')
img2 = load_fixture('test2.ext4')
-def guestfs_working():
- try:
- import guestfs
- except ImportError:
- return False
- g = guestfs.GuestFS (python_return_dict=True)
- cachedir = os.path.join(os.getcwd(), "cache")
- os.makedirs(cachedir, exist_ok=True)
- g.set_cachedir(cachedir)
- g.add_drive_opts("/dev/null", format="raw", readonly=1)
- try:
- g.launch()
- except RuntimeError:
- return False
- return True
+ at pytest.fixture(scope="module")
+def guestfs_tempdir():
+ import guestfs
+ with tempfile.TemporaryDirectory(suffix='_diffoscope') as cachedir:
+ g = guestfs.GuestFS(python_return_dict=True)
+ g.set_cachedir(cachedir)
+ # set cachedir for the diffoscope.comparators.fsimage module as well
+ os.environ["LIBGUESTFS_CACHEDIR"] = cachedir
+ g.add_drive_opts("/dev/null", format="raw", readonly=1)
+ try:
+ g.launch()
+ except RuntimeError:
+ import traceback
+ traceback.print_exc()
+ pytest.skip('guestfs not working on the system')
+ yield cachedir
def test_identification(img1):
assert isinstance(img1, FsImageFile)
- at pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
-def test_no_differences(img1):
+def test_no_differences(img1, guestfs_tempdir):
difference = img1.compare(img1)
assert difference is None
@@ -60,10 +61,9 @@ def test_no_differences(img1):
def differences(img1, img2):
return img1.compare(img2).details
- at pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
-def test_differences(differences):
+def test_differences(differences, guestfs_tempdir):
assert differences[0].source1 == 'test1.ext4.tar'
tarinfo = differences[0].details[0]
tardiff = differences[0].details[1]
@@ -78,10 +78,9 @@ def test_differences(differences):
found_diff = tarinfo.unified_diff + tardiff.unified_diff + encodingdiff.unified_diff
assert expected_diff == found_diff
- at pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
-def test_compare_non_existing(monkeypatch, img1):
+def test_compare_non_existing(monkeypatch, img1, guestfs_tempdir):
monkeypatch.setattr(Config(), 'new_file', True)
difference = img1.compare(MissingFile('/nonexisting', img1))
assert difference.source2 == '/nonexisting'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list