|
3 | 3 | """ |
4 | 4 | #======================================================================= |
5 | 5 |
|
| 6 | +import matplotlib |
6 | 7 | import math |
7 | 8 | import operator |
8 | 9 | import os |
9 | 10 | import numpy as np |
10 | 11 | import shutil |
11 | 12 | import subprocess |
| 13 | +import sys |
12 | 14 |
|
13 | 15 | #======================================================================= |
14 | 16 |
|
15 | 17 | __all__ = [ |
16 | 18 | 'compare_float', |
17 | 19 | 'compare_images', |
| 20 | + 'comparable_formats', |
18 | 21 | ] |
19 | 22 |
|
20 | 23 | #----------------------------------------------------------------------- |
@@ -77,17 +80,32 @@ def compare_float( expected, actual, relTol = None, absTol = None ): |
77 | 80 | # A dictionary that maps filename extensions to functions that map |
78 | 81 | # parameters old and new to a list that can be passed to Popen to |
79 | 82 | # convert files with that extension to png format. |
80 | | -converter = { 'pdf': lambda old, new: \ |
81 | | - ['gs', '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH', |
82 | | - '-sOutputFile=' + new, old], |
83 | | - } |
| 83 | +converter = { } |
| 84 | + |
| 85 | +if matplotlib.checkdep_ghostscript() is not None: |
| 86 | + # FIXME: make checkdep_ghostscript return the command |
| 87 | + if sys.platform == 'win32': |
| 88 | + gs = 'gswin32c' |
| 89 | + else: |
| 90 | + gs = 'gs' |
| 91 | + cmd = lambda old, new: \ |
| 92 | + [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH', |
| 93 | + '-sOutputFile=' + new, old] |
| 94 | + converter['pdf'] = cmd |
| 95 | + converter['eps'] = cmd |
| 96 | + |
| 97 | +def comparable_formats(): |
| 98 | + '''Returns the list of file formats that compare_images can compare |
| 99 | + on this system.''' |
| 100 | + return ['png'] + converter.keys() |
| 101 | + |
84 | 102 | def convert(filename): |
85 | 103 | '''Convert the named file into a png file. |
86 | 104 | Returns the name of the created file. |
87 | 105 | ''' |
88 | 106 | base, extension = filename.rsplit('.', 1) |
89 | 107 | if extension not in converter: |
90 | | - raise KeyError, "Don't know how to convert %s files to png" % extension |
| 108 | + raise NotImplementedError, "Don't know how to convert %s files to png" % extension |
91 | 109 | newname = base + '_' + extension + '.png' |
92 | 110 | cmd = converter[extension](filename, newname) |
93 | 111 | pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
0 commit comments