Skip to content

Commit c49e9c9

Browse files
committed
Fix tests broken due to pytest-dev/pytest#5412
This breaks our tests as we use str(e) everywhere and as the above PR changes the behaviour of str to be the same as repr which is top print the Exception info Object, it breaks our tests.
1 parent 17ecdff commit c49e9c9

12 files changed

+39
-39
lines changed

tests/integration/chunkstore/test_chunkstore.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -664,19 +664,19 @@ def test_read_chunk_range(chunkstore_lib):
664664
def test_read_data_doesnt_exist(chunkstore_lib):
665665
with pytest.raises(NoDataFoundException) as e:
666666
chunkstore_lib.read('some_data')
667-
assert('No data found' in str(e))
667+
assert('No data found' in str(e.value))
668668

669669

670670
def test_invalid_type(chunkstore_lib):
671671
with pytest.raises(Exception) as e:
672672
chunkstore_lib.write('some_data', str("Cannot write a string"), 'D')
673-
assert('Can only chunk DataFrames' in str(e))
673+
assert('Can only chunk DataFrames' in str(e.value))
674674

675675

676676
def test_append_no_data(chunkstore_lib):
677677
with pytest.raises(NoDataFoundException) as e:
678678
chunkstore_lib.append('some_data', DataFrame())
679-
assert('Symbol does not exist.' in str(e))
679+
assert('Symbol does not exist.' in str(e.value))
680680

681681

682682
def test_append_upsert(chunkstore_lib):
@@ -849,11 +849,11 @@ def test_rename(chunkstore_lib):
849849

850850
with pytest.raises(Exception) as e:
851851
chunkstore_lib.rename('new_name', 'new_name')
852-
assert('already exists' in str(e))
852+
assert('already exists' in str(e.value))
853853

854854
with pytest.raises(NoDataFoundException) as e:
855855
chunkstore_lib.rename('doesnt_exist', 'temp')
856-
assert('No data found for doesnt_exist' in str(e))
856+
assert('No data found for doesnt_exist' in str(e.value))
857857

858858
assert('test' not in chunkstore_lib.list_symbols())
859859

@@ -1012,7 +1012,7 @@ def test_unnamed_colums(chunkstore_lib):
10121012
)
10131013
with pytest.raises(Exception) as e:
10141014
chunkstore_lib.write('test_df', df, chunk_size='D')
1015-
assert('must be named' in str(e))
1015+
assert('must be named' in str(e.value))
10161016

