Skip to content

Commit 7b43300

Browse files
committed
Adapt analyzer tests to py3
1 parent c573c93 commit 7b43300

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

tests/test_analyzer-sqn.py

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

2828
import backtrader as bt
2929
import backtrader.indicators as btind
30+
from backtrader.utils.py3 import PY2
3031

3132

3233
class 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

tests/test_analyzer-timereturn.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import backtrader as bt
2929
import backtrader.indicators as btind
30+
from backtrader.utils.py3 import PY2
3031

3132

3233
class 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

165172
if __name__ == '__main__':

0 commit comments

Comments
 (0)