Skip to content

Commit

Permalink
Merge pull request #797 from shashank88/fix_tests_py3
Browse files Browse the repository at this point in the history
Fix tests broken due to pytest-dev/pytest#5412
  • Loading branch information
shashank88 authored Jul 5, 2019
2 parents 17ecdff + c49e9c9 commit 9fe59ef
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions tests/integration/chunkstore/test_chunkstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,19 +664,19 @@ def test_read_chunk_range(chunkstore_lib):
def test_read_data_doesnt_exist(chunkstore_lib):
with pytest.raises(NoDataFoundException) as e:
chunkstore_lib.read('some_data')
assert('No data found' in str(e))
assert('No data found' in str(e.value))


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


def test_append_no_data(chunkstore_lib):
with pytest.raises(NoDataFoundException) as e:
chunkstore_lib.append('some_data', DataFrame())
assert('Symbol does not exist.' in str(e))
assert('Symbol does not exist.' in str(e.value))


def test_append_upsert(chunkstore_lib):
Expand Down Expand Up @@ -849,11 +849,11 @@ def test_rename(chunkstore_lib):

with pytest.raises(Exception) as e:
chunkstore_lib.rename('new_name', 'new_name')
assert('already exists' in str(e))
assert('already exists' in str(e.value))

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

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

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

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


def test_quarterly_data(chunkstore_lib):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_lib_rename(arctic):
assert(l.read('test_data').data == 'abc')
with pytest.raises(LibraryNotFoundException) as e:
l = arctic['test']
assert('Library test' in str(e))
assert('Library test' in str(e.value))
assert('test' not in arctic.list_libraries())


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

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

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

with pytest.raises(LibraryNotFoundException) as e:
l = arctic['namespace.test']
assert('Library namespace.test' in str(e))
assert('Library namespace.test' in str(e.value))
assert('namespace.test' not in arctic.list_libraries())


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_compress_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def test_exceptions():
data = data[0:16]
with pytest.raises(Exception) as e:
c.decompress(data)
assert("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower())
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())

data = c.compress(b'1010101010100000000000000000000000000000000000000000000000000000000011111111111111111111111111111')
data = [data[0:16] for x in (1, 2, 3)]
with pytest.raises(Exception) as e:
c.decompress_array(data)
assert ("decompressor wrote" in str(e).lower() or "corrupt input at" in str(e).lower() or "decompression failed: corrupt input" in str(e).lower())
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())
6 changes: 3 additions & 3 deletions tests/integration/tickstore/test_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_should_raise_exceptions_if_no_libraries_are_found_in_the_date_range_whe
'library_name': 'FEED_2010.LEVEL1'})
with pytest.raises(NoDataFoundException) as e:
toplevel_tickstore.read('blah', DateRange(start=dt(2012, 1, 1), end=dt(2012, 3, 1)))
assert "No underlying libraries exist for the given date range" in str(e)
assert "No underlying libraries exist for the given date range" in str(e.value)


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


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


def test_should_successfully_do_a_roundtrip_write_and_read_spanning_multiple_underlying_libraries(toplevel_tickstore, arctic):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tickstore/test_ts_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,4 @@ def fake(self):

with pytest.raises(Exception) as e:
tickstore_lib.write('test', df)
assert('Casting object column to string failed' in str(e))
assert('Casting object column to string failed' in str(e.value))
4 changes: 2 additions & 2 deletions tests/unit/chunkstore/test_date_chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def test_to_chunks_exceptions():

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

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


def test_exclude():
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/serialization/test_numpy_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_multi_column_fail():

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


def test_dataframe_writable_after_objify():
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/store/test_pickle_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ def test_pickle_store_future_version():
ps = PickleStore()
with pytest.raises(UnsupportedPickleStoreVersion) as e:
ps.read(arctic_lib, version, sentinel.symbol)
assert('unsupported version of pickle store' in str(e))
assert('unsupported version of pickle store' in str(e.value))
2 changes: 1 addition & 1 deletion tests/unit/store/test_version_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_read_reports_random_errors():
with pytest.raises(Exception) as e:
with patch('arctic.store.version_store.log_exception') as le:
VersionStore.read(self, sentinel.symbol, sentinel.as_of, sentinel.from_version)
assert 'bad' in str(e)
assert 'bad' in str(e.value)
assert le.call_count == 1


Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DummyType(object):

with pytest.raises(ArcticException) as e:
register_library_type("new_dummy_type", DummyType)
assert "ArcticException: Library new_dummy_type already registered" in str(e)
assert "Library new_dummy_type already registered" in str(e.value)


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


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


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


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


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


def test_mongo_host_get_set():
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_decorators_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def foo():
foo = mongo_retry(foo)
with pytest.raises(Exception) as e:
foo()
assert "Unexpected Error" in str(e)
assert "Unexpected Error" in str(e.value)
assert le.call_count == 1
assert le.call_args[0][0] == "foo"

Expand All @@ -112,7 +112,7 @@ def foo():
raise Exception("Unexpected Error")
with pytest.raises(Exception) as e:
foo()
assert "Unexpected Error" in str(e)
assert "Unexpected Error" in str(e.value)
assert le.call_count == 0


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


Expand All @@ -137,7 +137,7 @@ def foo():
raise error
with pytest.raises(OperationFailure) as e:
foo()
assert 'duplicate key' in str(e)
assert 'duplicate key' in str(e.value)
assert le.call_count == 1


Expand All @@ -149,7 +149,7 @@ def foo():
raise error
with pytest.raises(ServerSelectionTimeoutError) as e:
foo()
assert 'some error' in str(e)
assert 'some error' in str(e.value)
assert le.call_count == 1


Expand Down
14 changes: 7 additions & 7 deletions tests/unit/tickstore/test_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ def test_raise_exception_if_daterange_is_not_provided():
store = TopLevelTickStore(Mock())
with pytest.raises(Exception) as e:
store._get_library_metadata(None)
assert "A date range must be provided" in str(e)
assert "A date range must be provided" in str(e.value)


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


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


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


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


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


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

0 comments on commit 9fe59ef

Please sign in to comment.