File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727
2828import backtrader as bt
2929import backtrader .indicators as btind
30+ from backtrader .utils .py3 import PY2
3031
3132
3233class TestStrategy (bt .Strategy ):
@@ -157,7 +158,11 @@ def test_run(main=False):
157158 print (analysis )
158159 print (str (analysis .sqn ))
159160 else :
160- assert str (analysis .sqn ) == '0.912550316439'
161+ # Handle different precision
162+ if PY2 :
163+ assert str (analysis .sqn ) == '0.912550316439'
164+ else :
165+ assert str (analysis .sqn ) == '0.9125503164393756'
161166 assert str (analysis .trades ) == '11'
162167
163168
Original file line number Diff line number Diff line change 2727
2828import backtrader as bt
2929import backtrader .indicators as btind
30+ from backtrader .utils .py3 import PY2
3031
3132
3233class TestStrategy (bt .Strategy ):
@@ -157,9 +158,15 @@ def test_run(main=False):
157158 analysis = analyzer .get_analysis ()
158159 if main :
159160 print (analysis )
160- print (str (analysis [analysis .keys [ 0 ] ]))
161+ print (str (analysis [next ( iter ( analysis .keys ())) ]))
161162 else :
162- assert str (analysis [analysis .keys ()[0 ]]) == '0.2795'
163+ # Handle different precision
164+ if PY2 :
165+ sval = '0.2795'
166+ else :
167+ sval = '0.2794999999999983'
168+
169+ assert str (analysis [next (iter (analysis .keys ()))]) == sval
163170
164171
165172if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments