From 65d919da06152feaef7ce20d6b9e6ef9a0354d9b Mon Sep 17 00:00:00 2001 From: Martin Bubel Date: Tue, 10 Oct 2023 19:49:25 +0200 Subject: [PATCH] migrate prior_tests to pytest --- GPy/testing/prior_tests.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/GPy/testing/prior_tests.py b/GPy/testing/prior_tests.py index 4821584c..eb12a8d1 100644 --- a/GPy/testing/prior_tests.py +++ b/GPy/testing/prior_tests.py @@ -1,12 +1,11 @@ # Copyright (c) 2012, GPy authors (see AUTHORS.txt). # Licensed under the BSD 3-clause license (see LICENSE.txt) - -import unittest +import pytest import numpy as np import GPy -class PriorTests(unittest.TestCase): +class TestPrior: def test_studentT(self): xmin, xmax = 1, 2.5 * np.pi b, C, SNR = 1, 0, 0.1 @@ -21,14 +20,16 @@ class PriorTests(unittest.TestCase): # setting a StudentT prior on non-negative parameters # should raise an assertionerror. - self.assertRaises(AssertionError, m.rbf.set_prior, studentT) + + with pytest.raises(AssertionError): + m.rbf.set_prior(studentT) # The gradients need to be checked assert m.checkgrad() # Check the singleton pattern: - self.assertIs(studentT, GPy.priors.StudentT(1, 2, 4)) - self.assertIsNot(studentT, GPy.priors.StudentT(2, 2, 4)) + assert studentT is GPy.priors.StudentT(1, 2, 4) + assert studentT is not GPy.priors.StudentT(2, 2, 4) def test_lognormal(self): xmin, xmax = 1, 2.5 * np.pi @@ -82,7 +83,8 @@ class PriorTests(unittest.TestCase): gaussian = GPy.priors.Gaussian(1, 1) # setting a Gaussian prior on non-negative parameters # should raise an assertionerror. - self.assertRaises(AssertionError, m.rbf.set_prior, gaussian) + with pytest.raises(AssertionError): + m.rbf.set_prior(gaussian) def test_set_prior(self): xmin, xmax = 1, 2.5 * np.pi @@ -97,7 +99,8 @@ class PriorTests(unittest.TestCase): # m.rbf.set_prior(gaussian) # setting a Gaussian prior on non-negative parameters # should raise an assertionerror. - self.assertRaises(AssertionError, m.rbf.set_prior, gaussian) + with pytest.raises(AssertionError): + m.rbf.set_prior(gaussian) def test_uniform(self): xmin, xmax = 1, 2.5 * np.pi @@ -157,7 +160,8 @@ class PriorTests(unittest.TestCase): gaussian = GPy.priors.Gaussian(1, 1) # setting a Gaussian prior on non-negative parameters # should raise an assertionerror. - self.assertRaises(AssertionError, m.rbf.set_prior, gaussian) + with pytest.raises(AssertionError): + m.rbf.set_prior(gaussian) def test_fixed_domain_check1(self): xmin, xmax = 1, 2.5 * np.pi @@ -172,9 +176,5 @@ class PriorTests(unittest.TestCase): gaussian = GPy.priors.Gaussian(1, 1) # setting a Gaussian prior on non-negative parameters # should raise an assertionerror. - self.assertRaises(AssertionError, m.rbf.set_prior, gaussian) - - -if __name__ == "__main__": - print("Running unit tests, please be (very) patient...") - unittest.main() + with pytest.raises(AssertionError): + m.rbf.set_prior(gaussian)