@@ -244,17 +244,28 @@ def _image_directories(func):
244244 module_name = func .__module__
245245 if module_name == '__main__' :
246246 # FIXME: this won't work for nested packages in matplotlib.tests
247- import warnings
248247 warnings .warn ('test module run as script. guessing baseline image locations' )
249248 script_name = sys .argv [0 ]
250249 basedir = os .path .abspath (os .path .dirname (script_name ))
251250 subdir = os .path .splitext (os .path .split (script_name )[1 ])[0 ]
252251 else :
253252 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")
255255 assert mods .pop (0 ) == 'tests'
256256 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 )
258269
259270 baseline_dir = os .path .join (basedir , 'baseline_images' , subdir )
260271 result_dir = os .path .abspath (os .path .join ('result_images' , subdir ))
0 commit comments