10171017
df = DataFrame(data={None: [1, 2, 3]},
10181018
index=MultiIndex.from_tuples([(dt(2016, 1, 1), 1),
@@ -1022,7 +1022,7 @@ def test_unnamed_colums(chunkstore_lib):
10221022
)
10231023
with pytest.raises(Exception) as e:
10241024
chunkstore_lib.write('test_df', df, chunk_size='D')
1025-
assert('must be named' in str(e))
1025+
assert('must be named' in str(e.value))
10261026

10271027

10281028
def test_quarterly_data(chunkstore_lib):

tests/integration/test_arctic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_lib_rename(arctic):
191191
assert(l.read('test_data').data == 'abc')
192192
with pytest.raises(LibraryNotFoundException) as e:
193193
l = arctic['test']
194-
assert('Library test' in str(e))
194+
assert('Library test' in str(e.value))
195195
assert('test' not in arctic.list_libraries())
196196

197197

@@ -202,15 +202,15 @@ def test_lib_rename_namespace(arctic):
202202

203203
with pytest.raises(ValueError) as e:
204204
arctic.rename_library('namespace.test', 'new_namespace.test')
205-
assert('Collection can only be renamed in the same database' in str(e))
205+
assert('Collection can only be renamed in the same database' in str(e.value))
206206

207207
arctic.rename_library('namespace.test', 'namespace.newlib')
208208
l = arctic['namespace.newlib']
209209
assert(l.read('test_data').data == 'abc')
210210

211211
with pytest.raises(LibraryNotFoundException) as e:
212212
l = arctic['namespace.test']
213-
assert('Library namespace.test' in str(e))
213+
assert('Library namespace.test' in str(e.value))
214214
assert('namespace.test' not in arctic.list_libraries())
215215

216216

tests/integration/test_compress_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def test_exceptions():
6565
data = data[0:16]
6666
with pytest.raises(Exception) as e:
6767
c.decompress(data)
68-
assert("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower())
68+
assert("decompressor wrote" in str(e.value).lower() or "corrupt input at" in str(e.value).lower() or "decompression failed: corrupt input" in str(e.value).lower())
6969

7070
data = c.compress(b'1010101010100000000000000000000000000000000000000000000000000000000011111111111111111111111111111')
7171
data = [data[0:16] for x in (1, 2, 3)]
7272
with pytest.raises(Exception) as e:
7373
c.decompress_array(data)
74-
assert ("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower())
74+
assert ("decompressor wrote" in str(e.value).lower() or "corrupt input at" in str(e.value).lower() or "decompression failed: corrupt input" in str(e.value).lower())

tests/integration/tickstore/test_toplevel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_should_raise_exceptions_if_no_libraries_are_found_in_the_date_range_whe
4545
'library_name': 'FEED_2010.LEVEL1'})
4646
with pytest.raises(NoDataFoundException) as e:
4747
toplevel_tickstore.read('blah', DateRange(start=dt(2012, 1, 1), end=dt(2012, 3, 1)))
48-
assert "No underlying libraries exist for the given date range" in str(e)
48+
assert "No underlying libraries exist for the given date range" in str(e.value)
4949

5050

5151
def test_should_return_data_when_date_range_falls_in_a_single_underlying_library(toplevel_tickstore, arctic):
@@ -118,7 +118,7 @@ def test_should_raise_exception_if_library_does_not_exist(toplevel_tickstore):
118118
with pytest.raises(LibraryNotFoundException) as e:
119119
toplevel_tickstore.add(DateRange(start=dt(2010, 1, 1), end=dt(2010, 12, 31, 23, 59, 59, 999000)), 'FEED_2010.LEVEL1')
120120
assert toplevel_tickstore._collection.find_one({'library_name': 'FEED_2010.LEVEL1'})
121-
assert "Library FEED_2010.LEVEL1 was not correctly initialized" in str(e)
121+
assert "Library FEED_2010.LEVEL1 was not correctly initialized" in str(e.value)
122122

123123

124124
def test_should_raise_exception_if_date_range_for_library_overlaps_with_existing_libraries(toplevel_tickstore, arctic):
@@ -127,7 +127,7 @@ def test_should_raise_exception_if_date_range_for_library_overlaps_with_existing
127127
with pytest.raises(OverlappingDataException) as e:
128128
toplevel_tickstore.add(DateRange(start=dt(2010, 6, 1), end=dt(2010, 12, 31, 23, 59, 59, 999000)), 'FEED_2010a.LEVEL1')
129129
assert toplevel_tickstore._collection.find_one({'library_name': 'FEED_2010.LEVEL1'})
130-
assert "There are libraries that overlap with the date range:" in str(e)
130+
assert "There are libraries that overlap with the date range:" in str(e.value)
131131

132132

133133
def test_should_successfully_do_a_roundtrip_write_and_read_spanning_multiple_underlying_libraries(toplevel_tickstore, arctic):

tests/integration/tickstore/test_ts_read.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,4 @@ def fake(self):
701701

702702
with pytest.raises(Exception) as e:
703703
tickstore_lib.write('test', df)
704-
assert('Casting object column to string failed' in str(e))
704+
assert('Casting object column to string failed' in str(e.value))

tests/unit/chunkstore/test_date_chunker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def test_to_chunks_exceptions():
7979

8080
with pytest.raises(Exception) as e:
8181
six.next(c.to_chunks(df, 'D'))
82-
assert('datetime indexed' in str(e))
82+
assert('datetime indexed' in str(e.value))
8383

8484
df.columns = ['date']
8585
with pytest.raises(Exception) as e:
8686
six.next(c.to_chunks(df, 'ZSDFG'))
87-
assert('Unknown freqstr' in str(e) or 'Invalid frequency' in str(e))
87+
assert('Unknown freqstr' in str(e.value) or 'Invalid frequency' in str(e.value))
8888

8989

9090
def test_exclude():

tests/unit/serialization/test_numpy_arrays.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_multi_column_fail():
9191

9292
with pytest.raises(Exception) as e:
9393
n.deserialize(a, columns=['A', 'B'])
94-
assert('Duplicate' in str(e))
94+
assert('Duplicate' in str(e.value))
9595

9696

9797
def test_dataframe_writable_after_objify():

tests/unit/store/test_pickle_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,4 @@ def test_pickle_store_future_version():
171171
ps = PickleStore()
172172
with pytest.raises(UnsupportedPickleStoreVersion) as e:
173173
ps.read(arctic_lib, version, sentinel.symbol)
174-
assert('unsupported version of pickle store' in str(e))
174+
assert('unsupported version of pickle store' in str(e.value))

tests/unit/store/test_version_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_read_reports_random_errors():
245245
with pytest.raises(Exception) as e:
246246
with patch('arctic.store.version_store.log_exception') as le:
247247
VersionStore.read(self, sentinel.symbol, sentinel.as_of, sentinel.from_version)
248-
assert 'bad' in str(e)
248+
assert 'bad' in str(e.value)
249249
assert le.call_count == 1
250250

251251

tests/unit/test_arctic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class DummyType(object):
182182

183183
with pytest.raises(ArcticException) as e:
184184
register_library_type("new_dummy_type", DummyType)
185-
assert "ArcticException: Library new_dummy_type already registered" in str(e)
185+
assert "Library new_dummy_type already registered" in str(e.value)
186186

187187

188188
def test_set_quota():
@@ -301,7 +301,7 @@ def test_check_quota_exceeded():
301301
}))
302302
with pytest.raises(QuotaExceededException) as e:
303303
ArcticLibraryBinding.check_quota(self)
304-
assert "Quota Exceeded: arctic_db.lib 1.000 / 1 GB used" in str(e)
304+
assert "Quota Exceeded: arctic_db.lib 1.000 / 1 GB used" in str(e.value)
305305

