1
from phablet.diff import ImageDiff
4
from io import StringIO
9
class DiffTests(unittest.TestCase):
11
fd, source_tarball_path = tempfile.mkstemp()
13
fd, target_tarball_path = tempfile.mkstemp()
16
source_tarball = tarfile.open(source_tarball_path, "w")
17
target_tarball = tarfile.open(target_tarball_path, "w")
27
c_dir = tarfile.TarInfo()
29
c_dir.type = tarfile.DIRTYPE
36
d_source = tarfile.TarInfo()
41
d_target = tarfile.TarInfo()
46
source_tarball.addfile(a, StringIO(u"test"))
47
source_tarball.addfile(b, StringIO(u"test"))
48
source_tarball.addfile(c_dir, StringIO(u"test"))
49
source_tarball.addfile(d_source, StringIO(u"test-abc"))
51
target_tarball.addfile(a, StringIO(u"test"))
52
target_tarball.addfile(c_dir, StringIO(u"test"))
53
target_tarball.addfile(c, StringIO(u"test"))
54
target_tarball.addfile(d_target, StringIO(u"test-def"))
56
source_tarball.close()
57
target_tarball.close()
59
self.imagediff = ImageDiff(source_tarball_path, target_tarball_path)
60
self.source_tarball_path = source_tarball_path
61
self.target_tarball_path = target_tarball_path
64
# os.remove(self.source_tarball_path)
65
# os.remove(self.target_tarball_path)
68
def test_content(self):
69
content_set, content_dict = self.imagediff.scan_content("source")
70
self.assertEquals(sorted(content_dict.keys()),
71
['a', 'b', 'c', 'c/d'])
73
content_set, content_dict = self.imagediff.scan_content("target")
74
self.assertEquals(sorted(content_dict.keys()),
75
['a', 'c', 'c/c', 'c/d'])
77
def test_content_invalid_image(self):
78
self.assertRaises(KeyError, self.imagediff.scan_content, "invalid")
80
def test_compare(self):
81
self.imagediff.compare_images()
82
self.imagediff.print_changes()