Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c60d5c

Browse files
committed
Beginnings of a capability to test the pdf backend.
svn path=/trunk/matplotlib/; revision=7830
1 parentea1b2d7 commit8c60d5c

36 files changed

+87
-36
lines changed

‎CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2009-09-27 Beginnings of a capability to test the pdf backend. - JKS
2+
13
2009-09-27 Add a savefig.extension rcparam to control the default
24
filename extension used by savefig. - JKS
35

‎lib/matplotlib/testing/compare.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
importos
99
importnumpyasnp
1010
importshutil
11+
importsubprocess
1112

1213
#=======================================================================
1314

@@ -73,6 +74,33 @@ def compare_float( expected, actual, relTol = None, absTol = None ):
7374
returnNone
7475

7576
#-----------------------------------------------------------------------
77+
# A dictionary that maps filename extensions to functions that map
78+
# parameters old and new to a list that can be passed to Popen to
79+
# convert files with that extension to png format.
80+
converter= {'pdf':lambdaold,new: \
81+
['gs','-q','-sDEVICE=png16m','-dNOPAUSE','-dBATCH',
82+
'-sOutputFile='+new,old],
83+
}
84+
defconvert(filename):
85+
'''Convert the named file into a png file.
86+
Returns the name of the created file.
87+
'''
88+
base,extension=filename.rsplit('.',1)
89+
ifextensionnotinconverter:
90+
raiseKeyError,"Don't know how to convert %s files to png"%extension
91+
newname=base+'_'+extension+'.png'
92+
cmd=converter[extension](filename,newname)
93+
pipe=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
94+
stdout,stderr=pipe.communicate()
95+
ifnotos.path.exists(newname):
96+
msg="Conversion command failed:\n%s\n"%' '.join(cmd)
97+
ifstdout:
98+
msg+="Standard output:\n%s\n"%stdout
99+
ifstderr:
100+
msg+="Standard error:\n%s\n"%stderr
101+
raiseIOError,msg
102+
returnnewname
103+
76104
defcompare_images(expected,actual,tol,in_decorator=False ):
77105
'''Compare two image files - not the greatest, but fast and good enough.
78106
@@ -99,7 +127,15 @@ def compare_images( expected, actual, tol, in_decorator=False ):
99127
"be installed. To run tests without using PIL, then use " \
100128
"the '--without-tag=PIL' command-line option.\n" \
101129
"Importing PIL failed with the following error:\n%s"%e
102-
returnmsg
130+
ifin_decorator:
131+
raiseNotImplementedError,e
132+
else:
133+
returnmsg
134+
135+
# Convert the image to png
136+
extension=expected.split('.')[-1]
137+
ifextension!='png':
138+
expected,actual=convert(expected),convert(actual)
103139

104140
# open the image files and remove the alpha channel (if it exists)
105141
expectedImage=Image.open(expected ).convert("RGB")

‎lib/matplotlib/testing/decorators.py

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
KnownFailureDidNotFailTest,ImageComparisonFailure
33
importos,sys
44
importnose
5+
importmatplotlib
56
importmatplotlib.tests
67
frommatplotlib.testing.compareimportcompare_images
78

@@ -48,42 +49,54 @@ def image_comparison(baseline_images=None):
4849
raiseValueError('baseline_images must be specified')
4950
defcompare_images_decorator(func):
5051
defdecorated_compare_images(*args,**kwargs):
51-
result=func(*args,**kwargs)
52-
extension='.png'# TODO: test more backends
53-
forfnameinbaseline_images:
54-
# FIXME: place "actual", or current images, images in
55-
# a more reasonable location than the current
56-
# directory. Also, perhaps put them in sub-directory
57-
# according to the name of the test module like the
58-
# baseline images.
59-
actual=fname+extension
6052

61-
# compute filename for baseline image
62-
module_name=func.__module__
63-
ifmodule_name=='__main__':
64-
# FIXME: this won't work for nested packages in matplotlib.tests
65-
importwarnings
66-
warnings.warn('test module run as script. guessing baseline image locations')
67-
script_name=sys.argv[0]
68-
basedir=os.path.abspath(os.path.dirname(script_name))
69-
subdir=os.path.splitext(os.path.split(script_name)[1])[0]
70-
else:
71-
mods=module_name.split('.')
72-
assertmods.pop(0)=='matplotlib'
73-
assertmods.pop(0)=='tests'
74-
subdir=os.path.join(*mods)
75-
basedir=os.path.dirname(matplotlib.tests.__file__)
76-
baseline_dir=os.path.join(basedir,'baseline_images',subdir)
77-
expected=os.path.join(baseline_dir,fname)+extension
53+
# compute baseline image directory
54+
module_name=func.__module__
55+
ifmodule_name=='__main__':
56+
# FIXME: this won't work for nested packages in matplotlib.tests
57+
importwarnings
58+
warnings.warn('test module run as script. guessing baseline image locations')
59+
script_name=sys.argv[0]
60+
basedir=os.path.abspath(os.path.dirname(script_name))
61+
subdir=os.path.splitext(os.path.split(script_name)[1])[0]
62+
else:
63+
mods=module_name.split('.')
64+
assertmods.pop(0)=='matplotlib'
65+
assertmods.pop(0)=='tests'
66+
subdir=os.path.join(*mods)
67+
basedir=os.path.dirname(matplotlib.tests.__file__)
68+
baseline_dir=os.path.join(basedir,'baseline_images',subdir)
69+
result_dir=os.path.join(basedir,'current_images',subdir)
70+
ifnotos.path.exists(result_dir):
71+
try:
72+
# make the current_images directory first
73+
os.mkdir(os.path.join(basedir,'current_images'))
74+
exceptOSError:
75+
pass# probably exists already
76+
os.mkdir(result_dir)
7877

79-
# compare the images
80-
tol=1e-3# default tolerance
81-
err=compare_images(expected,actual,tol,
82-
in_decorator=True )
83-
iferr:
84-
raiseImageComparisonFailure(
85-
'images not close: %(actual)s vs. %(expected)s '
86-
'(RMS %(rms).3f)'%err)
87-
returnresult
78+
forextensionin ['png','pdf']:
79+
# set the default format of savefig
80+
matplotlib.rc('savefig',extension=extension)
81+
# change to the result directory for the duration of the test
82+
old_dir=os.getcwd()
83+
os.chdir(result_dir)
84+
try:
85+
last_result=func(*args,**kwargs)# actually call the test function
86+
finally:
87+
os.chdir(old_dir)
88+
forfnameinbaseline_images:
89+
actual=os.path.join(result_dir,fname)+'.'+extension
90+
expected=os.path.join(baseline_dir,fname)+'.'+extension
91+
92+
# compare the images
93+
tol=1e-3# default tolerance
94+
err=compare_images(expected,actual,tol,
95+
in_decorator=True )
96+
iferr:
97+
raiseImageComparisonFailure(
98+
'images not close: %(actual)s vs. %(expected)s '
99+
'(RMS %(rms).3f)'%err)
100+
returnlast_result
88101
returnnose.tools.make_decorator(func)(decorated_compare_images)
89102
returncompare_images_decorator
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp