mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-15 11:22:18 +08:00
added tests for exception messages in datasources and transforms
This commit is contained in:
@@ -7,12 +7,15 @@ from zipline.test_algorithms import ExceptionAlgorithm, DivByZeroAlgorithm
|
||||
from zipline.finance.trading import SIMULATION_STYLE
|
||||
from zipline.core.devsimulator import AddressAllocator
|
||||
from zipline.lines import SimulatedTrading
|
||||
from zipline.gens.transform import StatefulTransform
|
||||
|
||||
from zipline.utils.test_utils import \
|
||||
drain_zipline, \
|
||||
check, \
|
||||
setup_logger, \
|
||||
teardown_logger
|
||||
teardown_logger, \
|
||||
ExceptionSource, \
|
||||
ExceptionTransform
|
||||
|
||||
DEFAULT_TIMEOUT = 15 # seconds
|
||||
EXTENDED_TIMEOUT = 90
|
||||
@@ -36,6 +39,39 @@ class ExceptionTestCase(TestCase):
|
||||
self.ctx.term()
|
||||
teardown_logger(self)
|
||||
|
||||
def test_datasource_exception(self):
|
||||
self.zipline_test_config['trade_source'] = ExceptionSource()
|
||||
zipline = SimulatedTrading.create_test_zipline(
|
||||
**self.zipline_test_config
|
||||
)
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
assert len(output) == 1
|
||||
assert output[0]['prefix'] == 'EXCEPTION'
|
||||
message = output[0]['payload']
|
||||
for field in ['date', 'message', 'name', 'stack']:
|
||||
assert field in message.keys()
|
||||
|
||||
assert message['message'] == 'integer division or modulo by zero'
|
||||
assert message['name'] == 'ZeroDivisionError'
|
||||
|
||||
def test_tranform_exception(self):
|
||||
exc_tnfm = StatefulTransform(ExceptionTransform)
|
||||
self.zipline_test_config['transforms'] = [exc_tnfm]
|
||||
|
||||
zipline = SimulatedTrading.create_test_zipline(
|
||||
**self.zipline_test_config
|
||||
)
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
assert len(output) == 1
|
||||
assert output[0]['prefix'] == 'EXCEPTION'
|
||||
message = output[0]['payload']
|
||||
for field in ['date', 'message', 'name', 'stack']:
|
||||
assert field in message.keys()
|
||||
|
||||
assert message['message'] == 'An assertion message'
|
||||
assert message['name'] == 'AssertionError'
|
||||
|
||||
|
||||
def test_exception_in_init(self):
|
||||
# Simulation
|
||||
# ----------
|
||||
|
||||
Reference in New Issue
Block a user