1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Reiner Herrmann <reiner@reiner-h.de>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import pytest
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
img1 = load_fixture('test1.ext4')
img2 = load_fixture('test2.ext4')
def guestfs_working():
try:
import guestfs
except ImportError:
return False
g = guestfs.GuestFS (python_return_dict=True)
g.add_drive_opts("/dev/null", format="raw", readonly=1)
try:
g.launch()
except RuntimeError:
return False
return True
def test_identification(img1):
assert isinstance(img1, FsImageFile)
@pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_no_differences(img1):
difference = img1.compare(img1)
assert difference is None
@pytest.fixture
def differences(img1, img2):
return img1.compare(img2).details
@pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_differences(differences):
assert differences[0].source1 == 'test1.ext4.tar'
tarinfo = differences[0].details[0]
tardiff = differences[0].details[1]
encodingdiff = tardiff.details[0]
assert tarinfo.source1 == 'file list'
assert tarinfo.source2 == 'file list'
assert tardiff.source1 == './date.txt'
assert tardiff.source2 == './date.txt'
assert encodingdiff.source1 == 'encoding'
assert encodingdiff.source2 == 'encoding'
expected_diff = get_data('ext4_expected_diffs')
found_diff = tarinfo.unified_diff + tardiff.unified_diff + encodingdiff.unified_diff
assert expected_diff == found_diff
@pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_compare_non_existing(monkeypatch, img1):
monkeypatch.setattr(Config(), 'new_file', True)
difference = img1.compare(MissingFile('/nonexisting', img1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
|