Refactor imagetest.sh to test_image()

This commit is contained in:
LeoHsiao 2020-08-25 22:37:21 +08:00
parent b900cea6cf
commit cfaf4e6fa2
2 changed files with 95 additions and 7 deletions

View File

@ -502,6 +502,67 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
BT.reportTest('icc-test', out)
def test_image(self):
test_files = [
'table.jpg',
'smiley1.jpg',
'smiley2.jpg',]
erase_test_files = [
'glider.exv',
'iptc-noAPP13.jpg',
'iptc-psAPP13-noIPTC.jpg',
'iptc-psAPP13-noIPTC-psAPP13-wIPTC.jpg',
'iptc-psAPP13s-noIPTC-psAPP13s-wIPTC.jpg',
'iptc-psAPP13s-wIPTC-psAPP13s-noIPTC.jpg',
'iptc-psAPP13s-wIPTCs-psAPP13s-wIPTCs.jpg',
'iptc-psAPP13-wIPTC1-psAPP13-wIPTC2.jpg',
'iptc-psAPP13-wIPTCbeg.jpg',
'iptc-psAPP13-wIPTCempty.jpg',
'iptc-psAPP13-wIPTCempty-psAPP13-wIPTC.jpg',
'iptc-psAPP13-wIPTCend.jpg',
'iptc-psAPP13-wIPTCmid1-wIPTCempty-wIPTCmid2.jpg',
'iptc-psAPP13-wIPTCmid.jpg',
'iptc-psAPP13-wIPTC-psAPP13-noIPTC.jpg',]
pass_count = 0
fail_count = 0
out = BT.Output()
out += ''
out += 'Erase all tests'
for i in test_files + erase_test_files:
if BT.eraseTest(i):
pass_count += 1
else:
fail_count += 1
out += 'Failed: ' + i
out += ''
out += 'Copy all tests'
for num, src in enumerate(test_files, 1):
for dst in test_files:
if BT.copyTest(num, src, dst):
pass_count += 1
else:
fail_count += 1
out += 'Failed: {}'.format((num, src, dst))
out += ''
out += 'Copy iptc tests'
for num, src in enumerate(test_files, 1):
for dst in test_files:
if BT.iptcTest(num, src, dst):
pass_count += 1
else:
fail_count += 1
out += 'Failed: {}'.format((num, src, dst))
out += ''
out += '{} passed, {} failed'.format(pass_count, fail_count)
if fail_count:
raise RuntimeError('\n' + str(out))
# BT.reportTest('imagetest', out)
def test_io(self):
# Test driver for file i/o
test_files = ['table.jpg', 'smiley2.jpg', 'ext.dat']

View File

@ -50,6 +50,9 @@ class Log:
self.add('[ERROR] {}'.format(msg))
log = Log()
class Output:
"""
Simulate the stdout buffer.
@ -217,12 +220,6 @@ def copyTestFile(src, dest=''):
os.path.join(Conf.tmp_dir, dest))
def md5sum(filename):
""" Calculate the MD5 value of the file """
with open(filename, "rb") as f:
return hashlib.md5(f.read()).hexdigest()
def excute(cmd: str, vars_dict=dict(),
expected_returncodes=[0],
mix_stdout_and_stderr=True,
@ -281,6 +278,12 @@ def reportTest(testname, output: str, encoding=None):
raise RuntimeError('\n' + log.to_str())
def md5sum(filename):
""" Calculate the MD5 value of the file """
with open(filename, "rb") as f:
return hashlib.md5(f.read()).hexdigest()
def ioTest(filename):
src = os.path.join(Conf.data_dir, filename)
out1 = os.path.join(Conf.tmp_dir, '{}.1'.format(filename))
@ -308,4 +311,28 @@ class HttpServer:
self.process.terminate()
log = Log()
def eraseTest(filename):
test_file = filename + '.etst'
good_file = os.path.join(Conf.data_dir, filename + '.egd')
copyTestFile(filename, test_file)
excute('metacopy {test_file} {test_file}', vars())
return md5sum(test_file) == md5sum(good_file)
def copyTest(num, src, dst):
test_file = '{}.c{}tst'.format(dst, num)
good_src = os.path.join(Conf.data_dir, src)
good_dst = os.path.join(Conf.data_dir, '{}.c{}gd'.format(dst, num))
copyTestFile(dst, test_file)
excute('metacopy -a {good_src} {test_file}', vars())
return md5sum(test_file) == md5sum(good_dst)
def iptcTest(num, src, dst):
test_file = '{}.i{}tst'.format(dst, num)
good_src = os.path.join(Conf.data_dir, src)
good_dst = os.path.join(Conf.data_dir, '{}.i{}gd'.format(dst, num))
copyTestFile(dst, test_file)
excute('metacopy -ip {good_src} {test_file}', vars())
return md5sum(test_file) == md5sum(good_dst)