mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
BUG: Add backwards compatibility for position lookup by int.
This commit is contained in:
@@ -113,6 +113,22 @@ def handle_data(context, data):
|
||||
assert iter_list == items_list
|
||||
"""
|
||||
|
||||
reference_missing_position_by_int_algo = """
|
||||
def initialize(context):
|
||||
pass
|
||||
|
||||
def handle_data(context, data):
|
||||
context.portfolio.positions[24]
|
||||
"""
|
||||
|
||||
reference_missing_position_by_unexpected_type_algo = """
|
||||
def initialize(context):
|
||||
pass
|
||||
|
||||
def handle_data(context, data):
|
||||
context.portfolio.positions["foobar"]
|
||||
"""
|
||||
|
||||
|
||||
class TestAPIShim(WithCreateBarData,
|
||||
WithDataPortal,
|
||||
@@ -513,3 +529,33 @@ class TestAPIShim(WithCreateBarData,
|
||||
self.assertEqual("Iterating over the assets in `data` is "
|
||||
"deprecated.",
|
||||
str(warning.message))
|
||||
|
||||
def test_reference_empty_position_by_int(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(reference_missing_position_by_int_algo)
|
||||
algo.run(self.data_portal)
|
||||
|
||||
self.assertEqual(1, len(w))
|
||||
self.assertEqual(
|
||||
w[0].message.message,
|
||||
"Referencing positions by integer is deprecated. Use an asset "
|
||||
"instead."
|
||||
)
|
||||
|
||||
def test_reference_empty_position_by_unexpected_type(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("default", ZiplineDeprecationWarning)
|
||||
|
||||
algo = self.create_algo(
|
||||
reference_missing_position_by_unexpected_type_algo
|
||||
)
|
||||
algo.run(self.data_portal)
|
||||
|
||||
self.assertEqual(1, len(w))
|
||||
self.assertEqual(
|
||||
w[0].message.message,
|
||||
"Position lookup expected a value of type Asset but got str"
|
||||
" instead."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user