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
=== modified file 'tests/run_acceptance_test'
--- tests/run_acceptance_test 2010-02-23 15:14:31 +0000
+++ tests/run_acceptance_test 2010-02-23 18:37:21 +0000
@@ -134,6 +134,7 @@
134 default='',134 default='',
135 help='Command line options to pass to phatch'135 help='Command line options to pass to phatch'
136 )136 )
137
137 options, args = parser.parse_args()138 options, args = parser.parse_args()
138 if not options.no_execute and not os.path.exists(options.input):139 if not options.no_execute and not os.path.exists(options.input):
139 logging.error(140 logging.error(
@@ -235,6 +236,14 @@
235 report.info('Errors:\n\t%s' % '\n\t'.join(errors))236 report.info('Errors:\n\t%s' % '\n\t'.join(errors))
236 else:237 else:
237 logging.info('No errors')238 logging.info('No errors')
239
240 for image in os.listdir(options.output):
241 path1 = os.path.join(options.output, image)
242 if os.path.exists(path1):
243 ok, reason = utils.verify_image_type(path1)
244 if not ok:
245 report.info('Format/Ext Mismatch: %s' % reason)
246
238 if options.compare:247 if options.compare:
239 utils.create_path(config.OUT_DIFF)248 utils.create_path(config.OUT_DIFF)
240 new = []249 new = []
241250
=== modified file 'tests/test_suite/utils.py'
--- tests/test_suite/utils.py 2010-02-23 15:20:48 +0000
+++ tests/test_suite/utils.py 2010-02-23 18:37:21 +0000
@@ -23,6 +23,8 @@
23import filecmp23import filecmp
24import os24import os
25import shutil25import shutil
26import imghdr
27import Image
2628
2729
28def system_path(path):30def system_path(path):
@@ -79,6 +81,39 @@
79 return name81 return name
8082
8183
84def verify_image_type(name):
85 """Check that file extension matches the content
86 if successful: ok = True, reason = None
87 else: ok = False, reason = string describing error
88 """
89 altext = {
90 'jpeg': ['jpg', 'jpe'],
91 'tiff': ['tif'],
92 'eps': ['ps'],
93 'pgm': ['ppm'], # PIL bug: PIL saves greyscale PPM as PGM
94 'pbm': ['ppm'], # PIL bug: PIL saves black and white PPM as PBM
95 }
96
97 # first use opinion of imghdr (python standard library)
98 t = imghdr.what(name)
99 ext = os.path.splitext(name)[1][1:]
100
101 if t is None:
102 # Get PILs opinion
103 # Known types support by PIL but not imghdr: im, pcx, jpeg(CMYK)
104 try:
105 im = Image.open(name)
106 t = im.format.lower()
107 except IOError:
108 return False, 'Content type not recognized in %s' % name
109
110 if ext!=t and ext not in altext.get(t, []):
111 return (False,
112 'Content type %s does not match extension in %s' % (t, name))
113 else:
114 return True, None
115
116
82def compare(file1, file2):117def compare(file1, file2):
83 """Compare two files"""118 """Compare two files"""
84 return filecmp.cmp(file1, file2)119 return filecmp.cmp(file1, file2)

Subscribers

People subscribed via source and target branches

to status/vote changes: