def test_oracledatasource_notimplemented(user_pw, oracledatasource_cfg_and_data): cfg, dbms_cfg, _ = oracledatasource_cfg_and_data() ora_mock = mock.MagicMock() sys.modules["cx_Oracle"] = ora_mock ds = mllp_ds.OracleDataSource("bla", cfg, dbms_cfg) with pytest.raises(NotImplementedError, match="get_dataframe"): ds.get_raw() del sys.modules["cx_Oracle"]
def test_oracledatasource_df(user_pw, pd_read, oracledatasource_cfg_and_data): """OracleDataSource should connect, read dataframe and return it unaltered.""" cfg, dbms_cfg, data = oracledatasource_cfg_and_data() ora_mock = mock.MagicMock() sys.modules["cx_Oracle"] = ora_mock pd_read.return_value = data ds = mllp_ds.OracleDataSource("bla", cfg, dbms_cfg) df = ds.get_dataframe() pd.testing.assert_frame_equal(df, data) ora_mock.connect.assert_called_once() pd_read.assert_called_once() del sys.modules["cx_Oracle"]
def test_oracledatasource_df_chunksize(user_pw, pd_read, oracledatasource_cfg_and_data): """OracleDataSource with chunksize should return generator.""" cfg, dbms_cfg, full_data = oracledatasource_cfg_and_data() iter_data = [full_data.iloc[:2, :].copy(), full_data.iloc[2:, :].copy()] ora_mock = mock.MagicMock() sys.modules["cx_Oracle"] = ora_mock pd_read.return_value = iter_data ds = mllp_ds.OracleDataSource("bla", cfg, dbms_cfg) df_gen = ds.get_dataframe(chunksize=2) for df, orig in zip(df_gen, iter_data): pd.testing.assert_frame_equal(df, orig) del sys.modules["cx_Oracle"]
def test_oracledatasource_regression_nas_issue86( user_pw, pd_read, values, expected, oracledatasource_cfg_and_data): """ OracleDataSource should connect, read dataframe and return it unaltered with the exception of None values --> they should be converted to np.nan. """ cfg, dbms_cfg, _ = oracledatasource_cfg_and_data() ora_mock = mock.MagicMock() sys.modules["cx_Oracle"] = ora_mock pd_read.return_value = values ds = mllp_ds.OracleDataSource("bla", cfg, dbms_cfg) df = ds.get_dataframe() pd.testing.assert_frame_equal(df, expected) # assert df == expected ora_mock.connect.assert_called_once() pd_read.assert_called_once() del sys.modules["cx_Oracle"]