1+ import os
2+ import os .path
3+ import glob
4+ import mplfinance as mpf
5+ import matplotlib .pyplot as plt
6+ from matplotlib .testing .compare import compare_images
7+
8+ print ('mpf.__version__ =' ,mpf .__version__ ) # for the record
9+ print ("plt.rcParams['backend'] =" ,plt .rcParams ['backend' ]) # for the record
10+
11+ base = 'pnf'
12+ tdir = os .path .join ('tests' ,'test_images' )
13+ refd = os .path .join ('tests' ,'reference_images' )
14+
15+ globpattern = os .path .join (tdir ,base + '*.png' )
16+ oldtestfiles = glob .glob (globpattern )
17+
18+ for fn in oldtestfiles :
19+ try :
20+ os .remove (fn )
21+ except :
22+ print ('Error removing file "' + fn + '"' )
23+
24+ # IMGCOMP_TOLERANCE = 7.0 # this works fine for linux
25+ IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it).
26+
27+ def test_pnf01 (bolldata ):
28+
29+ df = bolldata
30+
31+ fname = base + '01.png'
32+ tname = os .path .join (tdir ,fname )
33+ rname = os .path .join (refd ,fname )
34+
35+ mpf .plot (df ,type = 'pnf' , volume = True ,savefig = tname )
36+
37+ tsize = os .path .getsize (tname )
38+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
39+
40+ rsize = os .path .getsize (rname )
41+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
42+
43+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
44+ if result is not None :
45+ print ('result=' ,result )
46+ assert result is None
47+
48+
49+ def test_pnf02 (bolldata ):
50+
51+ df = bolldata
52+
53+ fname = base + '02.png'
54+ tname = os .path .join (tdir ,fname )
55+ rname = os .path .join (refd ,fname )
56+
57+ mpf .plot (df ,type = 'pnf' , pointnfig_params = dict (box_size = 4 ), volume = True , savefig = tname )
58+
59+ tsize = os .path .getsize (tname )
60+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
61+
62+ rsize = os .path .getsize (rname )
63+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
64+
65+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
66+ if result is not None :
67+ print ('result=' ,result )
68+ assert result is None
69+
70+
71+ def test_pnf03 (bolldata ):
72+
73+ df = bolldata
74+
75+ fname = base + '03.png'
76+ tname = os .path .join (tdir ,fname )
77+ rname = os .path .join (refd ,fname )
78+
79+ mpf .plot (df ,type = 'pnf' , pointnfig_params = dict (box_size = 'atr' , atr_length = 2 ), volume = True , savefig = tname )
80+
81+ tsize = os .path .getsize (tname )
82+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
83+
84+ rsize = os .path .getsize (rname )
85+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
86+
87+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
88+ if result is not None :
89+ print ('result=' ,result )
90+ assert result is None
91+
92+ def test_pnf04 (bolldata ):
93+
94+ df = bolldata
95+
96+ fname = base + '04.png'
97+ tname = os .path .join (tdir ,fname )
98+ rname = os .path .join (refd ,fname )
99+
100+ mpf .plot (df ,type = 'pnf' , pointnfig_params = dict (box_size = 'atr' , atr_length = 'total' ), mav = (4 ,6 ,8 ), volume = True , savefig = tname )
101+
102+ tsize = os .path .getsize (tname )
103+ print (glob .glob (tname ),'[' ,tsize ,'bytes' ,']' )
104+
105+ rsize = os .path .getsize (rname )
106+ print (glob .glob (rname ),'[' ,rsize ,'bytes' ,']' )
107+
108+ result = compare_images (rname ,tname ,tol = IMGCOMP_TOLERANCE )
109+ if result is not None :
110+ print ('result=' ,result )
111+ assert result is None
0 commit comments