[diffoscope] 03/07: Factor out ugly os.path.join in tests to a utility method.
Chris Lamb
chris at chris-lamb.co.uk
Mon Aug 15 21:55: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 54d0fb3122368c03af5de50f200bce538bf629e5
Author: Chris Lamb <lamby at debian.org>
Date: Mon Aug 15 20:17:02 2016 +0100
Factor out ugly os.path.join in tests to a utility method.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
tests/comparators/conftest.py | 7 +++++++
tests/comparators/test_binary.py | 23 +++++++++++------------
tests/comparators/test_bzip2.py | 11 +++++------
tests/comparators/test_cbfs.py | 11 +++++------
tests/comparators/test_cpio.py | 13 ++++++-------
tests/comparators/test_deb.py | 9 +++++----
tests/comparators/test_debian.py | 25 +++++++++++++------------
tests/comparators/test_dex.py | 9 ++++-----
tests/comparators/test_directory.py | 8 +++++---
tests/comparators/test_elf.py | 22 +++++++++++-----------
tests/comparators/test_epub.py | 9 ++++-----
tests/comparators/test_fonts.py | 9 ++++-----
tests/comparators/test_fsimage.py | 9 ++++-----
tests/comparators/test_gettext.py | 15 +++++++--------
tests/comparators/test_gzip.py | 11 ++++++-----
tests/comparators/test_icc.py | 9 ++++-----
tests/comparators/test_image.py | 9 ++++-----
tests/comparators/test_ipk.py | 9 +++++----
tests/comparators/test_iso9660.py | 15 +++++++--------
tests/comparators/test_java.py | 9 ++++-----
tests/comparators/test_json.py | 9 +++++----
tests/comparators/test_macho.py | 8 ++++----
tests/comparators/test_mono.py | 9 ++++-----
tests/comparators/test_pdf.py | 11 +++++------
tests/comparators/test_png.py | 9 ++++-----
tests/comparators/test_ppu.py | 9 ++++-----
tests/comparators/test_ps.py | 11 +++++------
tests/comparators/test_rlib.py | 13 ++++++-------
tests/comparators/test_rpm.py | 13 ++++++-------
tests/comparators/test_sqlite.py | 9 ++++-----
tests/comparators/test_squashfs.py | 13 ++++++-------
tests/comparators/test_tar.py | 15 ++++++++-------
tests/comparators/test_text.py | 21 +++++++++++----------
tests/comparators/test_utils.py | 17 ++++++++---------
tests/comparators/test_xz.py | 9 ++++-----
tests/comparators/test_zip.py | 19 +++++++++----------
36 files changed, 214 insertions(+), 223 deletions(-)
diff --git a/tests/comparators/conftest.py b/tests/comparators/conftest.py
index b740bf0..33465dc 100644
--- a/tests/comparators/conftest.py
+++ b/tests/comparators/conftest.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
+import os
import pytest
import diffoscope
import subprocess
@@ -33,6 +34,12 @@ def set_locale():
def tool_missing(cmd):
return find_executable(cmd) is None
+def data(filename):
+ return os.path.join(
+ os.path.dirname(os.path.dirname(__file__)),
+ 'data',
+ filename,
+ )
def tool_older_than(cmdline, min_ver, vcls=StrictVersion):
if find_executable(cmdline[0]) is None:
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index 61b628f..f3b3ec2 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -18,7 +18,6 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
import subprocess
import diffoscope.comparators.binary
@@ -28,13 +27,13 @@ from diffoscope.difference import Difference
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import File, FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/binary1')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/binary2')
-TEST_ASCII_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
-TEST_UNICODE_PATH = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
-TEST_ISO8859_PATH = os.path.join(os.path.dirname(__file__), '../data/text_iso8859')
+TEST_FILE1_PATH = data('binary1')
+TEST_FILE2_PATH = data('binary2')
+TEST_ASCII_PATH = data('text_ascii1')
+TEST_UNICODE_PATH = data('text_unicode1')
+TEST_ISO8859_PATH = data('text_iso8859')
@pytest.fixture
def binary1():
@@ -72,7 +71,7 @@ def test_no_differences_with_xxd(binary1):
@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
def test_compare_with_xxd(binary1, binary2):
difference = binary1.compare_bytes(binary2)
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
+ expected_diff = open(data('binary_expected_diff')).read()
assert difference.unified_diff == expected_diff
def test_compare_non_existing_with_xxd(binary1):
@@ -91,7 +90,7 @@ def test_no_differences_without_xxd(xxd_not_found, binary1):
def test_compare_without_xxd(xxd_not_found, binary1, binary2):
difference = binary1.compare(binary2)
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_hexdump_expected_diff')).read()
+ expected_diff = open(data('binary_hexdump_expected_diff')).read()
assert difference.unified_diff == expected_diff
def test_with_compare_details():
@@ -108,7 +107,7 @@ def test_with_compare_details_and_fallback():
def compare_details(self, other, source=None):
return []
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
+ expected_diff = open(data('binary_expected_diff')).read()
assert 'yet data differs' in difference.comment
assert difference.unified_diff == expected_diff
@@ -127,7 +126,7 @@ def test_with_compare_details_and_failed_process():
subprocess.check_output(['sh', '-c', 'echo "%s"; exit 42' % output], shell=False)
raise Exception('should not be run')
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
+ expected_diff = open(data('../data/binary_expected_diff')).read()
assert output in difference.comment
assert '42' in difference.comment
assert difference.unified_diff == expected_diff
@@ -140,7 +139,7 @@ def test_with_compare_details_and_tool_not_found(monkeypatch):
def compare_details(self, other, source=None):
raise Exception('should not be run')
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
+ expected_diff = open(data('binary_expected_diff')).read()
assert 'nonexistent' in difference.comment
assert 'some-package' in difference.comment
assert difference.unified_diff == expected_diff
diff --git a/tests/comparators/test_bzip2.py b/tests/comparators/test_bzip2.py
index 2d52b80..34fe575 100644
--- a/tests/comparators/test_bzip2.py
+++ b/tests/comparators/test_bzip2.py
@@ -19,17 +19,16 @@
import shutil
import pytest
-import os.path
+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.config import Config
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.bz2')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.bz2')
+TEST_FILE1_PATH = data('test1.bz2')
+TEST_FILE2_PATH = data('test2.bz2')
@pytest.fixture
@@ -70,7 +69,7 @@ def test_content_source_without_extension(tmpdir):
@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
def test_content_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
diff --git a/tests/comparators/test_cbfs.py b/tests/comparators/test_cbfs.py
index 12c8d19..400216a 100644
--- a/tests/comparators/test_cbfs.py
+++ b/tests/comparators/test_cbfs.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-import os
import struct
import pytest
import subprocess
@@ -28,10 +27,10 @@ from diffoscope.presenters.text import output_text
from diffoscope.comparators.cbfs import CbfsFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii2')
+TEST_FILE1_PATH = data('text_ascii1')
+TEST_FILE2_PATH = data('text_ascii2')
@pytest.fixture
def rom1(tmpdir):
@@ -77,14 +76,14 @@ def differences(rom1, rom2):
@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
def test_listing(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/cbfs_listing_expected_diff')).read()
+ expected_diff = open(data('cbfs_listing_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
def test_content(differences):
assert differences[1].source1 == 'text'
assert differences[1].source2 == 'text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
diff --git a/tests/comparators/test_cpio.py b/tests/comparators/test_cpio.py
index 3efaa48..139d4a1 100644
--- a/tests/comparators/test_cpio.py
+++ b/tests/comparators/test_cpio.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.cpio import CpioFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.cpio')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.cpio')
+TEST_FILE1_PATH = data('test1.cpio')
+TEST_FILE2_PATH = data('test2.cpio')
@pytest.fixture
def cpio1():
@@ -51,21 +50,21 @@ def differences(cpio1, cpio2):
@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_listing(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/cpio_listing_expected_diff')).read()
+ expected_diff = open(data('cpio_listing_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_symlink(differences):
assert differences[1].source1 == 'dir/link'
assert differences[1].comment == 'symlink'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
+ expected_diff = open(data('symlink_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_compressed_files(differences):
assert differences[2].source1 == 'dir/text'
assert differences[2].source2 == 'dir/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[2].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index dc784e4..b8b389c 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -18,7 +18,6 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
import diffoscope.comparators
@@ -27,8 +26,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.deb import DebFile, Md5sumsFile, DebDataTarFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.deb')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.deb')
+from conftest import data
+
+TEST_FILE1_PATH = data('test1.deb')
+TEST_FILE2_PATH = data('test2.deb')
@pytest.fixture
def deb1():
@@ -50,7 +51,7 @@ def differences(deb1, deb2):
return deb1.compare(deb2).details
def test_metadata(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/deb_metadata_expected_diff')).read()
+ expected_diff = open(data('deb_metadata_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
def test_compressed_files(differences):
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index 6cb8abf..65c1d35 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -19,13 +19,14 @@
import shutil
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.presenters.text import output_text
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from conftest import data
+
try:
from diffoscope.comparators.debian import DotChangesFile, DotDscFile, \
DotBuildinfoFile
@@ -34,10 +35,10 @@ except ImportError:
from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile, DotBuildinfoFile
miss_debian_module = True
-TEST_DOT_CHANGES_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.changes')
-TEST_DOT_CHANGES_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.changes')
-TEST_DEB_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.deb')
-TEST_DEB_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.deb')
+TEST_DOT_CHANGES_FILE1_PATH = data('test1.changes')
+TEST_DOT_CHANGES_FILE2_PATH = data('test2.changes')
+TEST_DEB_FILE1_PATH = data('test1.deb')
+TEST_DEB_FILE2_PATH = data('test2.deb')
@pytest.fixture
def dot_changes1(tmpdir):
@@ -80,7 +81,7 @@ def dot_changes_differences(dot_changes1, dot_changes2):
@pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_description(dot_changes_differences):
assert dot_changes_differences[0]
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/dot_changes_description_expected_diff')).read()
+ expected_diff = open(data('dot_changes_description_expected_diff')).read()
assert dot_changes_differences[0].unified_diff == expected_diff
@pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
@@ -95,10 +96,10 @@ def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
-TEST_DOT_DSC_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.dsc')
-TEST_DOT_DSC_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.dsc')
-TEST_DEB_SRC1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.debsrc.tar.gz')
-TEST_DEB_SRC2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.debsrc.tar.gz')
+TEST_DOT_DSC_FILE1_PATH = data('test1.dsc')
+TEST_DOT_DSC_FILE2_PATH = data('test2.dsc')
+TEST_DEB_SRC1_PATH = data('test1.debsrc.tar.gz')
+TEST_DEB_SRC2_PATH = data('test2.debsrc.tar.gz')
@pytest.fixture
def dot_dsc1(tmpdir):
@@ -150,8 +151,8 @@ def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
-TEST_DOT_BUILDINFO_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.buildinfo')
-TEST_DOT_BUILDINFO_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.buildinfo')
+TEST_DOT_BUILDINFO_FILE1_PATH = data('test1.buildinfo')
+TEST_DOT_BUILDINFO_FILE2_PATH = data('test2.buildinfo')
@pytest.fixture
def dot_buildinfo1(tmpdir):
diff --git a/tests/comparators/test_dex.py b/tests/comparators/test_dex.py
index efcd136..54f19e7 100644
--- a/tests/comparators/test_dex.py
+++ b/tests/comparators/test_dex.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.dex import DexFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.dex')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.dex')
+TEST_FILE1_PATH = data('test1.dex')
+TEST_FILE2_PATH = data('test2.dex')
@pytest.fixture
def dex1():
@@ -61,7 +60,7 @@ def test_differences(differences):
assert zipinfo.source2 == 'zipinfo -v {}'
assert classdiff.source1 == 'com/example/MainActivity.class'
assert classdiff.source2 == 'com/example/MainActivity.class'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/dex_expected_diffs')).read()
+ expected_diff = open(data('dex_expected_diffs')).read()
found_diff = zipinfo.unified_diff + classdiff.details[0].unified_diff
assert expected_diff == found_diff
diff --git a/tests/comparators/test_directory.py b/tests/comparators/test_directory.py
index 159e875..c3c9071 100644
--- a/tests/comparators/test_directory.py
+++ b/tests/comparators/test_directory.py
@@ -24,8 +24,10 @@ import pytest
from diffoscope.presenters.text import output_text
from diffoscope.comparators.directory import compare_directories
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii2')
+from conftest import data
+
+TEST_FILE1_PATH = data('text_ascii1')
+TEST_FILE2_PATH = data('text_ascii2')
def test_no_differences():
difference = compare_directories(os.path.dirname(__file__), os.path.dirname(__file__))
@@ -55,7 +57,7 @@ def test_content(differences):
output_text(differences[0], print_func=print)
assert differences[0].source1 == 'dir'
assert differences[0].details[0].source1 == 'text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[0].details[0].unified_diff == expected_diff
def test_stat(differences):
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 1a263f7..2d47050 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 conftest import tool_missing
+from conftest import tool_missing, data
try:
import diffoscope.comparators.debian # noqa
@@ -35,8 +35,8 @@ try:
except ImportError:
miss_debian_module = True
-TEST_OBJ1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.o')
-TEST_OBJ2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.o')
+TEST_OBJ1_PATH = data('test1.o')
+TEST_OBJ2_PATH = data('test2.o')
@pytest.fixture
def obj1():
@@ -67,11 +67,11 @@ def test_obj_compare_non_existing(monkeypatch, obj1):
@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_diff(obj_differences):
assert len(obj_differences) == 1
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_obj_expected_diff')).read()
+ expected_diff = open(data('elf_obj_expected_diff')).read()
assert obj_differences[0].unified_diff == expected_diff
-TEST_LIB1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.a')
-TEST_LIB2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.a')
+TEST_LIB1_PATH = data('test1.a')
+TEST_LIB2_PATH = data('test2.a')
@pytest.fixture
def lib1():
@@ -96,10 +96,10 @@ def lib_differences(lib1, lib2):
def test_lib_differences(lib_differences):
assert len(lib_differences) == 2
assert lib_differences[0].source1 == 'file list'
- expected_metadata_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_lib_metadata_expected_diff')).read()
+ expected_metadata_diff = open(data('elf_lib_metadata_expected_diff')).read()
assert lib_differences[0].unified_diff == expected_metadata_diff
assert 'objdump' in lib_differences[1].source1
- expected_objdump_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_lib_objdump_expected_diff')).read()
+ expected_objdump_diff = open(data('elf_lib_objdump_expected_diff')).read()
assert lib_differences[1].unified_diff == expected_objdump_diff
@pytest.mark.skipif(tool_missing('readelf') or tool_missing('objdump'), reason='missing readelf')
@@ -109,8 +109,8 @@ def test_lib_compare_non_existing(monkeypatch, lib1):
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
-TEST_DBGSYM_DEB1_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/add/test-dbgsym_1_amd64.deb')
-TEST_DBGSYM_DEB2_PATH = os.path.join(os.path.dirname(__file__), '../data/dbgsym/mult/test-dbgsym_1_amd64.deb')
+TEST_DBGSYM_DEB1_PATH = data('dbgsym/add/test-dbgsym_1_amd64.deb')
+TEST_DBGSYM_DEB2_PATH = data('dbgsym/mult/test-dbgsym_1_amd64.deb')
@pytest.fixture
def dbgsym_dir1():
@@ -141,5 +141,5 @@ def test_differences_with_dbgsym(dbgsym_differences):
def test_original_gnu_debuglink(dbgsym_differences):
bin_details = dbgsym_differences.details[2].details[0].details[0]
assert '.gnu_debuglink' in bin_details.details[2].source1
- expected_gnu_debuglink = open(os.path.join(os.path.dirname(__file__), '../data/gnu_debuglink_expected_diff')).read()
+ expected_gnu_debuglink = open(data('gnu_debuglink_expected_diff')).read()
assert bin_details.details[2].unified_diff == expected_gnu_debuglink
diff --git a/tests/comparators/test_epub.py b/tests/comparators/test_epub.py
index 9dc9b3e..9526954 100644
--- a/tests/comparators/test_epub.py
+++ b/tests/comparators/test_epub.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.zip import ZipFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.epub')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.epub')
+TEST_FILE1_PATH = data('test1.epub')
+TEST_FILE2_PATH = data('test2.epub')
@pytest.fixture
def epub1():
@@ -59,7 +58,7 @@ def test_differences(differences):
assert differences[2].source2 == 'toc.ncx'
assert differences[3].source1 == 'ch001.xhtml'
assert differences[3].source2 == 'ch001.xhtml'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/epub_expected_diffs')).read()
+ expected_diff = open(data('epub_expected_diffs')).read()
assert expected_diff == "".join(map(lambda x: x.unified_diff, differences))
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
diff --git a/tests/comparators/test_fonts.py b/tests/comparators/test_fonts.py
index a420e4b..17a8ded 100644
--- a/tests/comparators/test_fonts.py
+++ b/tests/comparators/test_fonts.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.fonts import TtfFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/Samyak-Malayalam1.ttf')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/Samyak-Malayalam2.ttf')
+TEST_FILE1_PATH = data('Samyak-Malayalam1.ttf')
+TEST_FILE2_PATH = data('Samyak-Malayalam2.ttf')
@pytest.fixture
def ttf1():
@@ -51,7 +50,7 @@ def differences(ttf1, ttf2):
@pytest.mark.skipif(tool_missing('showttf'), reason='missing showttf')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ttf_expected_diff')).read()
+ expected_diff = open(data('ttf_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('showttf'), reason='missing showttf')
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index c6b36af..ad41fd3 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -18,14 +18,13 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.fsimage import FsImageFile
-from conftest import tool_missing
+from conftest import tool_missing, data
try:
import guestfs
@@ -33,8 +32,8 @@ try:
except ImportError:
miss_guestfs = True
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.ext4')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.ext4')
+TEST_FILE1_PATH = data('test1.ext4')
+TEST_FILE2_PATH = data('test2.ext4')
def guestfs_working():
if miss_guestfs:
@@ -83,7 +82,7 @@ def test_differences(differences):
assert tardiff.source2 == './date.txt'
assert encodingdiff.source1 == 'encoding'
assert encodingdiff.source2 == 'encoding'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ext4_expected_diffs'), encoding='utf-8').read()
+ expected_diff = open(data('ext4_expected_diffs'), encoding='utf-8').read()
found_diff = tarinfo.unified_diff + tardiff.unified_diff + encodingdiff.unified_diff
assert expected_diff == found_diff
diff --git a/tests/comparators/test_gettext.py b/tests/comparators/test_gettext.py
index 3f4129a..b399e61 100644
--- a/tests/comparators/test_gettext.py
+++ b/tests/comparators/test_gettext.py
@@ -19,17 +19,16 @@
import codecs
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.gettext import MoFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.mo')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.mo')
+TEST_FILE1_PATH = data('test1.mo')
+TEST_FILE2_PATH = data('test2.mo')
@pytest.fixture
def mo1():
@@ -52,21 +51,21 @@ def differences(mo1, mo2):
@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/mo_expected_diff')).read()
+ expected_diff = open(data('mo_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.fixture
def mo_no_charset():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/test_no_charset.mo')))
+ return specialize(FilesystemFile(data('test_no_charset.mo')))
@pytest.fixture
def mo_iso8859_1():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/test_iso8859-1.mo')))
+ return specialize(FilesystemFile(data('test_iso8859-1.mo')))
@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
def test_charsets(mo_no_charset, mo_iso8859_1):
difference = mo_no_charset.compare(mo_iso8859_1)
- expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/mo_charsets_expected_diff'), encoding='utf-8').read()
+ expected_diff = codecs.open(data('mo_charsets_expected_diff'), encoding='utf-8').read()
assert difference.details[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index 0cde843..8fe70a9 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-import os.path
import shutil
import pytest
@@ -26,8 +25,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.gzip import GzipFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.gz')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.gz')
+from conftest import data
+
+TEST_FILE1_PATH = data('test1.gz')
+TEST_FILE2_PATH = data('test2.gz')
@pytest.fixture
def gzip1():
@@ -51,7 +52,7 @@ def differences(gzip1, gzip2):
def test_metadata(differences):
assert differences[0].source1 == 'metadata'
assert differences[0].source2 == 'metadata'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/gzip_metadata_expected_diff')).read()
+ expected_diff = open(data('gzip_metadata_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
def test_content_source(differences):
@@ -70,7 +71,7 @@ def test_content_source_without_extension(tmpdir):
assert difference[1].source2 == 'test2-content'
def test_content_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
def test_compare_non_existing(monkeypatch, gzip1):
diff --git a/tests/comparators/test_icc.py b/tests/comparators/test_icc.py
index e770de9..080fc77 100644
--- a/tests/comparators/test_icc.py
+++ b/tests/comparators/test_icc.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.icc import IccFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.icc')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.icc')
+TEST_FILE1_PATH = data('test1.icc')
+TEST_FILE2_PATH = data('test2.icc')
@pytest.fixture
def icc1():
@@ -51,7 +50,7 @@ def differences(icc1, icc2):
@pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/icc_expected_diff')).read()
+ expected_diff = open(data('icc_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
diff --git a/tests/comparators/test_image.py b/tests/comparators/test_image.py
index 50b125f..c32dc36 100644
--- a/tests/comparators/test_image.py
+++ b/tests/comparators/test_image.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.image import ImageFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.jpg')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.jpg')
+TEST_FILE1_PATH = data('test1.jpg')
+TEST_FILE2_PATH = data('test2.jpg')
@pytest.fixture
def image1():
@@ -51,7 +50,7 @@ def differences(image1, image2):
@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/image_expected_diff')).read()
+ expected_diff = open(data('image_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index 0713c38..da0f3f1 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -18,15 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.ipk import IpkFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/base-files_157-r45695_ar71xx.ipk')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/base-files_157-r45918_ar71xx.ipk')
+from conftest import data
+
+TEST_FILE1_PATH = data('base-files_157-r45695_ar71xx.ipk')
+TEST_FILE2_PATH = data('base-files_157-r45918_ar71xx.ipk')
@pytest.fixture
def ipk1():
@@ -49,7 +50,7 @@ def differences(ipk1, ipk2):
def test_metadata(differences):
assert differences[0].source1 == 'metadata'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ipk_metadata_expected_diff')).read()
+ expected_diff = open(data('ipk_metadata_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
def test_compressed_files(differences):
diff --git a/tests/comparators/test_iso9660.py b/tests/comparators/test_iso9660.py
index 8a8b095..178e038 100644
--- a/tests/comparators/test_iso9660.py
+++ b/tests/comparators/test_iso9660.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.iso9660 import Iso9660File
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.iso')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.iso')
+TEST_FILE1_PATH = data('test1.iso')
+TEST_FILE2_PATH = data('test2.iso')
@pytest.fixture
def iso1():
@@ -51,25 +50,25 @@ def differences(iso1, iso2):
@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_content(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/iso9660_content_expected_diff')).read()
+ expected_diff = open(data('iso9660_content_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_rockridge(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/iso9660_rockridge_expected_diff')).read()
+ expected_diff = open(data('iso9660_rockridge_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_symlink(differences):
assert differences[3].comment == 'symlink'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
+ expected_diff = open(data('symlink_expected_diff')).read()
assert differences[3].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_compressed_files(differences):
assert differences[2].source1 == 'text'
assert differences[2].source2 == 'text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[2].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
diff --git a/tests/comparators/test_java.py b/tests/comparators/test_java.py
index 069e8e0..254b2b2 100644
--- a/tests/comparators/test_java.py
+++ b/tests/comparators/test_java.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.java import ClassFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/Test1.class')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/Test2.class')
+TEST_FILE1_PATH = data('Test1.class')
+TEST_FILE2_PATH = data('Test2.class')
@pytest.fixture
def class1():
@@ -51,7 +50,7 @@ def differences(class1, class2):
@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/class_expected_diff')).read()
+ expected_diff = open(data('class_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
diff --git a/tests/comparators/test_json.py b/tests/comparators/test_json.py
index e12aa34..80adaf9 100644
--- a/tests/comparators/test_json.py
+++ b/tests/comparators/test_json.py
@@ -17,15 +17,16 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-import os
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.json import JSONFile
from diffoscope.comparators.binary import FilesystemFile
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.json')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.json')
+from conftest import data
+
+TEST_FILE1_PATH = data('test1.json')
+TEST_FILE2_PATH = data('test2.json')
@pytest.fixture
def json1():
@@ -46,6 +47,6 @@ def differences(json1, json2):
return json1.compare(json2).details
def test_diff(differences):
- with open(os.path.join(os.path.dirname(__file__), '../data/json_expected_diff')) as f:
+ with open(data('json_expected_diff')) as f:
expected_diff = f.read()
assert differences[0].unified_diff == expected_diff
diff --git a/tests/comparators/test_macho.py b/tests/comparators/test_macho.py
index 2bd862a..bb23561 100644
--- a/tests/comparators/test_macho.py
+++ b/tests/comparators/test_macho.py
@@ -26,10 +26,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.macho import MachoFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_OBJ1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.macho')
-TEST_OBJ2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.macho')
+TEST_OBJ1_PATH = data('test1.macho')
+TEST_OBJ2_PATH = data('test2.macho')
@pytest.fixture
def obj1():
@@ -64,5 +64,5 @@ def test_diff(obj_differences):
for idx, diff in enumerate(obj_differences):
with open(os.path.join(os.path.dirname(__file__), '../data', l[idx]), 'w') as f:
print(diff.unified_diff, file=f)
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/macho_expected_diff')).read()
+ expected_diff = open(data('macho_expected_diff')).read()
assert obj_differences[0].unified_diff == expected_diff
diff --git a/tests/comparators/test_mono.py b/tests/comparators/test_mono.py
index db2d6ad..0afc1d0 100644
--- a/tests/comparators/test_mono.py
+++ b/tests/comparators/test_mono.py
@@ -18,22 +18,21 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.mono import MonoExeFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
# 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 = os.path.join(os.path.dirname(__file__), '../data/test1.exe')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.exe')
+TEST_FILE1_PATH = data('test1.exe')
+TEST_FILE2_PATH = data('test2.exe')
@pytest.fixture
def exe1():
@@ -56,7 +55,7 @@ def differences(exe1, exe2):
@pytest.mark.skipif(tool_missing('pedump'), reason='missing pedump')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pe_expected_diff')).read()
+ expected_diff = open(data('pe_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('pedump'), reason='missing pedump')
diff --git a/tests/comparators/test_pdf.py b/tests/comparators/test_pdf.py
index 659c41a..18c1463 100644
--- a/tests/comparators/test_pdf.py
+++ b/tests/comparators/test_pdf.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.pdf import PdfFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.pdf')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.pdf')
+TEST_FILE1_PATH = data('test1.pdf')
+TEST_FILE2_PATH = data('test2.pdf')
@pytest.fixture
def pdf1():
@@ -52,13 +51,13 @@ def differences(pdf1, pdf2):
@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
reason='missing pdftk or pdftotext')
def test_text_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pdf_text_expected_diff')).read()
+ expected_diff = open(data('pdf_text_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
reason='missing pdftk or pdftotext')
def test_internal_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pdf_internal_expected_diff')).read()
+ expected_diff = open(data('pdf_internal_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
diff --git a/tests/comparators/test_png.py b/tests/comparators/test_png.py
index 82bcdcd..4223cd7 100644
--- a/tests/comparators/test_png.py
+++ b/tests/comparators/test_png.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.png import PngFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.png')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.png')
+TEST_FILE1_PATH = data('test1.png')
+TEST_FILE2_PATH = data('test2.png')
@pytest.fixture
def png1():
@@ -51,7 +50,7 @@ def differences(png1, png2):
@pytest.mark.skipif(tool_missing('sng'), reason='missing sng')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/png_expected_diff')).read()
+ expected_diff = open(data('png_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('sng'), reason='missing sng')
diff --git a/tests/comparators/test_ppu.py b/tests/comparators/test_ppu.py
index 7149e33..13ff3e1 100644
--- a/tests/comparators/test_ppu.py
+++ b/tests/comparators/test_ppu.py
@@ -19,14 +19,13 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.ppu import PpuFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
# 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
@@ -34,8 +33,8 @@ from conftest import tool_missing
# 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 = os.path.join(os.path.dirname(__file__), '../data/test1.ppu')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.ppu')
+TEST_FILE1_PATH = data('test1.ppu')
+TEST_FILE2_PATH = data('test2.ppu')
@pytest.fixture
def file1():
@@ -60,7 +59,7 @@ def differences(file1, file2):
@pytest.mark.skipif(tool_missing('ppudump'), reason='missing ppudump')
def test_diff(differences):
print(differences[0].unified_diff)
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ppu_expected_diff')).read()
+ expected_diff = open(data('ppu_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('ppudump'), reason='missing ppudump')
diff --git a/tests/comparators/test_ps.py b/tests/comparators/test_ps.py
index 22a27fb..43cb910 100644
--- a/tests/comparators/test_ps.py
+++ b/tests/comparators/test_ps.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-import os.path
import pytest
from diffoscope.config import Config
@@ -25,10 +24,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.ps import PsFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.ps')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.ps')
+TEST_FILE1_PATH = data('test1.ps')
+TEST_FILE2_PATH = data('test2.ps')
@pytest.fixture
def ps1():
@@ -51,12 +50,12 @@ def differences(ps1, ps2):
@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_internal_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ps_internal_expected_diff')).read()
+ expected_diff = open(data('ps_internal_expected_diff')).read()
assert differences.unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_text_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ps_text_expected_diff')).read()
+ expected_diff = open(data('ps_text_expected_diff')).read()
assert differences.details[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
diff --git a/tests/comparators/test_rlib.py b/tests/comparators/test_rlib.py
index 58cf2b4..5aafaa0 100644
--- a/tests/comparators/test_rlib.py
+++ b/tests/comparators/test_rlib.py
@@ -19,7 +19,6 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
@@ -27,10 +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 conftest import tool_missing, tool_older_than
+from conftest import tool_missing, tool_older_than, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.rlib')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.rlib')
+TEST_FILE1_PATH = data('test1.rlib')
+TEST_FILE2_PATH = data('test2.rlib')
@pytest.fixture
def rlib1():
@@ -57,13 +56,13 @@ def test_num_items(differences):
def test_item0_armap(differences):
assert differences[0].source1 == 'nm -s {}'
assert differences[0].source2 == 'nm -s {}'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_armap_expected_diff')).read()
+ expected_diff = open(data('rlib_armap_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
def test_item1_elf(differences):
assert differences[1].source1 == 'alloc_system-d16b8f0e.0.o'
assert differences[1].source2 == 'alloc_system-d16b8f0e.0.o'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_elf_expected_diff')).read()
+ expected_diff = open(data('rlib_elf_expected_diff')).read()
assert differences[1].details[0].unified_diff == expected_diff
def test_item2_rust_metadata_bin(differences):
@@ -75,7 +74,7 @@ def test_item2_rust_metadata_bin(differences):
def test_item3_deflate_llvm_bitcode(differences):
assert differences[3].source1 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
assert differences[3].source2 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_llvm_dis_expected_diff')).read()
+ expected_diff = open(data('rlib_llvm_dis_expected_diff')).read()
actual_diff = differences[3].details[0].details[1].unified_diff
assert diff_ignore_line_numbers(actual_diff) == diff_ignore_line_numbers(expected_diff)
diff --git a/tests/comparators/test_rpm.py b/tests/comparators/test_rpm.py
index 84070dd..3fb7981 100644
--- a/tests/comparators/test_rpm.py
+++ b/tests/comparators/test_rpm.py
@@ -18,13 +18,12 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
try:
from diffoscope.comparators.rpm import RpmFile
@@ -33,8 +32,8 @@ except ImportError:
from diffoscope.comparators.rpm_fallback import RpmFile
miss_rpm_module = True
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.rpm')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.rpm')
+TEST_FILE1_PATH = data('test1.rpm')
+TEST_FILE2_PATH = data('test2.rpm')
@pytest.fixture
def rpm1():
@@ -60,7 +59,7 @@ def differences(rpm1, rpm2):
@pytest.mark.skipif(tool_missing('rpm2cpio'), reason='missing rpm2cpio')
def test_header(differences):
assert differences[0].source1 == 'header'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rpm_header_expected_diff')).read()
+ expected_diff = open(data('rpm_header_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
@@ -68,7 +67,7 @@ def test_header(differences):
def test_listing(differences):
assert differences[1].source1 == 'content'
assert differences[1].details[0].source1 == 'file list'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rpm_listing_expected_diff')).read()
+ expected_diff = open(data('rpm_listing_expected_diff')).read()
assert differences[1].details[0].unified_diff == expected_diff
@pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
@@ -76,7 +75,7 @@ def test_listing(differences):
def test_content(differences):
assert differences[1].source1 == 'content'
assert differences[1].details[1].source1 == './dir/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[1].details[1].unified_diff == expected_diff
@pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
diff --git a/tests/comparators/test_sqlite.py b/tests/comparators/test_sqlite.py
index c775e6d..cc13aac 100644
--- a/tests/comparators/test_sqlite.py
+++ b/tests/comparators/test_sqlite.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.sqlite import Sqlite3Database
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.sqlite3')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.sqlite3')
+TEST_FILE1_PATH = data('test1.sqlite3')
+TEST_FILE2_PATH = data('test2.sqlite3')
@pytest.fixture
def sqlite3db1():
@@ -51,7 +50,7 @@ def differences(sqlite3db1, sqlite3db2):
@pytest.mark.skipif(tool_missing('sqlite3'), reason='missing sqlite3')
def test_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/sqlite3_expected_diff')).read()
+ expected_diff = open(data('sqlite3_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('sqlite3'), reason='missing sqlite3')
diff --git a/tests/comparators/test_squashfs.py b/tests/comparators/test_squashfs.py
index 42913c5..70648d9 100644
--- a/tests/comparators/test_squashfs.py
+++ b/tests/comparators/test_squashfs.py
@@ -18,17 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
from diffoscope.comparators.squashfs import SquashfsFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.squashfs')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.squashfs')
+TEST_FILE1_PATH = data('test1.squashfs')
+TEST_FILE2_PATH = data('test2.squashfs')
@pytest.fixture
def squashfs1():
@@ -56,20 +55,20 @@ def differences(squashfs1, squashfs2):
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_superblock(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/squashfs_superblock_expected_diff')).read()
+ expected_diff = open(data('squashfs_superblock_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_symlink(differences):
assert differences[2].comment == 'symlink'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
+ expected_diff = open(data('symlink_expected_diff')).read()
assert differences[2].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_compressed_files(differences):
assert differences[3].source1 == '/text'
assert differences[3].source2 == '/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[3].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index 11dc88f..283c3e6 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -18,15 +18,16 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.tar import TarFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.tar')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.tar')
+from conftest import data
+
+TEST_FILE1_PATH = data('test1.tar')
+TEST_FILE2_PATH = data('test2.tar')
@pytest.fixture
def tar1():
@@ -48,20 +49,20 @@ def differences(tar1, tar2):
return tar1.compare(tar2).details
def test_listing(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/tar_listing_expected_diff')).read()
+ expected_diff = open(data('tar_listing_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
def test_symlinks(differences):
assert differences[2].source1 == 'dir/link'
assert differences[2].source2 == 'dir/link'
assert differences[2].comment == 'symlink'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
+ expected_diff = open(data('symlink_expected_diff')).read()
assert differences[2].unified_diff == expected_diff
def test_text_file(differences):
assert differences[1].source1 == 'dir/text'
assert differences[1].source2 == 'dir/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
def test_compare_non_existing(monkeypatch, tar1):
@@ -72,7 +73,7 @@ def test_compare_non_existing(monkeypatch, tar1):
@pytest.fixture
def no_permissions_tar():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/no-perms.tar')))
+ return specialize(FilesystemFile(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 b563811..f2cf394 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -19,19 +19,20 @@
import codecs
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from conftest import data
+
@pytest.fixture
def ascii1():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/text_ascii1')))
+ return specialize(FilesystemFile(data('text_ascii1')))
@pytest.fixture
def ascii2():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/text_ascii2')))
+ return specialize(FilesystemFile(data('text_ascii2')))
def test_no_differences(ascii1):
difference = ascii1.compare(ascii1)
@@ -40,37 +41,37 @@ def test_no_differences(ascii1):
def test_difference_in_ascii(ascii1, ascii2):
difference = ascii1.compare(ascii2)
assert difference is not None
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert difference.unified_diff == expected_diff
assert not difference.comments
assert len(difference.details) == 0
@pytest.fixture
def unicode1():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/text_unicode1')))
+ return specialize(FilesystemFile(data('text_unicode1')))
@pytest.fixture
def unicode2():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/text_unicode2')))
+ return specialize(FilesystemFile(data('text_unicode2')))
def test_difference_in_unicode(unicode1, unicode2):
difference = unicode1.compare(unicode2)
- expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_unicode_expected_diff'), encoding='utf-8').read()
+ expected_diff = codecs.open(data('text_unicode_expected_diff'), encoding='utf-8').read()
assert difference.unified_diff == expected_diff
@pytest.fixture
def iso8859():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/text_iso8859')))
+ return specialize(FilesystemFile(data('text_iso8859')))
def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
difference = iso8859.compare(unicode1)
- expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
+ expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
assert difference.unified_diff == expected_diff
def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
utf8_path = str(tmpdir.join('utf8'))
with open(utf8_path, 'wb') as f:
- f.write(codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))
+ f.write(codecs.open(data('text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))
utf8 = specialize(FilesystemFile(utf8_path))
difference = iso8859.compare(utf8)
assert difference.unified_diff is None
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index 9eb2354..36bb83a 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -19,7 +19,6 @@
import codecs
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.difference import Difference
@@ -27,7 +26,7 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.utils import Command
from diffoscope.comparators.binary import FilesystemFile
-from conftest import tool_missing
+from conftest import tool_missing, data
try:
import tlsh # noqa
@@ -38,20 +37,20 @@ except ImportError:
@pytest.fixture
def fuzzy_tar1():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy1.tar')))
+ return specialize(FilesystemFile(data('fuzzy1.tar')))
@pytest.fixture
def fuzzy_tar2():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy2.tar')))
+ return specialize(FilesystemFile(data('fuzzy2.tar')))
@pytest.fixture
def fuzzy_tar3():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy3.tar')))
+ return specialize(FilesystemFile(data('fuzzy3.tar')))
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
differences = fuzzy_tar1.compare(fuzzy_tar2).details
- expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
+ expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
assert differences[1].source1 == './matching'
assert differences[1].source2 == './fuzzy'
assert 'similar' in differences[1].comment
@@ -61,15 +60,15 @@ def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
def test_fuzzy_matching_only_once(fuzzy_tar1, fuzzy_tar3):
differences = fuzzy_tar1.compare(fuzzy_tar3).details
assert len(differences) == 2
- expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
+ expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
@pytest.fixture
def fuzzy_tar_in_tar1():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy-tar-in-tar1.tar')))
+ return specialize(FilesystemFile(data('fuzzy-tar-in-tar1.tar')))
@pytest.fixture
def fuzzy_tar_in_tar2():
- return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy-tar-in-tar2.tar')))
+ return specialize(FilesystemFile(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 239e4bc..b711df3 100644
--- a/tests/comparators/test_xz.py
+++ b/tests/comparators/test_xz.py
@@ -19,17 +19,16 @@
import shutil
import pytest
-import os.path
from diffoscope.config import Config
from diffoscope.comparators import specialize
from diffoscope.comparators.xz import XzFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.xz')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.xz')
+TEST_FILE1_PATH = data('test1.xz')
+TEST_FILE2_PATH = data('test2.xz')
@pytest.fixture
def xz1():
@@ -69,7 +68,7 @@ def test_content_source_without_extension(tmpdir):
@pytest.mark.skipif(tool_missing('xz'), reason='missing xz')
def test_content_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('xz'), reason='missing xz')
diff --git a/tests/comparators/test_zip.py b/tests/comparators/test_zip.py
index 2f9177d..04f858f 100644
--- a/tests/comparators/test_zip.py
+++ b/tests/comparators/test_zip.py
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-import os.path
import pytest
from diffoscope.config import Config
@@ -25,10 +24,10 @@ from diffoscope.comparators import specialize
from diffoscope.comparators.zip import ZipFile, MozillaZipFile
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from conftest import tool_missing
+from conftest import tool_missing, data
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.zip')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.zip')
+TEST_FILE1_PATH = data('test1.zip')
+TEST_FILE2_PATH = data('test2.zip')
@pytest.fixture
def zip1():
@@ -51,14 +50,14 @@ def differences(zip1, zip2):
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_metadata(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/zip_zipinfo_expected_diff')).read()
+ expected_diff = open(data('zip_zipinfo_expected_diff')).read()
assert differences[0].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_compressed_files(differences):
assert differences[1].source1 == 'dir/text'
assert differences[1].source2 == 'dir/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
@@ -68,8 +67,8 @@ def test_compare_non_existing(monkeypatch, zip1):
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
-TEST_MOZZIP1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.mozzip')
-TEST_MOZZIP2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.mozzip')
+TEST_MOZZIP1_PATH = data('test1.mozzip')
+TEST_MOZZIP2_PATH = data('test2.mozzip')
@pytest.fixture
def mozzip1():
@@ -92,7 +91,7 @@ def mozzip_differences(mozzip1, mozzip2):
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_mozzip_metadata(mozzip_differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/mozzip_zipinfo_expected_diff')).read()
+ expected_diff = open(data('mozzip_zipinfo_expected_diff')).read()
diff = mozzip_differences[0].unified_diff
assert (diff.replace(TEST_MOZZIP1_PATH, 'test1.mozzip')
.replace(TEST_MOZZIP2_PATH, 'test2.mozzip')) == expected_diff
@@ -101,7 +100,7 @@ def test_mozzip_metadata(mozzip_differences):
def test_mozzip_compressed_files(mozzip_differences):
assert mozzip_differences[1].source1 == 'dir/text'
assert mozzip_differences[1].source2 == 'dir/text'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
+ expected_diff = open(data('text_ascii_expected_diff')).read()
assert mozzip_differences[1].unified_diff == expected_diff
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list