Skip to content

Commit b43b558

Browse files
author
Scott Sanderson
authored
Merge pull request #2622 from samatix/assertregex
DEP: Replacing the assertRaisesRegexp which is deprecated by assertRaisesRegex
2 parents 1abcb34 + 9340f38 commit b43b558

File tree

8 files changed

+40
-29
lines changed

8 files changed

+40
-29
lines changed

tests/data/bundles/test_core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ def bundle_ingest_no_create_writers(*args, **kwargs):
275275
called[0] = True
276276

277277
now = pd.Timestamp.utcnow()
278-
with self.assertRaisesRegexp(ValueError,
279-
"ingest .* creates writers .* downgrade"):
278+
with self.assertRaisesRegex(
279+
ValueError,
280+
"ingest .* creates writers .* downgrade"
281+
):
280282
self.ingest('bundle', self.environ, assets_versions=versions,
281283
timestamp=now - pd.Timedelta(seconds=1))
282284
assert_false(called[0])

tests/data/test_daily_bars.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ def test_read_known_and_unknown_sids(self):
336336
# E.g.
337337
# INVALID VALID INVALID VALID ... VALID INVALID
338338
query_assets = (
339-
[self.assets[-1] + 1] +
340-
list(range(self.assets[0], self.assets[-1] + 1)) +
341-
[self.assets[-1] + 3]
339+
[self.assets[-1] + 1] +
340+
list(range(self.assets[0], self.assets[-1] + 1)) +
341+
[self.assets[-1] + 3]
342342
)
343343

344344
columns = [CLOSE, VOLUME]
@@ -609,10 +609,10 @@ def test_write_attrs(self):
609609
result = self.bcolz_daily_bar_ctable
610610
expected_first_row = {
611611
'1': 0,
612-
'3': 5, # Asset 1 has 5 trading days.
613-
'5': 12, # Asset 3 has 7 trading days.
614-
'7': 33, # Asset 5 has 21 trading days.
615-
'9': 44, # Asset 7 has 11 trading days.
612+
'3': 5, # Asset 1 has 5 trading days.
613+
'5': 12, # Asset 3 has 7 trading days.
614+
'7': 33, # Asset 5 has 21 trading days.
615+
'9': 44, # Asset 7 has 11 trading days.
616616
'11': 49, # Asset 9 has 5 trading days.
617617
}
618618
expected_last_row = {
@@ -621,14 +621,14 @@ def test_write_attrs(self):
621621
'5': 32,
622622
'7': 43,
623623
'9': 48,
624-
'11': 57, # Asset 11 has 9 trading days.
624+
'11': 57, # Asset 11 has 9 trading days.
625625
}
626626
expected_calendar_offset = {
627-
'1': 0, # Starts on 6-01, 1st trading day of month.
628-
'3': 15, # Starts on 6-22, 16th trading day of month.
629-
'5': 1, # Starts on 6-02, 2nd trading day of month.
630-
'7': 0, # Starts on 6-01, 1st trading day of month.
631-
'9': 9, # Starts on 6-12, 10th trading day of month.
627+
'1': 0, # Starts on 6-01, 1st trading day of month.
628+
'3': 15, # Starts on 6-22, 16th trading day of month.
629+
'5': 1, # Starts on 6-02, 2nd trading day of month.
630+
'7': 0, # Starts on 6-01, 1st trading day of month.
631+
'9': 9, # Starts on 6-12, 10th trading day of month.
632632
'11': 10, # Starts on 6-15, 11th trading day of month.
633633
}
634634
self.assertEqual(result.attrs['first_row'], expected_first_row)
@@ -706,7 +706,7 @@ def test_missing_values_assertion(self):
706706
"[Timestamp('2015-06-15 00:00:00+0000', tz='UTC')]\n"
707707
"Extra sessions: []"
708708
)
709-
with self.assertRaisesRegexp(AssertionError, expected_msg):
709+
with self.assertRaisesRegex(AssertionError, expected_msg):
710710
writer.write(bar_data)
711711

712712

tests/pipeline/test_downsampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_yearly(self, base_terms, calendar_name):
197197
# land prior to the first date of 2012. The downsampled terms will fail
198198
# to request enough extra rows.
199199
for i in range(0, 30, 5):
200-
with self.assertRaisesRegexp(
200+
with self.assertRaisesRegex(
201201
NoFurtherDataError,
202202
r'\s*Insufficient data to compute Pipeline'
203203
):

tests/pipeline/test_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_bad_dates(self):
226226
p = Pipeline()
227227

228228
msg = "start_date must be before or equal to end_date .*"
229-
with self.assertRaisesRegexp(ValueError, msg):
229+
with self.assertRaisesRegex(ValueError, msg):
230230
self.engine.run_pipeline(p, self.dates[2], self.dates[1])
231231

232232
def test_fail_usefully_on_insufficient_data(self):

tests/pipeline/test_pipeline.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest import TestCase
55

66
from mock import patch
7+
from six import PY2
78

89
from zipline.pipeline import Factor, Filter, Pipeline
910
from zipline.pipeline.data import Column, DataSet, USEquityPricing
@@ -43,6 +44,10 @@ class SomeOtherFilter(Filter):
4344

4445
class PipelineTestCase(TestCase):
4546

47+
if PY2:
48+
def assertRaisesRegex(self, *args, **kwargs):
49+
return self.assertRaisesRegexp(*args, **kwargs)
50+
4651
def test_construction(self):
4752
p0 = Pipeline()
4853
self.assertEqual(p0.columns, {})
@@ -208,7 +213,7 @@ def mock_display_graph(g, format='svg', include_asset_exists=False):
208213
r"but got 'fizzbuzz' instead."
209214
)
210215