306306

307307
def test_initialize_library():
@@ -336,7 +336,7 @@ def test_initialize_library_too_many_ns():
336336
assert self._conn.__getitem__.call_args_list == [call(sentinel.db_name),
337337
call(sentinel.db_name)]
338338
assert lib_type.initialize_library.call_count == 0
339-
assert 'Too many namespaces 5001, not creating: sentinel.lib_name' in str(e)
339+
assert 'Too many namespaces 5001, not creating: sentinel.lib_name' in str(e.value)
340340

341341

342342
def test_initialize_library_with_list_coll_names():
@@ -391,7 +391,7 @@ def test_get_library_not_initialized():
391391
patch('arctic.arctic.ArcticLibraryBinding', autospec=True) as ML:
392392
ML.return_value.get_library_type.return_value = None
393393
Arctic.get_library(self, sentinel.lib_name)
394-
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e)
394+
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e.value)
395395

396396

397397
def test_get_library_auth_issue():
@@ -401,7 +401,7 @@ def test_get_library_auth_issue():
401401
patch('arctic.arctic.ArcticLibraryBinding', autospec=True) as ML:
402402
ML.return_value.get_library_type.side_effect = OperationFailure('database error: not authorized for query on arctic_marketdata.index.ARCTIC')
403403
Arctic.get_library(self, sentinel.lib_name)
404-
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e)
404+
assert "Library %s was not correctly initialized in %s." % (sentinel.lib_name, self) in str(e.value)
405405

406406

407407
def test_get_library_not_registered():
@@ -413,7 +413,7 @@ def test_get_library_not_registered():
413413
Arctic.get_library(self, sentinel.lib_name)
414414
assert ("Couldn't load LibraryType '%s' for '%s' (has the class been registered?)" %
415415
(sentinel.lib_type, sentinel.lib_name)
416-
)in str(e)
416+
)in str(e.value)
417417

418418

419419
def test_mongo_host_get_set():

tests/unit/test_decorators_unit.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def foo():
100100
foo = mongo_retry(foo)
101101
with pytest.raises(Exception) as e:
102102
foo()
103-
assert "Unexpected Error" in str(e)
103+
assert "Unexpected Error" in str(e.value)
104104
assert le.call_count == 1
105105
assert le.call_args[0][0] == "foo"
106106

@@ -112,7 +112,7 @@ def foo():
112112
raise Exception("Unexpected Error")
113113
with pytest.raises(Exception) as e:
114114
foo()
115-
assert "Unexpected Error" in str(e)
115+
assert "Unexpected Error" in str(e.value)
116116
assert le.call_count == 0
117117

118118

