Skip to content

Commit 6f12d71

Browse files
use matplotlib image comparison with tolerance
1 parent 326f232 commit 6f12d71

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed
-83.6 KB
Binary file not shown.
36.6 KB
Loading
-90.5 KB
Binary file not shown.
50.2 KB
Loading

examples/mpftests/test_addplot.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas as pd
33
import mplfinance as mpf
44
import matplotlib.pyplot as plt
5+
from matplotlib.testing.compare import compare_images
56

67
print('pd.__version__ =',pd.__version__ ) # for the record
78
print('mpf.__version__ =',mpf.__version__) # for the record
@@ -20,24 +21,32 @@
2021
prefix='addplot'
2122
tdir='test_images/'
2223
refd='reference_images/'
23-
os.system('rm -f '+tdir+prefix+'*.jpg')
24+
#os.system('rm -f '+tdir+prefix+'*.jpg')
2425
os.system('rm -f '+tdir+prefix+'*.png')
2526

27+
IMGCOMP_TOLERANCE = 7.0
28+
2629
# ---- Test 01 -----
2730

28-
fname=prefix+'01.jpg'
31+
fname=prefix+'01.png'
2932
mpf.plot(df,volume=True,savefig=tdir+fname)
3033

3134
os.system('ls -l '+tdir+fname)
32-
rc = os.system('diff '+tdir+fname+' '+refd+fname)
33-
assert rc == 0
35+
36+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
37+
if result is not None:
38+
print('result=',result)
39+
assert result is None
3440

3541
# ---- Test 02 -----
3642

37-
fname=prefix+'02.jpg'
43+
fname=prefix+'02.png'
3844
apdict = mpf.make_addplot(df['LowerB'])
3945
mpf.plot(df,volume=True,addplot=apdict,savefig=tdir+fname)
4046

4147
os.system('ls -l '+tdir+fname)
42-
rc = os.system('diff '+tdir+fname+' '+refd+fname)
43-
assert rc == 0
48+
49+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
50+
if result is not None:
51+
print('result=',result)
52+
assert result is None

examples/mpftests/test_images/placeholder.png

Loading

0 commit comments

Comments
 (0)