211-
with self.assertRaisesRegexp(ValueError, expected):
216+
with self.assertRaisesRegex(ValueError, expected):
212217
p.show_graph(format='fizzbuzz')
213218

214219
def test_infer_domain_no_terms(self):

tests/test_assets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def test_lookup_by_supplementary_field(self):
12671267
self.assertEqual(asset_1.sid, 1)
12681268

12691269
# We don't know about this ALT_ID yet.
1270-
with self.assertRaisesRegexp(
1270+
with self.assertRaisesRegex(
12711271
ValueNotFoundForField,
12721272
"Value '{}' was not found for field '{}'.".format(
12731273
'100000002',
@@ -1294,7 +1294,7 @@ def test_lookup_by_supplementary_field(self):
12941294
"Multiple occurrences of the value '{}' found for field '{}'."
12951295
).format('100000000', 'ALT_ID')
12961296

1297-
with self.assertRaisesRegexp(
1297+
with self.assertRaisesRegex(
12981298
MultipleValuesFoundForField,
12991299
expected_in_repr,
13001300
):
@@ -1377,7 +1377,7 @@ def test_get_supplementary_field(self):
13771377

13781378
# Since sid 2 has not yet started, we don't know about its
13791379
# ALT_ID.
1380-
with self.assertRaisesRegexp(
1380+
with self.assertRaisesRegex(
13811381
NoValueForSid,
13821382
"No '{}' value found for sid '{}'.".format('ALT_ID', 2),
13831383
):
@@ -1395,7 +1395,7 @@ def test_get_supplementary_field(self):
13951395
)
13961396

13971397
# Sid 0 has historically held two values for ALT_ID by this dt.
1398-
with self.assertRaisesRegexp(
1398+
with self.assertRaisesRegex(
13991399
MultipleValuesFoundForSid,
14001400
"Multiple '{}' values found for sid '{}'.".format('ALT_ID', 0),
14011401
):

tests/test_history.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def test_negative_bar_count(self):
627627
"""
628628
Negative bar counts leak future information.
629629
"""
630-
with self.assertRaisesRegexp(
630+
with self.assertRaisesRegex(
631631
ValueError,
632632
"bar_count must be >= 1, but got -1"
633633
):
@@ -1388,7 +1388,7 @@ def test_history_window_before_first_trading_day(self):
13881388
'window, start the backtest on or after 2014-01-06.'
13891389
)
13901390
for field in OHLCP:
1391-
with self.assertRaisesRegexp(
1391+
with self.assertRaisesRegex(
13921392
HistoryWindowStartsBeforeData, exp_msg):
13931393
self.data_portal.get_history_window(
13941394
[self.ASSET1],
@@ -2030,7 +2030,7 @@ def test_history_window_before_first_trading_day(self):
20302030
'window, start the backtest on or after 2014-01-09.'
20312031
)
20322032

2033-
with self.assertRaisesRegexp(HistoryWindowStartsBeforeData, exp_msg):
2033+
with self.assertRaisesRegex(HistoryWindowStartsBeforeData, exp_msg):
20342034
self.data_portal.get_history_window(
20352035
[self.ASSET1],
20362036
second_day,
@@ -2040,7 +2040,7 @@ def test_history_window_before_first_trading_day(self):
20402040
'daily',
20412041
)[self.ASSET1]
20422042

2043-
with self.assertRaisesRegexp(HistoryWindowStartsBeforeData, exp_msg):
2043+
with self.assertRaisesRegex(HistoryWindowStartsBeforeData, exp_msg):
20442044
self.data_portal.get_history_window(
20452045
[self.ASSET1],
20462046
second_day,
@@ -2054,7 +2054,7 @@ def test_history_window_before_first_trading_day(self):
20542054
first_minute = \
20552055
self.trading_calendar.schedule.market_open[self.TRADING_START_DT]
20562056

2057-
with self.assertRaisesRegexp(HistoryWindowStartsBeforeData, exp_msg):
2057+
with self.assertRaisesRegex(HistoryWindowStartsBeforeData, exp_msg):
20582058
self.data_portal.get_history_window(
20592059
[self.ASSET2],
20602060
first_minute,

zipline/testing/fixtures.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from logbook import NullHandler, Logger
88
import numpy as np
99
import pandas as pd
10-
from six import with_metaclass, iteritems, itervalues
10+
from six import with_metaclass, iteritems, itervalues, PY2
1111
import responses
1212
from toolz import flip, groupby, merge
1313
from trading_calendars import (
@@ -251,6 +251,10 @@ def add_instance_callback(self, callback):
251251
"""
252252
return self._instance_teardown_stack.callback(callback)
253253

254+
if PY2:
255+
def assertRaisesRegex(self, *args, **kwargs):
256+
return self.assertRaisesRegexp(*args, **kwargs)
257+
254258

255259
def alias(attr_name):
256260
"""Make a fixture attribute an alias of another fixture's attribute by

0 commit comments

Comments
 (0)