mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-11 11:16:15 +08:00
exception handling code revised. gevent, pypy, and threadsim vestiges removed.
devel flag removed.
This commit is contained in:
@@ -2,14 +2,17 @@ import zmq
|
||||
|
||||
from unittest2 import TestCase
|
||||
from collections import defaultdict
|
||||
from logbook.compat import LoggingHandler
|
||||
|
||||
from zipline.test_algorithms import ExceptionAlgorithm
|
||||
from zipline.test_algorithms import ExceptionAlgorithm, NoopAlgorithm
|
||||
from zipline.finance.trading import SIMULATION_STYLE
|
||||
from zipline.core.devsimulator import AddressAllocator
|
||||
from zipline.lines import SimulatedTrading
|
||||
|
||||
from zipline.utils.test_utils import drain_zipline, check
|
||||
from zipline.utils.test_utils import \
|
||||
drain_zipline, \
|
||||
check, \
|
||||
setup_logger, \
|
||||
teardown_logger
|
||||
|
||||
DEFAULT_TIMEOUT = 15 # seconds
|
||||
EXTENDED_TIMEOUT = 90
|
||||
@@ -30,67 +33,126 @@ class ExceptionTestCase(TestCase):
|
||||
'simulation_style' : SIMULATION_STYLE.FIXED_SLIPPAGE
|
||||
}
|
||||
self.ctx = zmq.Context()
|
||||
|
||||
self.log_handler = LoggingHandler()
|
||||
self.log_handler.push_application()
|
||||
setup_logger(self)
|
||||
|
||||
def tearDown(self):
|
||||
self.log_handler.pop_application()
|
||||
self.ctx.term()
|
||||
teardown_logger(self)
|
||||
|
||||
def test_exception_in_init(self):
|
||||
# Simulation
|
||||
# ----------
|
||||
self.zipline_test_config['algorithm'] = \
|
||||
ExceptionAlgorithm(
|
||||
'initialize',
|
||||
self.zipline_test_config['sid']
|
||||
)
|
||||
|
||||
zipline = SimulatedTrading.create_test_zipline(
|
||||
**self.zipline_test_config
|
||||
)
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
self.assertEqual(len(output), 1)
|
||||
self.assertEqual(output[-1]['prefix'], 'EXCEPTION')
|
||||
payload = output[-1]['payload']
|
||||
#check(self, payload, INITIALIZE_TB)
|
||||
|
||||
self.assertTrue(zipline.sim.ready())
|
||||
self.assertFalse(zipline.sim.exception)
|
||||
|
||||
|
||||
def test_exception_in_handle_data(self):
|
||||
|
||||
# Simulation
|
||||
# ----------
|
||||
|
||||
self.zipline_test_config['algorithm'] = \
|
||||
ExceptionAlgorithm('initialize')
|
||||
ExceptionAlgorithm(
|
||||
'handle_data',
|
||||
self.zipline_test_config['sid']
|
||||
)
|
||||
|
||||
zipline = SimulatedTrading.create_test_zipline(
|
||||
**self.zipline_test_config
|
||||
)
|
||||
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(len(output), 1)
|
||||
self.assertEqual(output[-1]['prefix'], 'EXCEPTION')
|
||||
payload = output[-1]['payload']
|
||||
check(self, payload, INITIALIZE_STACK_TB)
|
||||
#check(self, payload, HANDLE_DATA_TB)
|
||||
|
||||
import nose.tools; nose.tools.set_trace()
|
||||
self.assertTrue(zipline.sim.ready())
|
||||
self.assertFalse(zipline.sim.exception)
|
||||
|
||||
|
||||
# TODO:
|
||||
# - exception protocol to use prefix/payload as EXCEPT,
|
||||
# and the stack trace
|
||||
# - test exception in handle_data
|
||||
# - define more zipline failure modes: exception in other
|
||||
# components, exception in Monitor, etc. write tests
|
||||
# for those scenarios.
|
||||
|
||||
|
||||
|
||||
INITIALIZE_STACK_TB =\
|
||||
INITIALIZE_TB =\
|
||||
[{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self._run()',
|
||||
'lineno': 229,
|
||||
'method': 'run'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self.open()',
|
||||
'lineno': 208,
|
||||
'line': 'self.loop()',
|
||||
'lineno': 220,
|
||||
'method': '_run'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self.do_work()',
|
||||
'lineno': 257,
|
||||
'method': 'loop'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'self.initialize_algo()',
|
||||
'lineno': 73,
|
||||
'method': 'open'},
|
||||
'lineno': 100,
|
||||
'method': 'do_work'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'self.do_op(self.algorithm.initialize)',
|
||||
'lineno': 83,
|
||||
'method': 'initialize_algo'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'callable_op(*args, **kwargs)',
|
||||
'lineno': 205,
|
||||
'lineno': 208,
|
||||
'method': 'do_op'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/test_algorithms.py',
|
||||
'line': 'raise Exception("Algo exception in initialize")',
|
||||
'lineno': 161,
|
||||
'lineno': 162,
|
||||
'method': 'initialize'}]
|
||||
|
||||
HANDLE_DATA_TB =\
|
||||
[{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self._run()',
|
||||
'lineno': 229,
|
||||
'method': 'run'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self.loop()',
|
||||
'lineno': 220,
|
||||
'method': '_run'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py',
|
||||
'line': 'self.do_work()',
|
||||
'lineno': 257,
|
||||
'method': 'loop'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'self.process_event(event)',
|
||||
'lineno': 119,
|
||||
'method': 'do_work'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'self.run_algorithm()',
|
||||
'lineno': 167,
|
||||
'method': 'process_event'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'self.do_op(self.algorithm.handle_data, data)',
|
||||
'lineno': 189,
|
||||
'method': 'run_algorithm'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py',
|
||||
'line': 'callable_op(*args, **kwargs)',
|
||||
'lineno': 208,
|
||||
'method': 'do_op'},
|
||||
{'file': '/Users/fawce/projects/qexec/zipline_repo/zipline/test_algorithms.py',
|
||||
'line': 'raise Exception("Algo exception in handle_data")',
|
||||
'lineno': 183,
|
||||
'method': 'handle_data'}]
|
||||
|
||||
Reference in New Issue
Block a user