-
Notifications
You must be signed in to change notification settings - Fork 658
/
Copy pathtest_vlines.py
89 lines (63 loc) · 2.4 KB
/
test_vlines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import os.path
import glob
import mplfinance as mpf
import matplotlib.pyplot as plt
from matplotlib.testing.compare import compare_images
print('mpf.__version__ =',mpf.__version__) # for the record
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
base='vlines'
tdir = os.path.join('tests','test_images')
refd = os.path.join('tests','reference_images')
globpattern = os.path.join(tdir,base+'*.png')
oldtestfiles = glob.glob(globpattern)
for fn in oldtestfiles:
try:
os.remove(fn)
except:
print('Error removing file "'+fn+'"')
IMGCOMP_TOLERANCE = 10.0 # this works fine for linux
# IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
def test_vlines01(bolldata):
df = bolldata
fname = base+'01.png'
tname = os.path.join(tdir,fname)
rname = os.path.join(refd,fname)
mpf.plot(df,volume=True,savefig=tname,vlines=['2011-09-13'])
tsize = os.path.getsize(tname)
print(glob.glob(tname),'[',tsize,'bytes',']')
rsize = os.path.getsize(rname)
print(glob.glob(rname),'[',rsize,'bytes',']')
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
if result is not None:
print('result=',result)
assert result is None
def test_vlines02(bolldata):
df = bolldata
fname = base+'02.png'
tname = os.path.join(tdir,fname)
rname = os.path.join(refd,fname)
mpf.plot(df,volume=True,savefig=tname,vlines=['2011-09-13', '2012-02-06', '2011-07-01', '2012-06-28'])
tsize = os.path.getsize(tname)
print(glob.glob(tname),'[',tsize,'bytes',']')
rsize = os.path.getsize(rname)
print(glob.glob(rname),'[',rsize,'bytes',']')
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
if result is not None:
print('result=',result)
assert result is None
def test_vlines03(bolldata):
df = bolldata
fname = base+'03.png'
tname = os.path.join(tdir,fname)
rname = os.path.join(refd,fname)
vl = dict(vlines='02-06-2012',linestyle='-.',colors='g')
mpf.plot(df,type='pnf',vlines=vl,savefig=tname)
tsize = os.path.getsize(tname)
print(glob.glob(tname),'[',tsize,'bytes',']')
rsize = os.path.getsize(rname)
print(glob.glob(rname),'[',rsize,'bytes',']')
result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE)
if result is not None:
print('result=',result)
assert result is None