mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-10 09:54:34 +08:00
MAINT: Make exception handling tests compatible between Python 2 and 3
Python 3 removes the `.message` attribute, so use `str` instead. Also, the divide by zero message has changed slightly between versions, so just check for the exception type, instead of also checking the message.
This commit is contained in:
@@ -57,14 +57,9 @@ class ExceptionTestCase(TestCase):
|
||||
**self.zipline_test_config
|
||||
)
|
||||
|
||||
with self.assertRaises(ZeroDivisionError) as ctx:
|
||||
with self.assertRaises(ZeroDivisionError):
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(
|
||||
ctx.exception.message,
|
||||
'integer division or modulo by zero'
|
||||
)
|
||||
|
||||
def test_tranform_exception(self):
|
||||
exc_tnfm = StatefulTransform(ExceptionTransform)
|
||||
self.zipline_test_config['transforms'] = [exc_tnfm]
|
||||
@@ -76,7 +71,7 @@ class ExceptionTestCase(TestCase):
|
||||
with self.assertRaises(AssertionError) as ctx:
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
self.assertEqual(str(ctx.exception),
|
||||
'An assertion message')
|
||||
|
||||
def test_exception_in_handle_data(self):
|
||||
@@ -96,7 +91,7 @@ class ExceptionTestCase(TestCase):
|
||||
with self.assertRaises(Exception) as ctx:
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
self.assertEqual(str(ctx.exception),
|
||||
'Algo exception in handle_data')
|
||||
|
||||
def test_zerodivision_exception_in_handle_data(self):
|
||||
@@ -113,12 +108,9 @@ class ExceptionTestCase(TestCase):
|
||||
**self.zipline_test_config
|
||||
)
|
||||
|
||||
with self.assertRaises(ZeroDivisionError) as ctx:
|
||||
with self.assertRaises(ZeroDivisionError):
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
'integer division or modulo by zero')
|
||||
|
||||
def test_set_portfolio(self):
|
||||
"""
|
||||
Are we protected against overwriting an algo's portfolio?
|
||||
@@ -136,8 +128,5 @@ class ExceptionTestCase(TestCase):
|
||||
**self.zipline_test_config
|
||||
)
|
||||
|
||||
with self.assertRaises(AttributeError) as ctx:
|
||||
with self.assertRaises(AttributeError):
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
"can't set attribute")
|
||||
|
||||
@@ -95,6 +95,9 @@ class ExceptionSource(object):
|
||||
def next(self):
|
||||
5 / 0
|
||||
|
||||
def __next__(self):
|
||||
5 / 0
|
||||
|
||||
|
||||
class ExceptionTransform(object):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user