Skip to content

Commit 5605030

Browse files
restructure tests
1 parent 5901710 commit 5605030

File tree

8 files changed

+95
-70
lines changed

8 files changed

+95
-70
lines changed

examples/mpftests/test_addplot.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/mpftests/test_addplot.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os as os
2+
import pandas as pd
3+
import mplfinance as mpf
4+
import matplotlib.pyplot as plt
5+
from matplotlib.testing.compare import compare_images
6+
7+
print('pd.__version__ =',pd.__version__ ) # for the record
8+
print('mpf.__version__ =',mpf.__version__) # for the record
9+
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
10+
11+
import subprocess
12+
pwd = subprocess.run(['pwd'], stdout=subprocess.PIPE)
13+
print('pwd.stdout=',pwd.stdout)
14+
15+
df = pd.read_csv('examples/data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)
16+
print('df.shape=' , df.shape )
17+
print('df.head(3)=', df.head(3))
18+
print('df.tail(3)=', df.tail(3))
19+
20+
prefix='addplot'
21+
tdir='tests/mpftests/test_images/'
22+
refd='tests/mpftests/reference_images/'
23+
#os.system('rm -f '+tdir+prefix+'*.jpg')
24+
os.system('rm -f '+tdir+prefix+'*.png')
25+
26+
IMGCOMP_TOLERANCE = 7.0
27+
28+
# ---- Test 01 -----
29+
30+
def test_addplot01():
31+
32+
fname=prefix+'01.png'
33+
mpf.plot(df,volume=True,savefig=tdir+fname)
34+
35+
os.system('ls -l '+tdir+fname)
36+
37+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
38+
if result is not None:
39+
print('result=',result)
40+
assert result is None
41+
42+
# ---- Test 02 -----
43+
44+
def test_addplot02():
45+
fname=prefix+'02.png'
46+
apdict = mpf.make_addplot(df['LowerB'])
47+
mpf.plot(df,volume=True,addplot=apdict,savefig=tdir+fname)
48+
49+
os.system('ls -l '+tdir+fname)
50+
51+
result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
52+
if result is not None:
53+
print('result=',result)
54+
assert result is None

tests/mpftests/test_raise.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os as os
2+
import pandas as pd
3+
import mplfinance as mpf
4+
import matplotlib.pyplot as plt
5+
from matplotlib.testing.compare import compare_images
6+
7+
print('pd.__version__ =',pd.__version__ ) # for the record
8+
print('mpf.__version__ =',mpf.__version__) # for the record
9+
print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
10+
11+
import subprocess
12+
pwd = subprocess.run(['pwd'], stdout=subprocess.PIPE)
13+
print('pwd.stdout=',pwd.stdout)
14+
15+
df = pd.read_csv('examples/data/SPY_20110701_20120630_Bollinger.csv',index_col=0,parse_dates=True)
16+
print('df.shape=' , df.shape )
17+
print('df.head(3)=', df.head(3))
18+
print('df.tail(3)=', df.tail(3))
19+
20+
## prefix='addplot'
21+
## tdir='test_images/'
22+
## refd='reference_images/'
23+
## #os.system('rm -f '+tdir+prefix+'*.jpg')
24+
## os.system('rm -f '+tdir+prefix+'*.png')
25+
26+
import pytest
27+
28+
# @pytest.fixture(scope='session',autouse=True)
29+
# def root_directory(request):
30+
# return str(request.config.rootdir)
31+
32+
#def test_raise_ex(root_directory):
33+
def test_raise():
34+
#print("root_directory=",root_directory)
35+
apdict = mpf.make_addplot(df['LowerB'])
36+
with pytest.raises(ValueError):
37+
mpf.plot(df,volume='True',addplot=apdict)

tests.py renamed to tests/original_flavor/test_original_flavor.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,15 @@
22
import os
33
import subprocess
44

5-
def test_mplfinance():
6-
'''Run new mplfinance api tests.'''
7-
8-
os.environ['MPLBACKEND'] = 'agg'
9-
10-
os.chdir("examples/mpftests")
11-
12-
exs = glob.glob('test*.py')
13-
try:
14-
for ex in exs:
15-
subprocess.check_call(["python", ex])
16-
finally:
17-
os.chdir("../..")
18-
19-
205
def test_original_flavor_e2e_examples():
216
"""Run e2e tests for folder"""
227

8+
os.environ['MPLBACKEND'] = 'agg'
239
os.chdir("examples/original_flavor")
2410

2511
exs = glob.glob('*.py')
2612
try:
2713
for ex in exs:
2814
subprocess.check_call(["python", ex])
2915
finally:
30-
os.chdir("../..")
16+
os.chdir("../../")

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.py
1111

1212
[testenv]
1313
deps =

0 commit comments

Comments
 (0)