Refactor iptctest.sh to iptc_test()
This commit is contained in:
@@ -589,3 +589,67 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42'''
|
||||
|
||||
BT.reportTest('iotest', out)
|
||||
|
||||
|
||||
def iptc_test(self):
|
||||
# Test driver for Iptc metadata
|
||||
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',
|
||||
'smiley1.jpg',
|
||||
'smiley2.jpg',
|
||||
'table.jpg',]
|
||||
|
||||
pass_count = 0
|
||||
fail_count = 0
|
||||
out = BT.Output()
|
||||
|
||||
out += '\n--- Read tests ---'
|
||||
for i in test_files:
|
||||
if BT.printTest(i):
|
||||
pass_count += 1
|
||||
else:
|
||||
fail_count += 1
|
||||
out += 'Failed: ' + i
|
||||
|
||||
out += '\n--- Remove tests ---'
|
||||
for i in test_files:
|
||||
if BT.removeTest(i):
|
||||
pass_count += 1
|
||||
else:
|
||||
fail_count += 1
|
||||
out += 'Failed: ' + i
|
||||
|
||||
out += '\n--- Add/Mod tests ---'
|
||||
for i in test_files:
|
||||
if BT.addModTest(i):
|
||||
pass_count += 1
|
||||
else:
|
||||
fail_count += 1
|
||||
out += 'Failed: ' + i
|
||||
|
||||
out += '\n--- Extended tests ---'
|
||||
for i in test_files:
|
||||
if BT.extendedTest(i):
|
||||
pass_count += 1
|
||||
else:
|
||||
fail_count += 1
|
||||
out += 'Failed: ' + i
|
||||
|
||||
out += '\n--------------------\n'
|
||||
out += '{} passed, {} failed\n'.format(pass_count, fail_count)
|
||||
if fail_count:
|
||||
raise RuntimeError(str(out) + '\n' + BT.log.to_str())
|
||||
|
||||
|
||||
@@ -450,3 +450,67 @@ def iptcTest(num, src, dst):
|
||||
execute('metacopy -ip {src_file} {test_file}', vars())
|
||||
return diffCheck(good_file, test_file, in_bytes=True)
|
||||
|
||||
|
||||
def printTest(filename):
|
||||
test_file = filename + '.iptst'
|
||||
src_file = os.path.join(Config.data_dir, filename)
|
||||
good_file = os.path.join(Config.data_dir, filename + '.ipgd')
|
||||
copyTestFile(filename, test_file)
|
||||
save(execute('iptcprint {src_file}', vars(), expected_returncodes=None, return_in_bytes=True) + b'\n',
|
||||
test_file)
|
||||
return diffCheck(good_file, test_file, in_bytes=True)
|
||||
|
||||
|
||||
def removeTest(filename):
|
||||
tmp = 'temp'
|
||||
test_file = filename + '.irtst'
|
||||
src_file = os.path.join(Config.data_dir, filename)
|
||||
good_file = os.path.join(Config.data_dir, filename + '.irgd')
|
||||
copyTestFile(filename, tmp)
|
||||
stdin = """
|
||||
r Iptc.Application2.Byline
|
||||
r Iptc.Application2.Caption
|
||||
r Iptc.Application2.Keywords
|
||||
r Iptc.Application2.Keywords
|
||||
r Iptc.Application2.Keywords
|
||||
r Iptc.Application2.CountryName
|
||||
""".lstrip('\n').encode()
|
||||
execute('iptctest {tmp}', vars(), stdin=stdin)
|
||||
save(execute('iptcprint {tmp}', vars(), expected_returncodes=None, return_in_bytes=True) + b'\n',
|
||||
test_file)
|
||||
return diffCheck(good_file, test_file, in_bytes=True)
|
||||
|
||||
|
||||
def addModTest(filename):
|
||||
tmp = 'temp'
|
||||
test_file = filename + '.iatst'
|
||||
src_file = os.path.join(Config.data_dir, filename)
|
||||
good_file = os.path.join(Config.data_dir, filename + '.iagd')
|
||||
copyTestFile(filename, tmp)
|
||||
stdin = """
|
||||
a Iptc.Application2.Headline The headline I am
|
||||
a Iptc.Application2.Keywords Yet another keyword
|
||||
m Iptc.Application2.DateCreated 2004-8-3
|
||||
a Iptc.Application2.Urgency 3
|
||||
m Iptc.Application2.SuppCategory "bla bla ba"
|
||||
a Iptc.Envelope.ModelVersion 2
|
||||
a Iptc.Envelope.TimeSent 14:41:0-05:00
|
||||
a Iptc.Application2.RasterizedCaption 230 42 34 2 90 84 23 146
|
||||
""".lstrip('\n').encode()
|
||||
execute('iptctest {tmp}', vars(), stdin=stdin)
|
||||
save(execute('iptcprint {tmp}', vars(), expected_returncodes=None, return_in_bytes=True) + b'\n',
|
||||
test_file)
|
||||
return diffCheck(good_file, test_file, in_bytes=True)
|
||||
|
||||
|
||||
def extendedTest(filename):
|
||||
tmp = 'temp'
|
||||
test_file = filename + '.ixtst'
|
||||
src_file = os.path.join(Config.data_dir, filename)
|
||||
good_file = os.path.join(Config.data_dir, filename + '.ixgd')
|
||||
copyTestFile(filename, tmp)
|
||||
stdin = cat(os.path.join(Config.data_dir, 'ext.dat'), return_in_bytes=False)
|
||||
execute('iptctest {tmp}', vars(), stdin=stdin)
|
||||
save(execute('iptcprint {tmp}', vars(), return_in_bytes=True) + b'\n',
|
||||
test_file)
|
||||
return diffCheck(good_file, test_file, in_bytes=True)
|
||||
|
||||
Reference in New Issue
Block a user