1414tdir = os .path .join ('tests' ,'test_images' )
1515refd = os .path .join ('tests' ,'reference_images' )
1616
17+ globpattern = os .path .join (tdir ,base + '*.png' )
18+ oldtestfiles = glob .glob (globpattern )
19+ for fn in oldtestfiles :
20+ try :
21+ os .remove (fn )
22+ except :
23+ print ('Error removing file "' + fn + '"' )
24+
1725IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
1826# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
1927
20- def create_ema_image (tname ):
28+ _df = pd .DataFrame ()
29+ def get_ema_data ():
30+ global _df
31+ if len (_df ) == 0 :
32+ _df = pd .read_csv ('./examples/data/yahoofinance-GOOG-20040819-20180120.csv' ,
33+ index_col = 'Date' ,parse_dates = True )
34+ return _df
35+
2136
22- df = pd .read_csv ('./examples/data/yahoofinance-GOOG-20040819-20180120.csv' , parse_dates = True )
23- df .index = pd .DatetimeIndex (df ['Date' ])
37+ def create_ema_image (tname ):
2438
39+ df = get_ema_data ()
2540 df = df [- 50 :] # show last 50 data points only
2641
2742 ema25 = df ['Close' ].ewm (span = 25.0 , adjust = False ).mean ()
@@ -42,7 +57,7 @@ def create_ema_image(tname):
4257 )
4358
4459
45- def test_ema ():
60+ def test_ema01 ():
4661
4762 fname = base + '01.png'
4863 tname = os .path .join (tdir ,fname )
@@ -61,5 +76,49 @@ def test_ema():
6176 print ('result=' ,result )
6277 assert result is None
6378
79+ def test_ema02 ():
80+ fname = base + '02.png'
81+ tname = os .path .join (tdir ,fname )
82+ rname = os .path .join (refd ,fname )
83+
84+ df = get_ema_data ()
85+ df = df [- 125 :- 35 ]
86+
87+ mpf .plot (df , type = 'candle' , ema = (5 ,15 ,25 ), mav = (5 ,15 ,25 ), savefig = tname )
88+
89+ tsize = os .path .getsize (tname )
90+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
91+
92+ rsize = os .path .getsize (rname )
93+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
94+
95+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
96+ if result is not None :
97+ print ('result=' ,result )
98+ assert result is None
99+
100+ def test_ema03 ():
101+ fname = base + '03.png'
102+ tname = os .path .join (tdir ,fname )
103+ rname = os .path .join (refd ,fname )
104+
105+ df = get_ema_data ()
106+ df = df [- 125 :- 35 ]
107+
108+ mac = ['red' ,'orange' ,'yellow' ,'green' ,'blue' ,'purple' ]
109+
110+ mpf .plot (df , type = 'candle' , ema = (5 ,10 ,15 ,25 ), mav = (5 ,15 ,25 ),
111+ mavcolors = mac , savefig = tname )
112+
113+
114+ tsize = os .path .getsize (tname )
115+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
116+
117+ rsize = os .path .getsize (rname )
118+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
119+
120+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
121+ if result is not None :
122+ print ('result=' ,result )
123+ assert result is None
64124
65- test_ema ()
0 commit comments