mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 22:32:30 +08:00
bc0b117dc9
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.
82 lines
2.1 KiB
Python
82 lines
2.1 KiB
Python
@object.__new__
|
|
class nop_context(object):
|
|
"""A nop context manager.
|
|
"""
|
|
def __enter__(self):
|
|
pass
|
|
|
|
def __exit__(self, *excinfo):
|
|
pass
|
|
|
|
|
|
def _nop(*args, **kwargs):
|
|
pass
|
|
|
|
|
|
class CallbackManager(object):
|
|
"""Create a context manager from a pre-execution callback and a
|
|
post-execution callback.
|
|
|
|
Parameters
|
|
----------
|
|
pre : (...) -> any, optional
|
|
A pre-execution callback. This will be passed ``*args`` and
|
|
``**kwargs``.
|
|
post : (...) -> any, optional
|
|
A post-execution callback. This will be passed ``*args`` and
|
|
``**kwargs``.
|
|
|
|
Notes
|
|
-----
|
|
The enter value of this context manager will be the result of calling
|
|
``pre(*args, **kwargs)``
|
|
|
|
Examples
|
|
--------
|
|
>>> def pre(where):
|
|
... print('entering %s block' % where)
|
|
>>> def post(where):
|
|
... print('exiting %s block' % where)
|
|
>>> manager = CallbackManager(pre, post)
|
|
>>> with manager('example'):
|
|
... print('inside example block')
|
|
entering example block
|
|
inside example
|
|
exiting example block
|
|
|
|
These are reusable with different args:
|
|
>>> with manager('another'):
|
|
... print('inside another block')
|
|
entering another block
|
|
inside another block
|
|
exiting another block
|
|
"""
|
|
def __init__(self, pre=None, post=None):
|
|
self.pre = pre if pre is not None else _nop
|
|
self.post = post if post is not None else _nop
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
return _ManagedCallbackContext(self.pre, self.post, args, kwargs)
|
|
|
|
# special case, if no extra args are passed make this a context manager
|
|
# which forwards no args to pre and post
|
|
def __enter__(self):
|
|
return self.pre()
|
|
|
|
def __exit__(self, *excinfo):
|
|
self.post()
|
|
|
|
|
|
class _ManagedCallbackContext(object):
|
|
def __init__(self, pre, post, args, kwargs):
|
|
self._pre = pre
|
|
self._post = post
|
|
self._args = args
|
|
self._kwargs = kwargs
|
|
|
|
def __enter__(self):
|
|
return self._pre(*self._args, **self._kwargs)
|
|
|
|
def __exit__(self, *excinfo):
|
|
self._post(*self._args, **self._kwargs)
|