14
14
tdir = os .path .join ('tests' ,'test_images' )
15
15
refd = os .path .join ('tests' ,'reference_images' )
16
16
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
+
17
25
IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
18
26
# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
19
27
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
+
21
36
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 ):
24
38
39
+ df = get_ema_data ()
25
40
df = df [- 50 :] # show last 50 data points only
26
41
27
42
ema25 = df ['Close' ].ewm (span = 25.0 , adjust = False ).mean ()
@@ -42,7 +57,7 @@ def create_ema_image(tname):
42
57
)
43
58
44
59
45
- def test_ema ():
60
+ def test_ema01 ():
46
61
47
62
fname = base + '01.png'
48
63
tname = os .path .join (tdir ,fname )
@@ -61,5 +76,49 @@ def test_ema():
61
76
print ('result=' ,result )
62
77
assert result is None
63
78
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
64
124
65
- test_ema ()
0 commit comments