Skip to content

Commit 6a14ade

Browse files
add a couple more tests.
1 parent a0074c8 commit 6a14ade

File tree

5 files changed

+74
-7
lines changed

5 files changed

+74
-7
lines changed

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
print('\npd.__version__ =',pd.__version__ ) # for the record
88

9-
109
df = pd.read_csv('examples/data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)
1110
print('df.shape=' , df.shape )
1211
print('df.head(3)=', df.head(3))

tests/reference_images/addplot03.png

103 KB
Loading

tests/reference_images/addplot04.png

122 KB
Loading

tests/test_addplot.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
print('mpf.__version__ =',mpf.__version__) # for the record
77
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
88

9-
import subprocess
10-
pwd = subprocess.run(['pwd'], stdout=subprocess.PIPE)
11-
print('pwd.stdout=',str(pwd.stdout).strip())
12-
139
prefix='addplot'
1410
tdir='tests/test_images/'
1511
refd='tests/reference_images/'
@@ -39,6 +35,78 @@ def test_addplot02(bolldata):
3935

4036
os.system('ls -l '+tdir+fname)
4137

38+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
39+
if result is not None:
40+
print('result=',result)
41+
42+
def percentB_aboveone(percentB,price):
43+
import numpy as np
44+
signal = []
45+
previous = 2
46+
for date,value in percentB.iteritems():
47+
if value > 1 and previous <= 1:
48+
signal.append(price[date]*1.01)
49+
else:
50+
signal.append(np.nan)
51+
previous = value
52+
return signal
53+
54+
def percentB_belowzero(percentB,price):
55+
import numpy as np
56+
signal = []
57+
previous = -1.0
58+
for date,value in percentB.iteritems():
59+
if value < 0 and previous >= 0:
60+
signal.append(price[date]*0.99)
61+
else:
62+
signal.append(np.nan)
63+
previous = value
64+
return signal
65+
66+
def test_addplot03(bolldata):
67+
df = bolldata
68+
fname=prefix+'03.png'
69+
70+
tcdf = df[['LowerB','UpperB']] # DataFrame with two columns
71+
72+
low_signal = percentB_belowzero(df['PercentB'], df['Close'])
73+
high_signal = percentB_aboveone(df['PercentB'], df['Close'])
74+
75+
apds = [ mpf.make_addplot(tcdf),
76+
mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'),
77+
mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'),
78+
mpf.make_addplot((df['PercentB']),panel='lower',color='g')
79+
]
80+
81+
mpf.plot(df,addplot=apds,figscale=1.3,volume=True,savefig=tdir+fname)
82+
83+
os.system('ls -l '+tdir+fname)
84+
85+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
86+
if result is not None:
87+
print('result=',result)
88+
assert result is None
89+
90+
def test_addplot04(bolldata):
91+
df = bolldata
92+
fname=prefix+'04.png'
93+
94+
tcdf = df[['LowerB','UpperB']] # DataFrame with two columns
95+
96+
low_signal = percentB_belowzero(df['PercentB'], df['Close'])
97+
high_signal = percentB_aboveone(df['PercentB'], df['Close'])
98+
99+
apds = [ mpf.make_addplot(tcdf,linestyle='dashdot'),
100+
mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'),
101+
mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'),
102+
mpf.make_addplot((df['PercentB']),panel='lower',color='g',linestyle='dotted')
103+
]
104+
105+
mpf.plot(df,addplot=apds,figscale=1.5,volume=True,
106+
style='starsandstripes',savefig=tdir+fname)
107+
108+
os.system('ls -l '+tdir+fname)
109+
42110
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
43111
if result is not None:
44112
print('result=',result)

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
[tox]
77
envlist = py36, py37, py38
88

9-
#[pytest]
10-
#python_files = tests.py
9+
[pytest]
10+
python_files = tests/*
1111

1212
[testenv]
1313
deps =

0 commit comments

Comments
 (0)