Commit 761323b7 authored by Ximin Luo's avatar Ximin Luo

Refactor: move tests/comparators/utils up one directory

parent 9edbd007
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.apk import ApkFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
apk1 = load_fixture('test1.apk')
apk2 = load_fixture('test2.apk')
......
......@@ -19,7 +19,7 @@
import pytest
from utils.data import load_fixture
from ..utils.data import load_fixture
archive1 = load_fixture('archive1.tar')
......
......@@ -32,8 +32,8 @@ from diffoscope.comparators.utils.file import File
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.utils.compare import Xxd
from utils.data import data, init_fixture, get_data, normalize_zeros
from utils.tools import skip_unless_tools_exist
from ..utils.data import data, init_fixture, get_data, normalize_zeros
from ..utils.tools import skip_unless_tools_exist
TEST_FILE1_PATH = data('binary1')
......
......@@ -24,9 +24,9 @@ from diffoscope.comparators.bzip2 import Bzip2File
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
bzip1 = load_fixture('test1.bz2')
......
......@@ -25,9 +25,9 @@ from diffoscope.comparators.cbfs import CbfsFile
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import data, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
TEST_FILE1_PATH = data('text_ascii1')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.cpio import CpioFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
cpio1 = load_fixture('test1.cpio')
......
......@@ -27,7 +27,7 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data
from ..utils.data import load_fixture, get_data
deb1 = load_fixture('test1.deb')
......
......@@ -26,10 +26,10 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, get_data
from utils.tools import skip_unless_module_exists
from ..utils.data import data, get_data
from ..utils.tools import skip_unless_module_exists
from utils.nonexisting import assert_non_existing
from ..utils.nonexisting import assert_non_existing
try:
from diffoscope.comparators.debian import DotChangesFile, DotDscFile, \
......
......@@ -23,8 +23,8 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.device import Device
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data, normalize_zeros
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data, normalize_zeros
from ..utils.tools import skip_unless_tools_exist
text_ascii1 = load_fixture('text_ascii1')
......
......@@ -24,10 +24,10 @@ from diffoscope.config import Config
from diffoscope.comparators.dex import DexFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from test_java import javap_version
from .test_java import javap_version
dex1 = load_fixture('test1.dex')
......
......@@ -26,7 +26,7 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.directory import compare_directories
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, get_data
from ..utils.data import data, get_data
TEST_FILE1_PATH = data('text_ascii1')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.docx import DocxFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
docx1 = load_fixture('test1.docx')
docx2 = load_fixture('test2.docx')
......
......@@ -25,8 +25,8 @@ from diffoscope.config import Config
from diffoscope.comparators.dtb import DeviceTreeFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
# Generated by: dtc --in-format=dts --out-format=dtb --out=devicetree1.dtb devicetree1.dts
dtb1 = load_fixture('devicetree1.dtb')
......
......@@ -27,8 +27,8 @@ from diffoscope.comparators.directory import FilesystemDirectory
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, load_fixture, get_data
from utils.tools import skip_unless_tools_exist, \
from ..utils.data import data, load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, \
skip_if_binutils_does_not_support_x86, skip_unless_module_exists
obj1 = load_fixture('test1.o')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.zip import ZipFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
epub1 = load_fixture('test1.epub')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.fonts import TtfFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
ttf1 = load_fixture('Samyak-Malayalam1.ttf')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.fsimage import FsImageFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_module_exists
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_module_exists
img1 = load_fixture('test1.ext4')
img2 = load_fixture('test2.ext4')
......
......@@ -24,8 +24,8 @@ from diffoscope.config import Config
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.gettext import MoFile
from utils.data import data, load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import data, load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
mo1 = load_fixture('test1.mo')
......
......@@ -22,9 +22,9 @@ import pytest
from diffoscope.comparators.gif import GifFile
from diffoscope.config import Config
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
gif1 = load_fixture('test1.gif')
gif2 = load_fixture('test2.gif')
......
......@@ -21,7 +21,7 @@ import pytest
from diffoscope.comparators.git import GitIndexFile
from utils.data import get_data, load_fixture
from ..utils.data import get_data, load_fixture
git1 = load_fixture('test1.git-index')
......
......@@ -26,7 +26,7 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data
from ..utils.data import load_fixture, get_data
gzip1 = load_fixture('test1.gz')
......
......@@ -22,8 +22,8 @@ import pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.haskell import HiFile
from utils.data import get_data, load_fixture
from utils.tools import skip_unless_tools_exist
from ..utils.data import get_data, load_fixture
from ..utils.tools import skip_unless_tools_exist
haskell1 = load_fixture('test1.hi')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.icc import IccFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
icc1 = load_fixture('test1.icc')
......
......@@ -22,9 +22,9 @@ import pytest
from diffoscope.comparators.image import ICOImageFile
from diffoscope.config import Config
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from test_jpeg_image import identify_version
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from .test_jpeg_image import identify_version
image1 = load_fixture('test1.ico')
......
......@@ -23,7 +23,7 @@ from diffoscope.config import Config
from diffoscope.comparators.ipk import IpkFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from ..utils.data import load_fixture, get_data
ipk1 = load_fixture('base-files_157-r45695_ar71xx.ipk')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.missing_file import MissingFile
from diffoscope.comparators.iso9660 import Iso9660File
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
iso1 = load_fixture('test1.iso')
......
......@@ -24,8 +24,8 @@ from diffoscope.config import Config
from diffoscope.comparators.java import ClassFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
class1 = load_fixture('Test1.class')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.javascript import JavaScriptFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
javascript1 = load_fixture('test1.js')
......
......@@ -24,8 +24,8 @@ from diffoscope.config import Config
from diffoscope.comparators.image import JPEGImageFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
image1 = load_fixture('test1.jpg')
......
......@@ -21,8 +21,8 @@ import pytest
from diffoscope.comparators.json import JSONFile
from utils.data import load_fixture, get_data
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.nonexisting import assert_non_existing
json1 = load_fixture('test1.json')
......
......@@ -25,8 +25,8 @@ from diffoscope.config import Config
from diffoscope.comparators.macho import MachoFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
obj1 = load_fixture('test1.macho')
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.mono import MonoExeFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
# these were generated with:
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.odt import OdtFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
odt1 = load_fixture('test1.odt')
odt2 = load_fixture('test2.odt')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.ogg import OggFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
ogg1 = load_fixture('test1.ogg')
ogg2 = load_fixture('test2.ogg')
......
......@@ -24,8 +24,8 @@ from diffoscope.config import Config
from diffoscope.comparators.openssh import PublicKeyFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
# Generated by: ssh-keygen -t dsa -C "Test1"
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.pcap import PcapFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
pcap1 = load_fixture('test1.pcap')
pcap2 = load_fixture('test2.pcap')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.pdf import PdfFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
pdf1 = load_fixture('test1.pdf')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.pgp import PgpFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
pgp1 = load_fixture('test1.pgp')
pgp2 = load_fixture('test2.pgp')
......
......@@ -22,9 +22,9 @@ import pytest
from diffoscope.comparators.png import PngFile
from diffoscope.config import Config
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
png1 = load_fixture('test1.png')
......
......@@ -23,9 +23,9 @@ import subprocess
from diffoscope.comparators.ppu import PpuFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.nonexisting import assert_non_existing
# These test files were taken from two different builds of the Debian package
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.ps import PsFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
ps1 = load_fixture('test1.ps')
......
......@@ -21,10 +21,10 @@ import pytest
from diffoscope.comparators.gzip import GzipFile
from utils import diff_ignore_line_numbers
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils import diff_ignore_line_numbers
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
file1 = load_fixture('test1.rdx')
......
......@@ -23,11 +23,11 @@ import subprocess
from diffoscope.comparators.ar import ArFile
from utils import diff_ignore_line_numbers
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least, \
from ..utils import diff_ignore_line_numbers
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least, \
skip_if_binutils_does_not_support_x86
from utils.nonexisting import assert_non_existing
from ..utils.nonexisting import assert_non_existing
......
......@@ -23,9 +23,9 @@ from diffoscope.comparators import ComparatorManager
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, data, get_data, normalize_zeros
from utils.tools import skip_unless_tools_exist, skip_unless_module_exists
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, data, get_data, normalize_zeros
from ..utils.tools import skip_unless_tools_exist, skip_unless_module_exists
from ..utils.nonexisting import assert_non_existing
try:
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.sqlite import Sqlite3Database
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
sqlite3db1 = load_fixture('test1.sqlite3')
......
......@@ -22,9 +22,9 @@ import subprocess
from diffoscope.comparators.squashfs import SquashfsFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.nonexisting import assert_non_existing
def unsquashfs_version():
......
......@@ -22,7 +22,7 @@ import os
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import get_data
from ..utils.data import get_data
def test_destination(tmpdir):
......
......@@ -23,8 +23,8 @@ from diffoscope.config import Config
from diffoscope.comparators.tar import TarFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.nonexisting import assert_non_existing
tar1 = load_fixture('test1.tar')
......
......@@ -22,8 +22,8 @@ import codecs
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, load_fixture, get_data
from utils.nonexisting import assert_non_existing
from ..utils.data import data, load_fixture, get_data
from ..utils.nonexisting import assert_non_existing
ascii1 = load_fixture('text_ascii1')
......
......@@ -24,8 +24,8 @@ from diffoscope.config import Config
from diffoscope.difference import Difference
from diffoscope.comparators.utils.command import Command
from utils.data import data, load_fixture
from utils.tools import tools_missing, skip_unless_tools_exist, \
from ..utils.data import data, load_fixture
from ..utils.tools import tools_missing, skip_unless_tools_exist, \
skip_unless_module_exists
......
......@@ -24,9 +24,9 @@ from diffoscope.comparators.xz import XzFile
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
xz1 = load_fixture('test1.xz')
xz2 = load_fixture('test2.xz')
......
......@@ -21,9 +21,9 @@ import pytest
from diffoscope.comparators.zip import ZipFile, MozillaZipFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
zip1 = load_fixture('test1.zip')
......
......@@ -23,48 +23,30 @@ import pytest
from diffoscope.main import main
from .utils.data import cwd_data, get_data
re_html = re.compile(r'.*<body(?P<body>.*)<div class="footer">', re.MULTILINE | re.DOTALL)
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
def run(capsys, *args):
with pytest.raises(SystemExit) as exc:
prev = os.getcwd()
os.chdir(DATA_DIR)
try:
main(args + ('test1.tar', 'test2.tar'))
finally:
os.chdir(prev)
with pytest.raises(SystemExit) as exc, cwd_data():
main(args + ('test1.tar', 'test2.tar'))
out, err = capsys.readouterr()
assert err == ''
assert exc.value.code == 1
return out
def run_images(capsys, *args):
with pytest.raises(SystemExit) as exc:
prev = os.getcwd()
os.chdir(DATA_DIR)
try:
main(args + ('test1.png', 'test2.png'))
finally:
os.chdir(prev)
with pytest.raises(SystemExit) as exc, cwd_data():
main(args + ('test1.png', 'test2.png'))
out, err = capsys.readouterr()
assert err == ''
assert exc.value.code == 1
return out
def data(filename):
with open(os.path.join(DATA_DIR, filename), encoding='utf-8') as f:
return f.read()
def extract_body(val):
"""