1+ import os
2+ import os .path
3+ import glob
14import mplfinance as mpf
25import pandas as pd
6+ import matplotlib .pyplot as plt
7+ from matplotlib .testing .compare import compare_images
38
4- def test_ema ():
9+ print ('mpf.__version__ =' ,mpf .__version__ ) # for the record
10+ print ('mpf.__file__ =' ,mpf .__file__ ) # for the record
11+ print ("plt.rcParams['backend'] =" ,plt .rcParams ['backend' ]) # for the record
12+
13+ base = 'ema'
14+ tdir = os .path .join ('tests' ,'test_images' )
15+ refd = os .path .join ('tests' ,'reference_images' )
16+
17+ IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
18+ # IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
19+
20+ def create_ema_image (tname ):
521
622 df = pd .read_csv ('./examples/data/yahoofinance-GOOG-20040819-20180120.csv' , parse_dates = True )
723 df .index = pd .DatetimeIndex (df ['Date' ])
@@ -20,8 +36,30 @@ def test_ema():
2036 ylabel = 'calculated' , secondary_y = False )
2137 ]
2238
39+ # plot and save in `tname` path
2340 mpf .plot (df , ylabel = "mpf ema" , type = 'ohlc' ,
24- ema = 25 , addplot = ap , panel_ratios = (1 , 1 )
41+ ema = 25 , addplot = ap , panel_ratios = (1 , 1 ), savefig = tname
2542 )
2643
44+
45+ def test_ema ():
46+
47+ fname = base + '01.png'
48+ tname = os .path .join (tdir ,fname )
49+ rname = os .path .join (refd ,fname )
50+
51+ create_ema_image (tname )
52+
53+ tsize = os .path .getsize (tname )
54+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
55+
56+ rsize = os .path .getsize (rname )
57+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
58+
59+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
60+ if result is not None :
61+ print ('result=' ,result )
62+ assert result is None
63+
64+
2765test_ema ()
0 commit comments