Skip to content

Commit

Permalink
TST: fixing zipline tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvishaiW committed Feb 13, 2018
1 parent f279101 commit c571c1c
Show file tree
Hide file tree
Showing 57 changed files with 326 additions and 326 deletions.
2 changes: 1 addition & 1 deletion catalyst/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
write_bcolz_minute_data,
write_compressed,
)
from .fixtures import ZiplineTestCase # noqa
from .fixtures import CatalystTestCase # noqa
2 changes: 1 addition & 1 deletion catalyst/testing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def create_data_portal_from_trade_history(asset_finder, trading_calendar,
return DataPortal(
asset_finder, trading_calendar,
first_trading_day=equity_daily_reader.first_trading_day,
equity_daily_reader=equity_daily_reader,
daily_reader=equity_daily_reader,
)
else:
minutes = trading_calendar.minutes_in_range(
Expand Down
56 changes: 28 additions & 28 deletions catalyst/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
catalyst_dir = os.path.dirname(catalyst.__file__)


class ZiplineTestCase(with_metaclass(FinalMeta, TestCase)):
class CatalystTestCase(with_metaclass(FinalMeta, TestCase)):
"""
Shared extensions to core unittest.TestCase.
Expand Down Expand Up @@ -92,7 +92,7 @@ def setUpClass(cls):
cls._base_init_fixtures_was_called = False
cls.init_class_fixtures()
assert cls._base_init_fixtures_was_called, (
"ZiplineTestCase.init_class_fixtures() was not called.\n"
"CatalystTestCase.init_class_fixtures() was not called.\n"
"This probably means that you overrode init_class_fixtures"
" without calling super()."
)
Expand Down Expand Up @@ -170,7 +170,7 @@ def setUp(self):
self._init_instance_fixtures_was_called = False
self.init_instance_fixtures()
assert self._init_instance_fixtures_was_called, (
"ZiplineTestCase.init_instance_fixtures() was not"
"CatalystTestCase.init_instance_fixtures() was not"
" called.\n"
"This probably means that you overrode"
" init_instance_fixtures without calling super()."
Expand Down Expand Up @@ -251,7 +251,7 @@ def alias(attr_name):

class WithDefaultDateBounds(object):
"""
ZiplineTestCase mixin which makes it possible to synchronize date bounds
CatalystTestCase mixin which makes it possible to synchronize date bounds
across fixtures.
This fixture should always be the last fixture in bases of any fixture or
Expand All @@ -264,13 +264,13 @@ class WithDefaultDateBounds(object):
The date bounds to be used for fixtures that want to have consistent
dates.
"""
START_DATE = pd.Timestamp('2006-01-03', tz='utc')
END_DATE = pd.Timestamp('2006-12-29', tz='utc')
START_DATE = pd.Timestamp('2016-01-03', tz='utc')
END_DATE = pd.Timestamp('2016-12-29', tz='utc')


class WithLogger(object):
"""
ZiplineTestCase mixin providing cls.log_handler as an instance-level
CatalystTestCase mixin providing cls.log_handler as an instance-level
fixture.
After init_instance_fixtures has been called `self.log_handler` will be a
Expand All @@ -295,7 +295,7 @@ def init_class_fixtures(cls):

class WithAssetFinder(WithDefaultDateBounds):
"""
ZiplineTestCase mixin providing cls.asset_finder as a class-level fixture.
CatalystTestCase mixin providing cls.asset_finder as a class-level fixture.
After init_class_fixtures has been called, `cls.asset_finder` is populated
with an AssetFinder.
Expand Down Expand Up @@ -402,7 +402,7 @@ def init_class_fixtures(cls):

class WithTradingCalendars(object):
"""
ZiplineTestCase mixin providing cls.trading_calendar,
CatalystTestCase mixin providing cls.trading_calendar,
cls.all_trading_calendars, cls.trading_calendar_for_asset_type as a
class-level fixture.
Expand All @@ -423,7 +423,7 @@ class WithTradingCalendars(object):
with that asset type.
"""
TRADING_CALENDAR_STRS = ('NYSE',)
TRADING_CALENDAR_FOR_ASSET_TYPE = {Equity: 'NYSE', Future: 'us_futures'}
TRADING_CALENDAR_FOR_ASSET_TYPE = {Equity: 'NYSE', Future: 'us_futures', }
TRADING_CALENDAR_FOR_EXCHANGE = {}
# For backwards compatibility, exisitng tests and fixtures refer to
# `trading_calendar` with the assumption that the value is the NYSE
Expand Down Expand Up @@ -460,7 +460,7 @@ class WithTradingEnvironment(WithAssetFinder,
WithTradingCalendars,
WithDefaultDateBounds):
"""
ZiplineTestCase mixin providing cls.env as a class-level fixture.
CatalystTestCase mixin providing cls.env as a class-level fixture.
After ``init_class_fixtures`` has been called, `cls.env` is populated
with a trading environment whose `asset_finder` is the result of
Expand Down Expand Up @@ -560,7 +560,7 @@ def init_class_fixtures(cls):

class WithSimParams(WithTradingEnvironment):
"""
ZiplineTestCase mixin providing cls.sim_params as a class level fixture.
CatalystTestCase mixin providing cls.sim_params as a class level fixture.
The arguments used to construct the trading environment may be overridded
by putting ``SIM_PARAMS_{argname}`` in the class dict except for the
Expand Down Expand Up @@ -615,7 +615,7 @@ def init_class_fixtures(cls):

class WithTradingSessions(WithTradingCalendars, WithDefaultDateBounds):
"""
ZiplineTestCase mixin providing cls.trading_days, cls.all_trading_sessions
CatalystTestCase mixin providing cls.trading_days, cls.all_trading_sessions
as a class-level fixture.
After init_class_fixtures has been called, `cls.all_trading_sessions`
Expand Down Expand Up @@ -668,7 +668,7 @@ def init_class_fixtures(cls):

class WithTmpDir(object):
"""
ZiplineTestCase mixing providing cls.tmpdir as a class-level fixture.
CatalystTestCase mixing providing cls.tmpdir as a class-level fixture.
After init_class_fixtures has been called, `cls.tmpdir` is populated with
a `testfixtures.TempDirectory` object whose path is `cls.TMP_DIR_PATH`.
Expand All @@ -691,7 +691,7 @@ def init_class_fixtures(cls):

class WithInstanceTmpDir(object):
"""
ZiplineTestCase mixing providing self.tmpdir as an instance-level fixture.
CatalystTestCase mixing providing self.tmpdir as an instance-level fixture.
After init_instance_fixtures has been called, `self.tmpdir` is populated
with a `testfixtures.TempDirectory` object whose path is
Expand All @@ -714,7 +714,7 @@ def init_instance_fixtures(self):

class WithEquityDailyBarData(WithTradingEnvironment):
"""
ZiplineTestCase mixin providing cls.make_equity_daily_bar_data.
CatalystTestCase mixin providing cls.make_equity_daily_bar_data.
Attributes
----------
Expand Down Expand Up @@ -810,7 +810,7 @@ def init_class_fixtures(cls):

class WithBcolzEquityDailyBarReader(WithEquityDailyBarData, WithTmpDir):
"""
ZiplineTestCase mixin providing cls.bcolz_daily_bar_path,
CatalystTestCase mixin providing cls.bcolz_daily_bar_path,
cls.bcolz_daily_bar_ctable, and cls.bcolz_equity_daily_bar_reader
class level fixtures.
Expand Down Expand Up @@ -895,7 +895,7 @@ def init_class_fixtures(cls):

class WithBcolzEquityDailyBarReaderFromCSVs(WithBcolzEquityDailyBarReader):
"""
ZiplineTestCase mixin that provides
CatalystTestCase mixin that provides
cls.bcolz_equity_daily_bar_reader from a mapping of sids to CSV
file paths.
"""
Expand Down Expand Up @@ -925,7 +925,7 @@ class _WithMinuteBarDataBase(WithTradingEnvironment):

class WithEquityMinuteBarData(_WithMinuteBarDataBase):
"""
ZiplineTestCase mixin providing cls.equity_minute_bar_days.
CatalystTestCase mixin providing cls.equity_minute_bar_days.
After init_class_fixtures has been called:
- `cls.equity_minute_bar_days` has the range over which data has been
Expand Down Expand Up @@ -984,7 +984,7 @@ def init_class_fixtures(cls):

class WithFutureMinuteBarData(_WithMinuteBarDataBase):
"""
ZiplineTestCase mixin providing cls.future_minute_bar_days.
CatalystTestCase mixin providing cls.future_minute_bar_days.
After init_class_fixtures has been called:
- `cls.future_minute_bar_days` has the range over which data has been
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def init_class_fixtures(cls):

class WithBcolzEquityMinuteBarReader(WithEquityMinuteBarData, WithTmpDir):
"""
ZiplineTestCase mixin providing cls.bcolz_minute_bar_path,
CatalystTestCase mixin providing cls.bcolz_minute_bar_path,
cls.bcolz_minute_bar_ctable, and cls.bcolz_equity_minute_bar_reader
class level fixtures.
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def init_class_fixtures(cls):

class WithBcolzFutureMinuteBarReader(WithFutureMinuteBarData, WithTmpDir):
"""
ZiplineTestCase mixin providing cls.bcolz_minute_bar_path,
CatalystTestCase mixin providing cls.bcolz_minute_bar_path,
cls.bcolz_minute_bar_ctable, and cls.bcolz_equity_minute_bar_reader
class level fixtures.
Expand Down Expand Up @@ -1227,7 +1227,7 @@ def make_future_minute_bar_data(cls):

class WithAdjustmentReader(WithBcolzEquityDailyBarReader):
"""
ZiplineTestCase mixin providing cls.adjustment_reader as a class level
CatalystTestCase mixin providing cls.adjustment_reader as a class level
fixture.
After init_class_fixtures has been called, `cls.adjustment_reader` will be
Expand Down Expand Up @@ -1359,7 +1359,7 @@ def make_adjustment_db_conn_str(cls):

class WithSeededRandomPipelineEngine(WithTradingSessions, WithAssetFinder):
"""
ZiplineTestCase mixin providing class-level fixtures for running pipelines
CatalystTestCase mixin providing class-level fixtures for running pipelines
against deterministically-generated random data.
Attributes
Expand Down Expand Up @@ -1434,7 +1434,7 @@ class WithDataPortal(WithAdjustmentReader,
WithBcolzEquityMinuteBarReader,
WithBcolzFutureMinuteBarReader):
"""
ZiplineTestCase mixin providing self.data_portal as an instance level
CatalystTestCase mixin providing self.data_portal as an instance level
fixture.
After init_instance_fixtures has been called, `self.data_portal` will be
Expand Down Expand Up @@ -1485,12 +1485,12 @@ def make_data_portal(self):
self.env.asset_finder,
self.trading_calendar,
first_trading_day=self.DATA_PORTAL_FIRST_TRADING_DAY,
equity_daily_reader=(
daily_reader=(
self.bcolz_equity_daily_bar_reader
if self.DATA_PORTAL_USE_DAILY_DATA else
None
),
equity_minute_reader=(
minute_reader=(
self.bcolz_equity_minute_bar_reader
if self.DATA_PORTAL_USE_MINUTE_DATA else
None
Expand Down Expand Up @@ -1526,7 +1526,7 @@ def init_instance_fixtures(self):

class WithResponses(object):
"""
ZiplineTestCase mixin that provides self.responses as an instance
CatalystTestCase mixin that provides self.responses as an instance
fixture.
After init_instance_fixtures has been called, `self.responses` will be
Expand Down
2 changes: 1 addition & 1 deletion catalyst/utils/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__all__ = ['load_from_yahoo', 'load_bars_from_yahoo']


def create_simulation_parameters(year=2006, start=None, end=None,
def create_simulation_parameters(year=2016, start=None, end=None,
capital_base=float("1.0e5"),
num_days=None,
data_frequency='daily',
Expand Down
2 changes: 1 addition & 1 deletion docs/source/whatsnew/0.9.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ None
Miscellaneous
~~~~~~~~~~~~~

* Adds :class:`~zipline.testing.fixtures.ZiplineTestCase` which provides hooks
* Adds :class:`~zipline.testing.fixtures.CatalystTestCase` which provides hooks
to consume test fixtures. Fixtures are things like:
:class:`~zipline.testing.fixtures.WithAssetFinder` which will make
``self.asset_finder`` available to your test with some mock data
Expand Down
4 changes: 2 additions & 2 deletions tests/calendars/test_calendar_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
CyclicCalendarAlias,
InvalidCalendarName,
)
from catalyst.testing import ZiplineTestCase
from catalyst.testing import CatalystTestCase
from catalyst.utils.calendars.calendar_utils import TradingCalendarDispatcher
from catalyst.utils.calendars.exchange_calendar_ice import ICEExchangeCalendar


class CalendarAliasTestCase(ZiplineTestCase):
class CalendarAliasTestCase(CatalystTestCase):

@classmethod
def init_class_fixtures(cls):
Expand Down
4 changes: 2 additions & 2 deletions tests/data/bundles/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
subtest,
str_to_seconds,
)
from catalyst.testing.fixtures import WithInstanceTmpDir, ZiplineTestCase, \
from catalyst.testing.fixtures import WithInstanceTmpDir, CatalystTestCase, \
WithDefaultDateBounds
from catalyst.testing.predicates import (
assert_equal,
Expand All @@ -45,7 +45,7 @@

class BundleCoreTestCase(WithInstanceTmpDir,
WithDefaultDateBounds,
ZiplineTestCase):
CatalystTestCase):

START_DATE = pd.Timestamp('2014-01-06', tz='utc')
END_DATE = pd.Timestamp('2014-01-10', tz='utc')
Expand Down
4 changes: 2 additions & 2 deletions tests/data/bundles/test_quandl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
tmp_dir,
patch_read_csv,
)
from catalyst.testing.fixtures import ZiplineTestCase
from catalyst.testing.fixtures import CatalystTestCase
from catalyst.testing.predicates import (
assert_equal,
)
from catalyst.utils.functional import apply


class QuandlBundleTestCase(ZiplineTestCase):
class QuandlBundleTestCase(CatalystTestCase):
symbols = 'AAPL', 'BRK_A', 'MSFT', 'ZEN'
asset_start = pd.Timestamp('2014-01', tz='utc')
asset_end = pd.Timestamp('2015-01', tz='utc')
Expand Down
4 changes: 2 additions & 2 deletions tests/data/bundles/test_yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from catalyst.data.bundles import yahoo_equities
from catalyst.lib.adjustment import Float64Multiply
from catalyst.testing import test_resource_path, tmp_dir, read_compressed
from catalyst.testing.fixtures import WithResponses, ZiplineTestCase
from catalyst.testing.fixtures import WithResponses, CatalystTestCase
from catalyst.testing.predicates import assert_equal
from catalyst.utils.calendars import get_calendar


class YahooBundleTestCase(WithResponses, ZiplineTestCase):
class YahooBundleTestCase(WithResponses, CatalystTestCase):
symbols = 'AAPL', 'IBM', 'MSFT'
columns = 'open', 'high', 'low', 'close', 'volume'
asset_start = pd.Timestamp('2014-01-02', tz='utc')
Expand Down
6 changes: 3 additions & 3 deletions tests/data/test_dispatch_bar_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
WithBcolzEquityDailyBarReader,
WithBcolzFutureMinuteBarReader,
WithTradingSessions,
ZiplineTestCase,
CatalystTestCase,
)
OHLC = ['open', 'high', 'low', 'close']
Expand All @@ -46,7 +46,7 @@
class AssetDispatchSessionBarTestCase(WithBcolzEquityDailyBarReader,
WithBcolzFutureMinuteBarReader,
WithTradingSessions,
ZiplineTestCase):
CatalystTestCase):
TRADING_CALENDAR_STRS = ('us_futures', 'NYSE')
TRADING_CALENDAR_PRIMARY_CAL = 'us_futures'
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_load_raw_arrays(self):
class AssetDispatchMinuteBarTestCase(WithBcolzEquityMinuteBarReader,
WithBcolzFutureMinuteBarReader,
ZiplineTestCase):
CatalystTestCase):
TRADING_CALENDAR_STRS = ('us_futures', 'NYSE')
TRADING_CALENDAR_PRIMARY_CAL = 'us_futures'
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_minute_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
WithAssetFinder,
WithInstanceTmpDir,
WithTradingCalendars,
ZiplineTestCase,
CatalystTestCase,
)

# Calendar is set to cover several half days, to check a case where half
Expand All @@ -69,7 +69,7 @@
class BcolzMinuteBarTestCase(WithTradingCalendars,
WithAssetFinder,
WithInstanceTmpDir,
ZiplineTestCase):
CatalystTestCase):

ASSET_FINDER_EQUITY_SIDS = 1, 2

Expand Down
Loading

0 comments on commit c571c1c

Please sign in to comment.