def test_bad_arguments(self): # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: plot_similarity(setup_pd(), setup_np(), setup_np(), test=True) expected_error_msg = "Similarity matrix type is not np.ndarray." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg) # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: plot_similarity(setup_np(), setup_pd(), setup_np(), test=True) expected_error_msg = "Novelty score array type is not np.ndarray." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_calculate_similarity(self): """ Test calculate_similarity function. The test fails when: - Given array is not a numpy array - Given array is not 2 dimensional Returns ------- None. """ test_argument = setup_pd() # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: calculate_similarity(test_argument) expected_error_msg = "Data format is not a numpy array." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg) test_argument2 = setup_np() # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: calculate_similarity(test_argument2) expected_error_msg = "Matrix is not 2 dimensional." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_STL_decomposition(self): """ Test STL_decomposition function. Test passes with proper arguments and raises an AssertionError if the input time series is not numpy array. Returns ------- None. """ res = STL_decomposition(setup_np(), 'Test title', test=True) assert res is not None assert res.observed.all() is not None assert res.trend.all() is not None assert res.seasonal.all() is not None assert res.resid.all() is not None test_argument = setup_pd() # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: STL_decomposition(test_argument, 'Test title', test=True) expected_error_msg = "Series is not a numpy array." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_setup_pd(self): """ Test that setup_pd function returns a pandas dataframe Returns ------- None. """ test_argument = setup_pd() assert isinstance(test_argument, pd.DataFrame)
def test_rolling_statistics(self): """ Test with proper arguments. Returns ------- None. """ test_argument = setup_pd() test_argument = test_argument['level'].to_frame() res = rolling_statistics(test_argument, w = 7, savename = False, savepath = False, test = True) print(type(res)) assert res is not None, 'Function returned a None object.'
def test_process_decorator(self): @process_decorator def summary(df,name): ser = df[name] _ = summary_statistics.summary_statistics(ser, "{} summary".format(name), window = 14, savepath = False, savename = False, test = False) df = setup_pd() cols = ['level'] summary(df,cols)
def test_doi2int(self): """ Test with proper arguments. Returns ------- None. """ df = setup_pd() test_argument = (2011, 3, 1), (2011, 6, 1) a, b = doi2index(test_argument, df) assert a == pytest.approx(4478.12331851853) assert b == pytest.approx(4570.12331851853)
def test_rolling_statistics_long_window(self): """ Given too large window size, Rolling_statistics raises an error. Returns ------- None. """ test_argument = setup_pd() # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: rolling_statistics(test_argument,w=10000000) expected_error_msg = "Window length is larger than the time series length." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_rolling_statistics_w(self): """ Given window size as a string, Rolling_statistics raises an error. Returns ------- None. """ test_argument = setup_pd() # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: rolling_statistics(test_argument,w=str(7)) expected_error_msg = "Window size is not an integer." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_plot_decorator(self): df = setup_pd() name = ['level'] _ = plot_timeseries(df, name, title = "test title", roll = False, xlab = "Time", ylab = "Value", ylim = False, savename = False, savepath = False, highlight = False, test=True )
def test_summary_statistics(self): """ Test Summary_statistics function. Test that Pandas data frame as an argument raises an error. Returns ------- None. """ # Store information about raised ValueError in exc_info with pytest.raises(AssertionError) as exc_info: summary_statistics(setup_pd(), 'Test title', savepath=False, savename=False, test=True) expected_error_msg = "Series is not a pandas Series." # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)