TST: Add coverage for set_symbol_lookup_date method

This commit is contained in:
Stewart Douglas
2015-09-04 14:55:11 -04:00
parent 1e31866471
commit e507ee097d
+50
View File
@@ -40,6 +40,7 @@ from zipline.errors import (
AccountControlViolation,
SymbolNotFound,
RootSymbolNotFound,
UnsupportedDatetimeFormat,
)
from zipline.test_algorithms import (
access_account_in_init,
@@ -428,6 +429,55 @@ class TestMiscellaneousAPI(TestCase):
with self.assertRaises(RootSymbolNotFound):
algo.future_chain('')
# Check that invalid dates raise UnsupportedDatetimeFormat
with self.assertRaises(UnsupportedDatetimeFormat):
algo.future_chain('CL', 'my_finger_slipped')
with self.assertRaises(UnsupportedDatetimeFormat):
algo.future_chain('CL', '2015-09-')
def test_set_symbol_lookup_date(self):
"""
Test the set_symbol_lookup_date API method.
"""
# Note we start sid enumeration at i+3 so as not to
# collide with sids [1, 2] added in the setUp() method.
dates = pd.date_range('2013-01-01', freq='2D', periods=2, tz='UTC')
# Create two assets with the same symbol but different
# non-overlapping date ranges.
metadata = pd.DataFrame.from_records(
[
{
'sid': i + 3,
'file_name': 'DUP',
'start_date': date.value,
'end_date': (date + timedelta(days=1)).value,
}
for i, date in enumerate(dates)
]
)
algo = TradingAlgorithm(asset_metadata=metadata)
# Set the period end to a date after the period end
# dates for our assets.
algo.sim_params.period_end = pd.Timestamp('2015-01-01', tz='UTC')
# With no symbol lookup date set, we will use the period end date
# for the as_of_date, resulting here in the asset with the earlier
# start date being returned.
result = algo.symbol('DUP')
self.assertEqual(result.symbol, 'DUP')
# By first calling set_symbol_lookup_date, the relevant asset
# should be returned by lookup_symbol_resolve_multiple
for i, date in enumerate(dates):
algo.set_symbol_lookup_date(date)
result = algo.symbol('DUP')
self.assertEqual(result.symbol, 'DUP')
self.assertEqual(result.sid, i + 3)
with self.assertRaises(UnsupportedDatetimeFormat):
algo.set_symbol_lookup_date('foobar')
class TestTransformAlgorithm(TestCase):
def setUp(self):