mirror of
https://github.com/saymrwulf/zipline.git
synced 2026-05-14 20:58:10 +00:00
Changes BcolzDailyBarWriter to not be an abc, data is passed as an iterator of (sid, dataframe) pairs to the write method. Changes the AssetsDBWriter to be a single class which accepts an engine at construction time and has a `write` method for writing dataframes for the various tables. We no longer support writing the various other data types, callers should coerce their data into a dataframe themselves. See zipline.assets.synthetic for some helpers to do this. Adds many new fixtures and updates some existing fixtures to use the new ones: WithDefaultDateBounds A fixture that provides the suite a START_DATE and END_DATE. This is meant to make it easy for other fixtures to synchronize their date ranges without depending on eachother in strange ways. For example, WithBcolzMinuteBarReader and WithBcolzDailyBarReader by default should both have data for the same dates, so they may use depend on WithDefaultDates without forcing a dependency between them. WithTmpDir, WithInstanceTmpDir Provides the suite or individual test case a temporary directory. WithBcolzDailyBarReader Provides the suite a BcolzDailyBarReader which reads from bcolz data written to a temporary directory. The data will be read from dataframes and then converted to bcolz files with BcolzDailyBarWriter.write WithBcolzDailyBarReaderFromCSVs Provides the suite a BcolzDailyBarReader which reads from bcolz data written to a temporary directory. The data will be read from a collection of CSV files and then converted into the bcolz data through BcolzDailyBarWriter.write_csvs WithBcolzMinuteBarReader Provides the suite a BcolzMinuteBarReader which reads from bcolz data written to a temporary directory. The data will be read from dataframes and then converted to bcolz files with BcolzMinuteBarWriter.write WithAdjustmentReader Provides the suite a SQLiteAdjustmentReader which reads from an in memory sqlite database. The data will be read from dataframes and then converted into sqlite with SQLiteAdjustmentWriter.write WithDataPortal Provides each test case a DataPortal object with data from temporary resources.
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
#
|
|
# Copyright 2013 Quantopian, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import pandas as pd
|
|
|
|
from zipline.test_algorithms import (
|
|
ExceptionAlgorithm,
|
|
DivByZeroAlgorithm,
|
|
SetPortfolioAlgorithm,
|
|
)
|
|
from zipline.testing.fixtures import (
|
|
WithDataPortal,
|
|
WithSimParams,
|
|
ZiplineTestCase,
|
|
)
|
|
|
|
DEFAULT_TIMEOUT = 15 # seconds
|
|
EXTENDED_TIMEOUT = 90
|
|
|
|
|
|
class ExceptionTestCase(WithDataPortal, WithSimParams, ZiplineTestCase):
|
|
START_DATE = pd.Timestamp('2006-01-03', tz='utc')
|
|
START_DATE = pd.Timestamp('2006-01-07', tz='utc')
|
|
|
|
sid, = ASSET_FINDER_EQUITY_SIDS = 133,
|
|
|
|
def test_exception_in_handle_data(self):
|
|
algo = ExceptionAlgorithm('handle_data',
|
|
self.sid,
|
|
sim_params=self.sim_params,
|
|
env=self.env)
|
|
|
|
with self.assertRaises(Exception) as ctx:
|
|
algo.run(self.data_portal)
|
|
|
|
self.assertEqual(str(ctx.exception), 'Algo exception in handle_data')
|
|
|
|
def test_zerodivision_exception_in_handle_data(self):
|
|
algo = DivByZeroAlgorithm(self.sid,
|
|
sim_params=self.sim_params,
|
|
env=self.env)
|
|
|
|
with self.assertRaises(ZeroDivisionError):
|
|
algo.run(self.data_portal)
|
|
|
|
def test_set_portfolio(self):
|
|
"""
|
|
Are we protected against overwriting an algo's portfolio?
|
|
"""
|
|
algo = SetPortfolioAlgorithm(self.sid,
|
|
sim_params=self.sim_params,
|
|
env=self.env)
|
|
|
|
with self.assertRaises(AttributeError):
|
|
algo.run(self.data_portal)
|