[diffoscope] 04/04: Avoid Don't-Repeat-Yourself violations by factoring out fixture loading.
Chris Lamb
chris at chris-lamb.co.uk
Sat Aug 20 21:29:54 CEST 2016
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 9401a7e69ed5309a8a14232539e85fc7f900b246
Author: Chris Lamb <lamby at debian.org>
Date: Sat Aug 20 20:29:31 2016 +0100
Avoid Don't-Repeat-Yourself violations by factoring out fixture loading.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
tests/comparators/test_binary.py | 11 +++--------
tests/comparators/test_bzip2.py | 13 ++++---------
tests/comparators/test_cpio.py | 16 ++++------------
tests/comparators/test_deb.py | 13 +++----------
tests/comparators/test_dex.py | 16 ++++------------
tests/comparators/test_elf.py | 14 +++-----------
tests/comparators/test_epub.py | 17 ++++-------------
tests/comparators/test_fonts.py | 16 ++++------------
tests/comparators/test_fsimage.py | 17 ++++-------------
tests/comparators/test_gettext.py | 26 ++++++--------------------
tests/comparators/test_git.py | 15 +++------------
tests/comparators/test_gzip.py | 10 +++-------
tests/comparators/test_haskell.py | 16 +++-------------
tests/comparators/test_icc.py | 17 ++++-------------
tests/comparators/test_image.py | 17 ++++-------------
tests/comparators/test_ipk.py | 17 ++++-------------
tests/comparators/test_iso9660.py | 17 ++++-------------
tests/comparators/test_java.py | 17 ++++-------------
tests/comparators/test_json.py | 15 +++------------
tests/comparators/test_macho.py | 17 ++++-------------
tests/comparators/test_mono.py | 17 ++++-------------
tests/comparators/test_pdf.py | 17 ++++-------------
tests/comparators/test_png.py | 15 +++------------
tests/comparators/test_ppu.py | 17 ++++-------------
tests/comparators/test_ps.py | 16 ++++------------
tests/comparators/test_rlib.py | 14 +++-----------
tests/comparators/test_rpm.py | 17 ++++-------------
tests/comparators/test_sqlite.py | 17 ++++-------------
tests/comparators/test_squashfs.py | 17 ++++-------------
tests/comparators/test_tar.py | 19 ++++---------------
tests/comparators/test_text.py | 24 ++++++------------------
tests/comparators/test_utils.py | 28 ++++++----------------------
tests/comparators/test_xz.py | 11 +++--------
tests/comparators/test_zip.py | 23 +++++------------------
tests/comparators/utils.py | 8 ++++++++
35 files changed, 141 insertions(+), 436 deletions(-)
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index 401de7e..5cc1160 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -25,10 +25,9 @@ import diffoscope.comparators.binary
from diffoscope import tool_required
from diffoscope.exc import RequiredToolNotFound
from diffoscope.difference import Difference
-from diffoscope.comparators import specialize
from diffoscope.comparators.binary import File, FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
TEST_FILE1_PATH = data('binary1')
TEST_FILE2_PATH = data('binary2')
@@ -36,13 +35,9 @@ TEST_ASCII_PATH = data('text_ascii1')
TEST_UNICODE_PATH = data('text_unicode1')
TEST_ISO8859_PATH = data('text_iso8859')
- at pytest.fixture
-def binary1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
- at pytest.fixture
-def binary2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+binary1 = load_fixture(TEST_FILE1_PATH)
+binary2 = load_fixture(TEST_FILE2_PATH)
def test_same_content(binary1):
assert binary1.has_same_content_as(binary1) is True
diff --git a/tests/comparators/test_bzip2.py b/tests/comparators/test_bzip2.py
index 144afed..706efa7 100644
--- a/tests/comparators/test_bzip2.py
+++ b/tests/comparators/test_bzip2.py
@@ -22,22 +22,17 @@ import pytest
from diffoscope.config import Config
from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.bzip2 import Bzip2File
+from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
TEST_FILE1_PATH = data('test1.bz2')
TEST_FILE2_PATH = data('test2.bz2')
- at pytest.fixture
-def bzip1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def bzip2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+bzip1 = load_fixture(TEST_FILE1_PATH)
+bzip2 = load_fixture(TEST_FILE2_PATH)
def test_identification(bzip1):
assert isinstance(bzip1, Bzip2File)
diff --git a/tests/comparators/test_cpio.py b/tests/comparators/test_cpio.py
index 435de58..3415d43 100644
--- a/tests/comparators/test_cpio.py
+++ b/tests/comparators/test_cpio.py
@@ -20,22 +20,14 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.cpio import CpioFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.cpio')
-TEST_FILE2_PATH = data('test2.cpio')
- at pytest.fixture
-def cpio1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def cpio2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+cpio1 = load_fixture(data('test1.cpio'))
+cpio2 = load_fixture(data('test2.cpio'))
def test_identification(cpio1):
assert isinstance(cpio1, CpioFile)
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index cdf8caa..2bb85a1 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -26,18 +26,11 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.deb import DebFile, Md5sumsFile, DebDataTarFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import data
+from utils import data, load_fixture
-TEST_FILE1_PATH = data('test1.deb')
-TEST_FILE2_PATH = data('test2.deb')
- at pytest.fixture
-def deb1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def deb2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+deb1 = load_fixture(data('test1.deb'))
+deb2 = load_fixture(data('test2.deb'))
def test_identification(deb1):
assert isinstance(deb1, DebFile)
diff --git a/tests/comparators/test_dex.py b/tests/comparators/test_dex.py
index 03cc4cf..787f7f4 100644
--- a/tests/comparators/test_dex.py
+++ b/tests/comparators/test_dex.py
@@ -20,22 +20,14 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.dex import DexFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.dex')
-TEST_FILE2_PATH = data('test2.dex')
- at pytest.fixture
-def dex1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def dex2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+dex1 = load_fixture(data('test1.dex'))
+dex2 = load_fixture(data('test2.dex'))
def test_identification(dex1):
assert isinstance(dex1, DexFile)
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 24ab904..ee150a1 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -27,7 +27,7 @@ from diffoscope.comparators.elf import ElfFile, StaticLibFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.directory import FilesystemDirectory
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
try:
import diffoscope.comparators.debian # noqa
@@ -35,16 +35,8 @@ try:
except ImportError:
miss_debian_module = True
-TEST_OBJ1_PATH = data('test1.o')
-TEST_OBJ2_PATH = data('test2.o')
-
- at pytest.fixture
-def obj1():
- return specialize(FilesystemFile(TEST_OBJ1_PATH))
-
- at pytest.fixture
-def obj2():
- return specialize(FilesystemFile(TEST_OBJ2_PATH))
+obj1 = load_fixture(data('test1.o'))
+obj2 = load_fixture(data('test2.o'))
def test_obj_identification(obj1):
assert isinstance(obj1, ElfFile)
diff --git a/tests/comparators/test_epub.py b/tests/comparators/test_epub.py
index a680703..b33f8b0 100644
--- a/tests/comparators/test_epub.py
+++ b/tests/comparators/test_epub.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.zip import ZipFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.epub')
-TEST_FILE2_PATH = data('test2.epub')
-
- at pytest.fixture
-def epub1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def epub2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+epub1 = load_fixture(data('test1.epub'))
+epub2 = load_fixture(data('test2.epub'))
def test_identification(epub1):
assert isinstance(epub1, ZipFile)
diff --git a/tests/comparators/test_fonts.py b/tests/comparators/test_fonts.py
index 33cf2c4..747de24 100644
--- a/tests/comparators/test_fonts.py
+++ b/tests/comparators/test_fonts.py
@@ -20,22 +20,14 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.fonts import TtfFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('Samyak-Malayalam1.ttf')
-TEST_FILE2_PATH = data('Samyak-Malayalam2.ttf')
- at pytest.fixture
-def ttf1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def ttf2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+ttf1 = load_fixture(data('Samyak-Malayalam1.ttf'))
+ttf2 = load_fixture(data('Samyak-Malayalam2.ttf'))
def test_identification(ttf1):
assert isinstance(ttf1, TtfFile)
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index 391a698..603f9c8 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -20,11 +20,10 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
from diffoscope.comparators.fsimage import FsImageFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
try:
import guestfs
@@ -32,8 +31,8 @@ try:
except ImportError:
miss_guestfs = True
-TEST_FILE1_PATH = data('test1.ext4')
-TEST_FILE2_PATH = data('test2.ext4')
+img1 = load_fixture(data('test1.ext4'))
+img2 = load_fixture(data('test2.ext4'))
def guestfs_working():
if miss_guestfs:
@@ -46,14 +45,6 @@ def guestfs_working():
return False
return True
- at pytest.fixture
-def img1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def img2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
-
def test_identification(img1):
assert isinstance(img1, FsImageFile)
diff --git a/tests/comparators/test_gettext.py b/tests/comparators/test_gettext.py
index ba1ca99..534cdd6 100644
--- a/tests/comparators/test_gettext.py
+++ b/tests/comparators/test_gettext.py
@@ -21,22 +21,13 @@ import codecs
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
from diffoscope.comparators.gettext import MoFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.mo')
-TEST_FILE2_PATH = data('test2.mo')
-
- at pytest.fixture
-def mo1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def mo2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+mo1 = load_fixture(data('test1.mo'))
+mo2 = load_fixture(data('test2.mo'))
def test_identification(mo1):
assert isinstance(mo1, MoFile)
@@ -54,13 +45,8 @@ def test_diff(differences):
expected_diff = open(data('mo_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
- at pytest.fixture
-def mo_no_charset():
- return specialize(FilesystemFile(data('test_no_charset.mo')))
-
- at pytest.fixture
-def mo_iso8859_1():
- return specialize(FilesystemFile(data('test_iso8859-1.mo')))
+mo_no_charset = load_fixture(data('test_no_charset.mo'))
+mo_iso8859_1 = load_fixture(data('test_iso8859-1.mo'))
@skip_unless_tool_exists('msgunfmt')
def test_charsets(mo_no_charset, mo_iso8859_1):
diff --git a/tests/comparators/test_git.py b/tests/comparators/test_git.py
index cfb5853..2939bae 100644
--- a/tests/comparators/test_git.py
+++ b/tests/comparators/test_git.py
@@ -19,22 +19,13 @@
import pytest
-from diffoscope.comparators import specialize
from diffoscope.comparators.git import GitIndexFile
from diffoscope.comparators.binary import FilesystemFile
-from utils import data
+from utils import data, load_fixture
-TEST_FILE1_PATH = data('test1.git-index')
-TEST_FILE2_PATH = data('test2.git-index')
-
- at pytest.fixture
-def git1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def git2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+git1 = load_fixture(data('test1.git-index'))
+git2 = load_fixture(data('test2.git-index'))
def test_identification(git1):
assert isinstance(git1, GitIndexFile)
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index 323f25e..c6c2c96 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -25,18 +25,14 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.gzip import GzipFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import data
+from utils import data, load_fixture
TEST_FILE1_PATH = data('test1.gz')
TEST_FILE2_PATH = data('test2.gz')
- at pytest.fixture
-def gzip1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
- at pytest.fixture
-def gzip2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+gzip1 = load_fixture(TEST_FILE1_PATH)
+gzip2 = load_fixture(TEST_FILE2_PATH)
def test_identification(gzip1):
assert isinstance(gzip1, GzipFile)
diff --git a/tests/comparators/test_haskell.py b/tests/comparators/test_haskell.py
index 0a6ecbf..b9233d0 100644
--- a/tests/comparators/test_haskell.py
+++ b/tests/comparators/test_haskell.py
@@ -19,22 +19,12 @@
import pytest
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.haskell import HiFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.hi')
-TEST_FILE2_PATH = data('test2.hi')
-
- at pytest.fixture
-def haskell1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def haskell2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+haskell1 = load_fixture(data('test1.hi'))
+haskell2 = load_fixture(data('test2.hi'))
@skip_unless_tool_exists('ghc')
def test_identification(haskell1):
diff --git a/tests/comparators/test_icc.py b/tests/comparators/test_icc.py
index 6b0c7ae..42adfd3 100644
--- a/tests/comparators/test_icc.py
+++ b/tests/comparators/test_icc.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.icc import IccFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.icc')
-TEST_FILE2_PATH = data('test2.icc')
-
- at pytest.fixture
-def icc1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def icc2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+icc1 = load_fixture(data('test1.icc'))
+icc2 = load_fixture(data('test2.icc'))
def test_identification(icc1):
assert isinstance(icc1, IccFile)
diff --git a/tests/comparators/test_image.py b/tests/comparators/test_image.py
index 273ac7c..cd58f27 100644
--- a/tests/comparators/test_image.py
+++ b/tests/comparators/test_image.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.image import ImageFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.jpg')
-TEST_FILE2_PATH = data('test2.jpg')
-
- at pytest.fixture
-def image1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def image2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+image1 = load_fixture(data('test1.jpg'))
+image2 = load_fixture(data('test2.jpg'))
def test_identification(image1):
assert isinstance(image1, ImageFile)
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index 959a27f..b1029cb 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.ipk import IpkFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import data
+from utils import data, load_fixture
-TEST_FILE1_PATH = data('base-files_157-r45695_ar71xx.ipk')
-TEST_FILE2_PATH = data('base-files_157-r45918_ar71xx.ipk')
-
- at pytest.fixture
-def ipk1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def ipk2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+ipk1 = load_fixture(data('base-files_157-r45695_ar71xx.ipk'))
+ipk2 = load_fixture(data('base-files_157-r45918_ar71xx.ipk'))
def test_identification(ipk1):
assert isinstance(ipk1, IpkFile)
diff --git a/tests/comparators/test_iso9660.py b/tests/comparators/test_iso9660.py
index 7ab4953..151c306 100644
--- a/tests/comparators/test_iso9660.py
+++ b/tests/comparators/test_iso9660.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
from diffoscope.comparators.iso9660 import Iso9660File
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.iso')
-TEST_FILE2_PATH = data('test2.iso')
-
- at pytest.fixture
-def iso1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def iso2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+iso1 = load_fixture(data('test1.iso'))
+iso2 = load_fixture(data('test2.iso'))
def test_identification(iso1):
assert isinstance(iso1, Iso9660File)
diff --git a/tests/comparators/test_java.py b/tests/comparators/test_java.py
index bd8337e..b5044ed 100644
--- a/tests/comparators/test_java.py
+++ b/tests/comparators/test_java.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.java import ClassFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('Test1.class')
-TEST_FILE2_PATH = data('Test2.class')
-
- at pytest.fixture
-def class1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def class2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+class1 = load_fixture(data('Test1.class'))
+class2 = load_fixture(data('Test2.class'))
def test_identification(class1):
assert isinstance(class1, ClassFile)
diff --git a/tests/comparators/test_json.py b/tests/comparators/test_json.py
index 5a72995..1302d29 100644
--- a/tests/comparators/test_json.py
+++ b/tests/comparators/test_json.py
@@ -21,20 +21,11 @@ import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.json import JSONFile
-from diffoscope.comparators.binary import FilesystemFile
-from utils import data
+from utils import data, load_fixture
-TEST_FILE1_PATH = data('test1.json')
-TEST_FILE2_PATH = data('test2.json')
-
- at pytest.fixture
-def json1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def json2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+json1 = load_fixture(data('test1.json'))
+json2 = load_fixture(data('test2.json'))
def test_identification(json1):
assert isinstance(json1, JSONFile)
diff --git a/tests/comparators/test_macho.py b/tests/comparators/test_macho.py
index 6c7c6e8..d2ef29c 100644
--- a/tests/comparators/test_macho.py
+++ b/tests/comparators/test_macho.py
@@ -22,22 +22,13 @@ import pytest
import os.path
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.macho import MachoFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_OBJ1_PATH = data('test1.macho')
-TEST_OBJ2_PATH = data('test2.macho')
-
- at pytest.fixture
-def obj1():
- return specialize(FilesystemFile(TEST_OBJ1_PATH))
-
- at pytest.fixture
-def obj2():
- return specialize(FilesystemFile(TEST_OBJ2_PATH))
+obj1 = load_fixture(data('test1.macho'))
+obj2 = load_fixture(data('test2.macho'))
def test_obj_identification(obj1):
assert isinstance(obj1, MachoFile)
diff --git a/tests/comparators/test_mono.py b/tests/comparators/test_mono.py
index b3423a5..b71f36c 100644
--- a/tests/comparators/test_mono.py
+++ b/tests/comparators/test_mono.py
@@ -20,27 +20,18 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.mono import MonoExeFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
# these were generated with:
# echo 'public class Test { static public void Main () {} }' > test.cs
# mcs -out:test1.exe test.cs ; sleep 2; mcs -out:test2.exe test.cs
-TEST_FILE1_PATH = data('test1.exe')
-TEST_FILE2_PATH = data('test2.exe')
-
- at pytest.fixture
-def exe1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def exe2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+exe1 = load_fixture(data('test1.exe'))
+exe2 = load_fixture(data('test2.exe'))
def test_identification(exe1):
assert isinstance(exe1, MonoExeFile)
diff --git a/tests/comparators/test_pdf.py b/tests/comparators/test_pdf.py
index d3795f9..7e49d6c 100644
--- a/tests/comparators/test_pdf.py
+++ b/tests/comparators/test_pdf.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.pdf import PdfFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.pdf')
-TEST_FILE2_PATH = data('test2.pdf')
-
- at pytest.fixture
-def pdf1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def pdf2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+pdf1 = load_fixture(data('test1.pdf'))
+pdf2 = load_fixture(data('test2.pdf'))
def test_identification(pdf1):
assert isinstance(pdf1, PdfFile)
diff --git a/tests/comparators/test_png.py b/tests/comparators/test_png.py
index d5d3d65..2c6e1ea 100644
--- a/tests/comparators/test_png.py
+++ b/tests/comparators/test_png.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.png import PngFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.png')
-TEST_FILE2_PATH = data('test2.png')
-
- at pytest.fixture
-def png1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def png2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+png1 = load_fixture(data('test1.png'))
+png2 = load_fixture(data('test2.png'))
def test_identification(png1):
assert isinstance(png1, PngFile)
diff --git a/tests/comparators/test_ppu.py b/tests/comparators/test_ppu.py
index 4296ea1..8ef5896 100644
--- a/tests/comparators/test_ppu.py
+++ b/tests/comparators/test_ppu.py
@@ -21,11 +21,10 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.ppu import PpuFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
# These test files were taken from two different builds of the Debian package
# fp-units-castle-game-engine (version 5.1.1-2 on amd64) on the Debian
@@ -33,16 +32,8 @@ from utils import skip_unless_tool_exists, data
# castletexturefont_dejavusans_10.ppu which are generated during package
# building of the cge package from dejavusans font in the fonts-dejavu package.
-TEST_FILE1_PATH = data('test1.ppu')
-TEST_FILE2_PATH = data('test2.ppu')
-
- at pytest.fixture
-def file1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def file2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+file1 = load_fixture(data('test1.ppu'))
+file2 = load_fixture(data('test2.ppu'))
@skip_unless_tool_exists('ppudump')
def test_identification(file1):
diff --git a/tests/comparators/test_ps.py b/tests/comparators/test_ps.py
index 2a34a08..804532c 100644
--- a/tests/comparators/test_ps.py
+++ b/tests/comparators/test_ps.py
@@ -22,20 +22,12 @@ import pytest
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.ps import PsFile
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.ps')
-TEST_FILE2_PATH = data('test2.ps')
-
- at pytest.fixture
-def ps1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def ps2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+ps1 = load_fixture(data('test1.ps'))
+ps2 = load_fixture(data('test2.ps'))
def test_identification(ps1):
assert isinstance(ps1, PsFile)
diff --git a/tests/comparators/test_rlib.py b/tests/comparators/test_rlib.py
index b896505..8a3a9c9 100644
--- a/tests/comparators/test_rlib.py
+++ b/tests/comparators/test_rlib.py
@@ -26,18 +26,10 @@ from diffoscope.comparators.ar import ArFile
from diffoscope.comparators.utils import diff_ignore_line_numbers
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, tool_older_than, data
+from utils import skip_unless_tool_exists, tool_older_than, data, load_fixture
-TEST_FILE1_PATH = data('test1.rlib')
-TEST_FILE2_PATH = data('test2.rlib')
-
- at pytest.fixture
-def rlib1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def rlib2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+rlib1 = load_fixture(data('test1.rlib'))
+rlib2 = load_fixture(data('test2.rlib'))
def test_identification(rlib1):
assert isinstance(rlib1, ArFile)
diff --git a/tests/comparators/test_rpm.py b/tests/comparators/test_rpm.py
index f851370..36bca5e 100644
--- a/tests/comparators/test_rpm.py
+++ b/tests/comparators/test_rpm.py
@@ -20,10 +20,9 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
try:
from diffoscope.comparators.rpm import RpmFile
@@ -32,16 +31,8 @@ except ImportError:
from diffoscope.comparators.rpm_fallback import RpmFile
miss_rpm_module = True
-TEST_FILE1_PATH = data('test1.rpm')
-TEST_FILE2_PATH = data('test2.rpm')
-
- at pytest.fixture
-def rpm1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def rpm2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+rpm1 = load_fixture(data('test1.rpm'))
+rpm2 = load_fixture(data('test2.rpm'))
def test_identification(rpm1):
assert isinstance(rpm1, RpmFile)
diff --git a/tests/comparators/test_sqlite.py b/tests/comparators/test_sqlite.py
index 0e39533..5dabc56 100644
--- a/tests/comparators/test_sqlite.py
+++ b/tests/comparators/test_sqlite.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
from diffoscope.comparators.sqlite import Sqlite3Database
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.sqlite3')
-TEST_FILE2_PATH = data('test2.sqlite3')
-
- at pytest.fixture
-def sqlite3db1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def sqlite3db2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+sqlite3db1 = load_fixture(data('test1.sqlite3'))
+sqlite3db2 = load_fixture(data('test2.sqlite3'))
def test_identification(sqlite3db1):
assert isinstance(sqlite3db1, Sqlite3Database)
diff --git a/tests/comparators/test_squashfs.py b/tests/comparators/test_squashfs.py
index 8ba994e..ce054c1 100644
--- a/tests/comparators/test_squashfs.py
+++ b/tests/comparators/test_squashfs.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
-from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.binary import NonExistingFile
from diffoscope.comparators.squashfs import SquashfsFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.squashfs')
-TEST_FILE2_PATH = data('test2.squashfs')
-
- at pytest.fixture
-def squashfs1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def squashfs2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+squashfs1 = load_fixture(data('test1.squashfs'))
+squashfs2 = load_fixture(data('test2.squashfs'))
def test_identification(squashfs1):
assert isinstance(squashfs1, SquashfsFile)
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index 6731110..4d6d176 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -20,22 +20,13 @@
import pytest
from diffoscope.config import Config
-from diffoscope.comparators import specialize
from diffoscope.comparators.tar import TarFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import data
+from utils import data, load_fixture
-TEST_FILE1_PATH = data('test1.tar')
-TEST_FILE2_PATH = data('test2.tar')
-
- at pytest.fixture
-def tar1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def tar2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+tar1 = load_fixture(data('test1.tar'))
+tar2 = load_fixture(data('test2.tar'))
def test_identification(tar1):
assert isinstance(tar1, TarFile)
@@ -71,9 +62,7 @@ def test_compare_non_existing(monkeypatch, tar1):
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
- at pytest.fixture
-def no_permissions_tar():
- return specialize(FilesystemFile(data('no-perms.tar')))
+no_permissions_tar = load_fixture(data('no-perms.tar'))
# Reported as Debian #797164. This is a good way to notice if we unpack directories
# as we won't be able to remove files in one if we don't have write permissions.
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
index 41ddbfc..23d63ba 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -24,15 +24,10 @@ from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import data
+from utils import data, load_fixture
- at pytest.fixture
-def ascii1():
- return specialize(FilesystemFile(data('text_ascii1')))
-
- at pytest.fixture
-def ascii2():
- return specialize(FilesystemFile(data('text_ascii2')))
+ascii1 = load_fixture(data('text_ascii1'))
+ascii2 = load_fixture(data('text_ascii2'))
def test_no_differences(ascii1):
difference = ascii1.compare(ascii1)
@@ -46,22 +41,15 @@ def test_difference_in_ascii(ascii1, ascii2):
assert not difference.comments
assert len(difference.details) == 0
- at pytest.fixture
-def unicode1():
- return specialize(FilesystemFile(data('text_unicode1')))
-
- at pytest.fixture
-def unicode2():
- return specialize(FilesystemFile(data('text_unicode2')))
+unicode1 = load_fixture(data('text_unicode1'))
+unicode2 = load_fixture(data('text_unicode2'))
def test_difference_in_unicode(unicode1, unicode2):
difference = unicode1.compare(unicode2)
expected_diff = codecs.open(data('text_unicode_expected_diff'), encoding='utf-8').read()
assert difference.unified_diff == expected_diff
- at pytest.fixture
-def iso8859():
- return specialize(FilesystemFile(data('text_iso8859')))
+iso8859 = load_fixture(data('text_iso8859'))
def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
difference = iso8859.compare(unicode1)
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index 5e91c6e..0341739 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -22,11 +22,9 @@ import pytest
from diffoscope.config import Config
from diffoscope.difference import Difference
-from diffoscope.comparators import specialize
from diffoscope.comparators.utils import Command
-from diffoscope.comparators.binary import FilesystemFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
try:
import tlsh # noqa
@@ -34,18 +32,9 @@ try:
except ImportError:
miss_tlsh = True
-
- at pytest.fixture
-def fuzzy_tar1():
- return specialize(FilesystemFile(data('fuzzy1.tar')))
-
- at pytest.fixture
-def fuzzy_tar2():
- return specialize(FilesystemFile(data('fuzzy2.tar')))
-
- at pytest.fixture
-def fuzzy_tar3():
- return specialize(FilesystemFile(data('fuzzy3.tar')))
+fuzzy_tar1 = load_fixture(data('fuzzy1.tar'))
+fuzzy_tar2 = load_fixture(data('fuzzy2.tar'))
+fuzzy_tar3 = load_fixture(data('fuzzy3.tar'))
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
@@ -62,13 +51,8 @@ def test_fuzzy_matching_only_once(fuzzy_tar1, fuzzy_tar3):
assert len(differences) == 2
expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
- at pytest.fixture
-def fuzzy_tar_in_tar1():
- return specialize(FilesystemFile(data('fuzzy-tar-in-tar1.tar')))
-
- at pytest.fixture
-def fuzzy_tar_in_tar2():
- return specialize(FilesystemFile(data('fuzzy-tar-in-tar2.tar')))
+fuzzy_tar_in_tar1 = load_fixture(data('fuzzy-tar-in-tar1.tar'))
+fuzzy_tar_in_tar2 = load_fixture(data('fuzzy-tar-in-tar2.tar'))
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
diff --git a/tests/comparators/test_xz.py b/tests/comparators/test_xz.py
index 713bed3..1a2223c 100644
--- a/tests/comparators/test_xz.py
+++ b/tests/comparators/test_xz.py
@@ -25,18 +25,13 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.xz import XzFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
TEST_FILE1_PATH = data('test1.xz')
TEST_FILE2_PATH = data('test2.xz')
- at pytest.fixture
-def xz1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def xz2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+xz1 = load_fixture(TEST_FILE1_PATH)
+xz2 = load_fixture(TEST_FILE2_PATH)
def test_identification(xz1):
assert isinstance(xz1, XzFile)
diff --git a/tests/comparators/test_zip.py b/tests/comparators/test_zip.py
index e1d5d5e..4428b61 100644
--- a/tests/comparators/test_zip.py
+++ b/tests/comparators/test_zip.py
@@ -24,18 +24,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.zip import ZipFile, MozillaZipFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from utils import skip_unless_tool_exists, data
+from utils import skip_unless_tool_exists, data, load_fixture
-TEST_FILE1_PATH = data('test1.zip')
-TEST_FILE2_PATH = data('test2.zip')
-
- at pytest.fixture
-def zip1():
- return specialize(FilesystemFile(TEST_FILE1_PATH))
-
- at pytest.fixture
-def zip2():
- return specialize(FilesystemFile(TEST_FILE2_PATH))
+zip1 = load_fixture(data('test1.zip'))
+zip2 = load_fixture(data('test2.zip'))
def test_identification(zip1):
assert isinstance(zip1, ZipFile)
@@ -70,13 +62,8 @@ def test_compare_non_existing(monkeypatch, zip1):
TEST_MOZZIP1_PATH = data('test1.mozzip')
TEST_MOZZIP2_PATH = data('test2.mozzip')
- at pytest.fixture
-def mozzip1():
- return specialize(FilesystemFile(TEST_MOZZIP1_PATH))
-
- at pytest.fixture
-def mozzip2():
- return specialize(FilesystemFile(TEST_MOZZIP2_PATH))
+mozzip1 = load_fixture(TEST_MOZZIP1_PATH)
+mozzip2 = load_fixture(TEST_MOZZIP2_PATH)
def test_mozzip_identification(mozzip1):
assert isinstance(mozzip1, MozillaZipFile)
diff --git a/tests/comparators/utils.py b/tests/comparators/utils.py
index d8ea3e6..ac2e96e 100644
--- a/tests/comparators/utils.py
+++ b/tests/comparators/utils.py
@@ -25,6 +25,9 @@ import subprocess
from distutils.spawn import find_executable
from distutils.version import StrictVersion
+from diffoscope.comparators import specialize
+from diffoscope.comparators.binary import FilesystemFile
+
@pytest.fixture(autouse=True)
def set_locale():
@@ -36,6 +39,11 @@ def skip_unless_tool_exists(*alternatives):
reason="missing {}".format(" or ".join(alternatives)),
)
+def load_fixture(filename):
+ return pytest.fixture(
+ lambda: specialize(FilesystemFile(filename))
+ )
+
def data(filename):
return os.path.join(
os.path.dirname(os.path.dirname(__file__)),
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list