@@ -244,17 +244,28 @@ def _image_directories(func):
244
244
module_name = func .__module__
245
245
if module_name == '__main__' :
246
246
# FIXME: this won't work for nested packages in matplotlib.tests
247
- import warnings
248
247
warnings .warn ('test module run as script. guessing baseline image locations' )
249
248
script_name = sys .argv [0 ]
250
249
basedir = os .path .abspath (os .path .dirname (script_name ))
251
250
subdir = os .path .splitext (os .path .split (script_name )[1 ])[0 ]
252
251
else :
253
252
mods = module_name .split ('.' )
254
- assert mods .pop (0 ) == 'matplotlib'
253
+ mods .pop (0 ) # <- will be the name of the package being tested (in
254
+ # most cases "matplotlib")
255
255
assert mods .pop (0 ) == 'tests'
256
256
subdir = os .path .join (* mods )
257
- basedir = os .path .dirname (matplotlib .tests .__file__ )
257
+
258
+ import imp
259
+ def find_dotted_module (module_name , path = None ):
260
+ """A version of imp which can handle dots in the module name"""
261
+ res = None
262
+ for sub_mod in module_name .split ('.' ):
263
+ res = _ , path , _ = imp .find_module (sub_mod , path )
264
+ path = [path ]
265
+ return res
266
+
267
+ mod_file = find_dotted_module (func .__module__ )[1 ]
268
+ basedir = os .path .dirname (mod_file )
258
269
259
270
baseline_dir = os .path .join (basedir , 'baseline_images' , subdir )
260
271
result_dir = os .path .abspath (os .path .join ('result_images' , subdir ))
0 commit comments