@@ -125,7 +125,7 @@ def foo():
125125
raise error
126126
with pytest.raises(OperationFailure) as e:
127127
foo()
128-
assert 'OperationFailure: unauthorized for db:arctic_jblackburn' in str(e)
128+
assert 'OperationFailure: unauthorized for db:arctic_jblackburn' in str(e.value)
129129
assert le.call_count == 1
130130

131131

@@ -137,7 +137,7 @@ def foo():
137137
raise error
138138
with pytest.raises(OperationFailure) as e:
139139
foo()
140-
assert 'duplicate key' in str(e)
140+
assert 'duplicate key' in str(e.value)
141141
assert le.call_count == 1
142142

143143

@@ -149,7 +149,7 @@ def foo():
149149
raise error
150150
with pytest.raises(ServerSelectionTimeoutError) as e:
151151
foo()
152-
assert 'some error' in str(e)
152+
assert 'some error' in str(e.value)
153153
assert le.call_count == 1
154154

155155

tests/unit/tickstore/test_toplevel.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ def test_raise_exception_if_daterange_is_not_provided():
2424
store = TopLevelTickStore(Mock())
2525
with pytest.raises(Exception) as e:
2626
store._get_library_metadata(None)
27-
assert "A date range must be provided" in str(e)
27+
assert "A date range must be provided" in str(e.value)
2828

2929

3030
def test_raise_exception_if_date_range_does_not_contain_start_date():
3131
store = TopLevelTickStore(Mock())
3232
dr = DateRange(start=None, end=dt(2011, 1, 1))
3333
with pytest.raises(Exception) as e:
3434
store._get_library_metadata(dr)
35-
assert "The date range {0} must contain a start and end date".format(dr) in str(e)
35+
assert "The date range {0} must contain a start and end date".format(dr) in str(e.value)
3636

3737

3838
def test_raise_exception_if_date_range_does_not_contain_end_date():
3939
store = TopLevelTickStore(Mock())
4040
dr = DateRange(start=dt(2011, 1, 1), end=None)
4141
with pytest.raises(Exception) as e:
4242
store._get_library_metadata(dr)
43-
assert "The date range {0} must contain a start and end date".format(dr) in str(e)
43+
assert "The date range {0} must contain a start and end date".format(dr) in str(e.value)
4444

4545

4646
def test_raise_exception_if_date_range_does_not_contain_start_and_end_date():
4747
store = TopLevelTickStore(Mock())
4848
dr = DateRange(start=None, end=None)
4949
with pytest.raises(Exception) as e:
5050
store._get_library_metadata(dr)
51-
assert "The date range {0} must contain a start and end date".format(dr) in str(e)
51+
assert "The date range {0} must contain a start and end date".format(dr) in str(e.value)
5252

5353

5454
def test_raise_exception_and_log_an_error_if_an_invalid_library_name_is_added():
@@ -66,7 +66,7 @@ def test_raise_exception_if_date_range_overlaps():
6666
self._get_library_metadata.return_value = [TickStoreLibrary('lib1', None), ]
6767
with pytest.raises(OverlappingDataException) as e:
6868
TopLevelTickStore.add(self, DateRange(start=dt(2010, 1, 1), end=dt(2011, 1, 1, 23, 59, 59, 999000)), "blah")
69-
assert "There are libraries that overlap with the date range:" in str(e)
69+
assert "There are libraries that overlap with the date range:" in str(e.value)
7070

7171

7272
@pytest.mark.parametrize(('start', 'end', 'expected_start', 'expected_end'),
@@ -103,7 +103,7 @@ def test_raise_error_add_library_is_called_with_a_date_range_not_on_day_boundari
103103
self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock(), _collection=MagicMock())
104104
self._get_library_metadata.return_value = []
105105
TopLevelTickStore.add(self, DateRange(start=start, end=end), "blah")
106-
assert "Date range should fall on UTC day boundaries" in str(e)
106+
assert "Date range should fall on UTC day boundaries" in str(e.value)
107107

108108

109109
@pytest.mark.parametrize(('start', 'end', 'expected_start_index', 'expected_end_index'),
@@ -179,4 +179,4 @@ def test_slice_raises():
179179
m = TopLevelTickStore(Mock())
180180
with pytest.raises(UnhandledDtypeException) as e:
181181
m._slice("abc", 1, 2)
182-
assert("Can't persist type" in str(e))
182+
assert("Can't persist type" in str(e.value))

0 commit comments

Comments
 (0)