Merge lp:~kenseehart/phatch/PGM_bugfix_472978_test into lp:phatch

Proposed by Ken Seehart
Status: Merged
Merged at revision: not available
Proposed branch: lp:~kenseehart/phatch/PGM_bugfix_472978_test
Merge into: lp:phatch
Diff against target: 79 lines (+44/-0)
2 files modified
tests/run_acceptance_test (+9/-0)
tests/test_suite/utils.py (+35/-0)
To merge this branch: bzr merge lp:~kenseehart/phatch/PGM_bugfix_472978_test
Reviewer Review Type Date Requested Status
Stani Needs Fixing
Nadia Alramli Pending
Review via email: mp+19929@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ken Seehart (kenseehart) wrote :

Added verification that the file extension is appropriate for the format of the file content, on all output files.

1557. By Ken Seehart <ken@ken-laptop>

pep8

Revision history for this message
Nadia Alramli (nadiana) wrote :

Looks good to me, handing this to Stani to do the merge.

Revision history for this message
Stani (stani) wrote :

It is a good addition to the test suite, so thanks a lot!

I have only the following request:
verify_image_type should move to phatch/lib/imtools

Please push your branch when done and I'll merge it.

review: Needs Fixing
Revision history for this message
Stani (stani) wrote :

Also please fix these PEP8 issues:

PGM_bugfix_472978_test/tests$ ./run_pep8_test.py
../tests/run_acceptance_test.py:252:1: W291 trailing whitespace

^
1
../tests/test_suite/utils.py:93:24: E261 at least two spaces before inline comment
        'pgm': ['ppm'], # PIL bug: PIL saves greyscale PPM as PGM
                       ^
../tests/test_suite/utils.py:110:11: E225 missing whitespace around operator
    if ext!=t and ext not in altext.get(t, []):
          ^
2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/run_acceptance_test'
2--- tests/run_acceptance_test 2010-02-23 15:14:31 +0000
3+++ tests/run_acceptance_test 2010-02-23 18:37:21 +0000
4@@ -134,6 +134,7 @@
5 default='',
6 help='Command line options to pass to phatch'
7 )
8+
9 options, args = parser.parse_args()
10 if not options.no_execute and not os.path.exists(options.input):
11 logging.error(
12@@ -235,6 +236,14 @@
13 report.info('Errors:\n\t%s' % '\n\t'.join(errors))
14 else:
15 logging.info('No errors')
16+
17+ for image in os.listdir(options.output):
18+ path1 = os.path.join(options.output, image)
19+ if os.path.exists(path1):
20+ ok, reason = utils.verify_image_type(path1)
21+ if not ok:
22+ report.info('Format/Ext Mismatch: %s' % reason)
23+
24 if options.compare:
25 utils.create_path(config.OUT_DIFF)
26 new = []
27
28=== modified file 'tests/test_suite/utils.py'
29--- tests/test_suite/utils.py 2010-02-23 15:20:48 +0000
30+++ tests/test_suite/utils.py 2010-02-23 18:37:21 +0000
31@@ -23,6 +23,8 @@
32 import filecmp
33 import os
34 import shutil
35+import imghdr
36+import Image
37
38
39 def system_path(path):
40@@ -79,6 +81,39 @@
41 return name
42
43
44+def verify_image_type(name):
45+ """Check that file extension matches the content
46+ if successful: ok = True, reason = None
47+ else: ok = False, reason = string describing error
48+ """
49+ altext = {
50+ 'jpeg': ['jpg', 'jpe'],
51+ 'tiff': ['tif'],
52+ 'eps': ['ps'],
53+ 'pgm': ['ppm'], # PIL bug: PIL saves greyscale PPM as PGM
54+ 'pbm': ['ppm'], # PIL bug: PIL saves black and white PPM as PBM
55+ }
56+
57+ # first use opinion of imghdr (python standard library)
58+ t = imghdr.what(name)
59+ ext = os.path.splitext(name)[1][1:]
60+
61+ if t is None:
62+ # Get PILs opinion
63+ # Known types support by PIL but not imghdr: im, pcx, jpeg(CMYK)
64+ try:
65+ im = Image.open(name)
66+ t = im.format.lower()
67+ except IOError:
68+ return False, 'Content type not recognized in %s' % name
69+
70+ if ext!=t and ext not in altext.get(t, []):
71+ return (False,
72+ 'Content type %s does not match extension in %s' % (t, name))
73+ else:
74+ return True, None
75+
76+
77 def compare(file1, file2):
78 """Compare two files"""
79 return filecmp.cmp(file1, file2)

Subscribers

People subscribed via source and target branches

to status/vote changes: