BUG: Add backwards compatibility for position lookup by int.

This commit is contained in:
Jean Bredeche
2017-04-26 09:55:05 -04:00
parent e3a50dee8f
commit dead9651b2
2 changed files with 84 additions and 3 deletions
+46
View File
@@ -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."
)