コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    def test_doi2int_bad_arguments(self):

        test_argument = (2011, 3, 1), (2011, 6, 1)

        # Store information about raised ValueError in exc_info
        with pytest.raises(AssertionError) as exc_info:
            a, b = doi2index(test_argument, setup_np())
        expected_error_msg = "df is not a pandas dataframe."
        # 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:
            a, b = doi2index(123, setup_np())
        expected_error_msg = "Doi is not a tuple."
        # Check if the raised ValueError contains the correct message
        assert exc_info.match(expected_error_msg)
コード例 #5
0
    def test_setup_np(self):
        """
        Test that setup_pd function returns a numpy array.

        Returns
        -------
        None.

        """

        test_argument = setup_np()

        assert isinstance(test_argument, np.ndarray)
コード例 #6
0
    def test_STL_decomposition_proper(self):
        """ Test that the STL_decomposition returns something.
        

        Returns
        -------
        None.

        """

        test_argument = setup_np()
        res = STL_decomposition(test_argument, 'Test title', test=True)

        assert res is not None
コード例 #7
0
 def test_rolling_statistics_ts(self):
     """
     Given a numpy array, Rolling_statistics raises an error.
 
     Returns
     -------
     None.
 
     """
     test_argument = setup_np()
     # Store information about raised ValueError in exc_info
     with pytest.raises(AssertionError) as exc_info:
         rolling_statistics(test_argument,w=7)
     expected_error_msg = "Timeseries is not a pandas dataframe."
     # Check if the raised ValueError contains the correct message
     assert exc_info.match(expected_error_msg)
コード例 #8
0
    def test_plot_decomposition(self):
        """ Test that the _plot_decomposition returns something.
        

        Returns
        -------
        None.

        """

        test_argument = setup_np()
        res = STL_decomposition(test_argument, 'Test title', test=True)
        fig = _plot_decomposition(
            res,
            title="test",
            savepath=False,
            savename=False,
            dates=False,
            test=True,
        )
        assert fig is not None