|
22 | 22 | import collections |
23 | 23 | import functools |
24 | 24 | import os |
| 25 | +import sys |
25 | 26 |
|
26 | 27 | # Internal dependencies. |
27 | 28 | from dm_control import mujoco |
@@ -194,17 +195,19 @@ def decorated_method(*args, **kwargs): |
194 | 195 | try: |
195 | 196 | test_method(*args, **kwargs) |
196 | 197 | except ImagesNotClose as e: |
| 198 | + _, _, tb = sys.exc_info() |
| 199 | + if not os.path.exists(output_dir): |
| 200 | + os.makedirs(output_dir) |
197 | 201 | difference = e.actual.astype(np.double) - e.expected |
198 | 202 | difference = (0.5 * (difference + 255)).astype(np.uint8) |
199 | | - _save_pixels(e.expected, |
200 | | - os.path.join(output_dir, |
201 | | - '{}-expected.png'.format(method_name))) |
202 | | - _save_pixels(e.actual, |
203 | | - os.path.join(output_dir, |
204 | | - '{}-actual.png'.format(method_name))) |
205 | | - _save_pixels(difference, |
206 | | - os.path.join(output_dir, |
207 | | - '{}-difference.png'.format(method_name))) |
208 | | - raise # Reraise the exception with the original traceback. |
| 203 | + base_name = os.path.join(output_dir, method_name) |
| 204 | + _save_pixels(e.expected, base_name + '-expected.png') |
| 205 | + _save_pixels(e.actual, base_name + '-actual.png') |
| 206 | + _save_pixels(difference, base_name + '-difference.png') |
| 207 | + msg = ('{}. Debugging images saved to ' |
| 208 | + '{}-{{expected,actual,difference}}.png.'.format(e, base_name)) |
| 209 | + new_e = ImagesNotClose(msg, expected=e.expected, actual=e.actual) |
| 210 | + # Reraise the exception with the original traceback. |
| 211 | + six.reraise(ImagesNotClose, new_e, tb) |
209 | 212 | return decorated_method |
210 | 213 | return decorator |
0 commit comments