From 94f350b8e780f3886ec5e032ed1baade1c6d64c6 Mon Sep 17 00:00:00 2001 From: Maksym Balatsko Date: Tue, 19 Sep 2023 10:04:07 +0200 Subject: [PATCH] migrate from nose to pytest --- pykalman/sqrt/tests/test_unscented.py | 6 ++--- pykalman/tests/test_standard.py | 27 ++++++++++------------ pykalman/tests/test_unscented.py | 32 ++++++++++----------------- pyproject.toml | 4 ++-- 4 files changed, 28 insertions(+), 41 deletions(-) diff --git a/pykalman/sqrt/tests/test_unscented.py b/pykalman/sqrt/tests/test_unscented.py index 1e40acc..55cb739 100644 --- a/pykalman/sqrt/tests/test_unscented.py +++ b/pykalman/sqrt/tests/test_unscented.py @@ -3,8 +3,6 @@ from numpy.testing import assert_array_almost_equal from scipy import linalg -from nose.tools import assert_true - from pykalman.sqrt import AdditiveUnscentedKalmanFilter from pykalman.sqrt.unscented import cholupdate, qr @@ -46,8 +44,8 @@ def test_additive_sample(): kf = build_unscented_filter(AdditiveUnscentedKalmanFilter) (x, z) = kf.sample(100) - assert_true(x.shape == (100, 2)) - assert_true(z.shape == (100, 1)) + assert x.shape == (100, 2) + assert z.shape == (100, 1) def test_additive_filter(): diff --git a/pykalman/tests/test_standard.py b/pykalman/tests/test_standard.py index cedc526..76fd865 100644 --- a/pykalman/tests/test_standard.py +++ b/pykalman/tests/test_standard.py @@ -5,7 +5,6 @@ import numpy as np from numpy.testing import assert_array_almost_equal from scipy import linalg -from nose.tools import assert_true from pykalman import KalmanFilter from pykalman.datasets import load_robot @@ -29,8 +28,8 @@ def test_kalman_sampling(self): self.data.initial_state_covariance) (x, z) = kf.sample(100) - assert_true(x.shape == (100, self.data.transition_matrix.shape[0])) - assert_true(z.shape == (100, self.data.observation_matrix.shape[0])) + assert x.shape == (100, self.data.transition_matrix.shape[0]) + assert z.shape == (100, self.data.observation_matrix.shape[0]) def test_kalman_filter_update(self): kf = self.KF( @@ -128,7 +127,7 @@ def test_kalman_fit(self): loglikelihoods[i] = kf.loglikelihood(self.data.observations) kf.em(X=self.data.observations, n_iter=1) - assert_true(np.allclose(loglikelihoods, self.data.loglikelihoods[:5])) + assert (np.allclose(loglikelihoods, self.data.loglikelihoods[:5])).all() # check that EM for all parameters is working kf.em_vars = 'all' @@ -137,7 +136,7 @@ def test_kalman_fit(self): kf.em(X=self.data.observations[0:n_timesteps], n_iter=1) loglikelihoods[i] = kf.loglikelihood(self.data.observations[0:n_timesteps]) for i in range(len(loglikelihoods) - 1): - assert_true(loglikelihoods[i] < loglikelihoods[i + 1]) + assert (loglikelihoods[i] < loglikelihoods[i + 1]).all() def test_kalman_initialize_parameters(self): self.check_dims(5, 1, {'transition_matrices': np.eye(5)}) @@ -154,16 +153,14 @@ def check_dims(self, n_dim_state, n_dim_obs, kwargs): initial_state_mean, initial_state_covariance) = ( kf._initialize_parameters() ) - assert_true(transition_matrices.shape == (n_dim_state, n_dim_state)) - assert_true(transition_offsets.shape == (n_dim_state,)) - assert_true(transition_covariance.shape == (n_dim_state, n_dim_state)) - assert_true(observation_matrices.shape == (n_dim_obs, n_dim_state)) - assert_true(observation_offsets.shape == (n_dim_obs,)) - assert_true(observation_covariance.shape == (n_dim_obs, n_dim_obs)) - assert_true(initial_state_mean.shape == (n_dim_state,)) - assert_true( - initial_state_covariance.shape == (n_dim_state, n_dim_state) - ) + assert transition_matrices.shape == (n_dim_state, n_dim_state) + assert transition_offsets.shape == (n_dim_state,) + assert transition_covariance.shape == (n_dim_state, n_dim_state) + assert observation_matrices.shape == (n_dim_obs, n_dim_state) + assert observation_offsets.shape == (n_dim_obs,) + assert observation_covariance.shape == (n_dim_obs, n_dim_obs) + assert initial_state_mean.shape == (n_dim_state,) + assert initial_state_covariance.shape == (n_dim_state, n_dim_state) def test_kalman_pickle(self): kf = self.KF( diff --git a/pykalman/tests/test_unscented.py b/pykalman/tests/test_unscented.py index 8e055ad..47cf150 100644 --- a/pykalman/tests/test_unscented.py +++ b/pykalman/tests/test_unscented.py @@ -4,8 +4,6 @@ from numpy import ma from numpy.testing import assert_array_almost_equal -from nose.tools import assert_true - from pykalman import AdditiveUnscentedKalmanFilter, UnscentedKalmanFilter from pykalman.datasets import load_robot @@ -56,38 +54,32 @@ def check_dims(n_dim_state, n_dim_obs, n_func_args, kf_cls, kwargs): kf._initialize_parameters() ) - assert_true( + assert ( transition_functions.shape == (1,) if not 'transition_functions' in kwargs else (len(kwargs['transition_functions']),) ) - assert_true( - all([len(inspect.getargspec(f).args) == n_func_args + assert all([len(inspect.getargspec(f).args) == n_func_args for f in transition_functions]) - ) - assert_true(transition_covariance.shape == (n_dim_state, n_dim_state)) - assert_true( + assert transition_covariance.shape == (n_dim_state, n_dim_state) + assert ( observation_functions.shape == (1,) if not 'observation_functions' in kwargs else (len(kwargs['observation_functions']),) ) - assert_true( - all([len(inspect.getargspec(f).args) == n_func_args + assert all([len(inspect.getargspec(f).args) == n_func_args for f in observation_functions]) - ) - assert_true(observation_covariance.shape == (n_dim_obs, n_dim_obs)) - assert_true(initial_state_mean.shape == (n_dim_state,)) - assert_true( - initial_state_covariance.shape == (n_dim_state, n_dim_state) - ) + assert observation_covariance.shape == (n_dim_obs, n_dim_obs) + assert initial_state_mean.shape == (n_dim_state,) + assert initial_state_covariance.shape == (n_dim_state, n_dim_state) def test_unscented_sample(): kf = build_unscented_filter(UnscentedKalmanFilter) (x, z) = kf.sample(100) - assert_true(x.shape == (100, 2)) - assert_true(z.shape == (100, 1)) + assert x.shape == (100, 2) + assert z.shape == (100, 1) def test_unscented_filter(): @@ -157,8 +149,8 @@ def test_additive_sample(): kf = build_unscented_filter(AdditiveUnscentedKalmanFilter) (x, z) = kf.sample(100) - assert_true(x.shape == (100, 2)) - assert_true(z.shape == (100, 1)) + assert x.shape == (100, 2) + assert z.shape == (100, 1) def test_additive_filter(): diff --git a/pyproject.toml b/pyproject.toml index 80057c4..49664e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ [project.optional-dependencies] tests = [ - "nose" + "pytest" ] docs = [ @@ -38,7 +38,7 @@ docs = [ ] all = [ - "nose", + "pytest", "Sphinx", "numpydoc" ]