mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
fix test errors after migration
This commit is contained in:
parent
cec7e999bb
commit
d77f140fec
10 changed files with 95 additions and 58 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
||||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
|
||||||
from . import core
|
from . import core
|
||||||
|
|
@ -18,30 +19,25 @@ from .util import normalizer
|
||||||
|
|
||||||
# backwards compatibility
|
# backwards compatibility
|
||||||
import sys
|
import sys
|
||||||
backwards_compatibility = ['lists_and_dicts', 'observable_array', 'index_operations']
|
|
||||||
|
backwards_compatibility = ["lists_and_dicts", "observable_array", "index_operations"]
|
||||||
for bc in backwards_compatibility:
|
for bc in backwards_compatibility:
|
||||||
sys.modules['GPy.core.parameterization.{!s}'.format(bc)] = getattr(core.parameterization, bc)
|
sys.modules["GPy.core.parameterization.{!s}".format(bc)] = getattr(
|
||||||
|
core.parameterization, bc
|
||||||
|
)
|
||||||
|
|
||||||
# Direct imports for convenience:
|
# Direct imports for convenience:
|
||||||
from .core import Model
|
from .core import Model
|
||||||
from .core.parameterization import priors
|
from .core.parameterization import priors
|
||||||
from .core.parameterization import Param, Parameterized, ObsAr, transformations as constraints
|
from .core.parameterization import (
|
||||||
|
Param,
|
||||||
|
Parameterized,
|
||||||
|
ObsAr,
|
||||||
|
transformations as constraints,
|
||||||
|
)
|
||||||
|
|
||||||
from .__version__ import __version__
|
from .__version__ import __version__
|
||||||
|
|
||||||
from numpy.testing import Tester
|
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.simplefilter('ignore')
|
|
||||||
try:
|
|
||||||
#Get rid of nose dependency by only ignoring if you have nose installed
|
|
||||||
from nose.tools import nottest
|
|
||||||
@nottest
|
|
||||||
def tests(verbose=10):
|
|
||||||
Tester(testing).test(verbose=verbose)
|
|
||||||
except:
|
|
||||||
def tests(verbose=10):
|
|
||||||
Tester(testing).test(verbose=verbose)
|
|
||||||
|
|
||||||
def load(file_or_path):
|
def load(file_or_path):
|
||||||
"""
|
"""
|
||||||
|
|
@ -52,10 +48,12 @@ def load(file_or_path):
|
||||||
# This is the pickling pain when changing _src -> src
|
# This is the pickling pain when changing _src -> src
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
sys.modules['GPy.kern._src'] = kern.src
|
|
||||||
|
sys.modules["GPy.kern._src"] = kern.src
|
||||||
for name, module in inspect.getmembers(kern.src):
|
for name, module in inspect.getmembers(kern.src):
|
||||||
if not name.startswith('_'):
|
if not name.startswith("_"):
|
||||||
sys.modules['GPy.kern._src.{}'.format(name)] = module
|
sys.modules["GPy.kern._src.{}".format(name)] = module
|
||||||
sys.modules['GPy.inference.optimization'] = inference.optimization
|
sys.modules["GPy.inference.optimization"] = inference.optimization
|
||||||
import paramz
|
import paramz
|
||||||
|
|
||||||
return paramz.load(file_or_path)
|
return paramz.load(file_or_path)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from nose.tools import with_setup
|
|
||||||
from GPy.models import GradientChecker
|
from GPy.models import GradientChecker
|
||||||
from GPy.likelihoods.noise_models import gp_transformations
|
from GPy.likelihoods.noise_models import gp_transformations
|
||||||
import inspect
|
import inspect
|
||||||
|
|
|
||||||
24
GPy/testing/move_files.py
Normal file
24
GPy/testing/move_files.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
python_files = [file for file in os.listdir() if file.endswith(".py")]
|
||||||
|
|
||||||
|
python_test_files = [file for file in python_files if "test" in file]
|
||||||
|
non_test_python_files = [file for file in python_files if "test" not in file]
|
||||||
|
print("Python Test Files: ", python_test_files)
|
||||||
|
|
||||||
|
print("Non-test Python Files:\n", non_test_python_files)
|
||||||
|
|
||||||
|
for file in python_test_files:
|
||||||
|
if file.endswith("_tests.py"):
|
||||||
|
test_name = file.split("_tests.py")[0]
|
||||||
|
elif file.endswith("_test.py"):
|
||||||
|
test_name = file.split("_test.py")[0]
|
||||||
|
else:
|
||||||
|
raise ValueError(f"File is not named as expected: {file}")
|
||||||
|
|
||||||
|
to_file = "test_" + test_name + ".py"
|
||||||
|
|
||||||
|
# print(" ".join(["git", "mv", "-f", file, to_file]))
|
||||||
|
subprocess.run(["git", "mv", "-f", file, to_file])
|
||||||
|
|
@ -24,7 +24,7 @@ These tests make sure that the pure python and cython codes work the same
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@pytest.skipIf(
|
@pytest.mark.skipif(
|
||||||
not choleskies_cython_working,
|
not choleskies_cython_working,
|
||||||
"Cython cholesky module has not been built on this machine",
|
"Cython cholesky module has not been built on this machine",
|
||||||
)
|
)
|
||||||
|
|
@ -44,7 +44,7 @@ class CythonTestChols:
|
||||||
assert np.allclose(A1, A2), "Flat mismatch!"
|
assert np.allclose(A1, A2), "Flat mismatch!"
|
||||||
|
|
||||||
|
|
||||||
@pytest.skipIf(
|
@pytest.mark.skipif(
|
||||||
not stationary_cython_working,
|
not stationary_cython_working,
|
||||||
"Cython stationary module has not been built on this machine",
|
"Cython stationary module has not been built on this machine",
|
||||||
)
|
)
|
||||||
|
|
@ -82,7 +82,7 @@ class TestStationary:
|
||||||
assert np.allclose(g1, g2), "Gradient mismatch on rect lengthscale!"
|
assert np.allclose(g1, g2), "Gradient mismatch on rect lengthscale!"
|
||||||
|
|
||||||
|
|
||||||
@pytest.skipIf(
|
@pytest.mark.skipif(
|
||||||
not choleskies_cython_working,
|
not choleskies_cython_working,
|
||||||
"Cython cholesky module has not been built on this machine",
|
"Cython cholesky module has not been built on this machine",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import unittest
|
|
||||||
import GPy
|
import GPy
|
||||||
from GPy.models import GradientChecker
|
|
||||||
|
|
||||||
|
|
||||||
fixed_seed = 10
|
fixed_seed = 10
|
||||||
|
|
@ -127,7 +126,7 @@ class TestObservationModels:
|
||||||
GPy.util.classification.conf_matrix(probs_mean_ep_alt, self.binary_Y)
|
GPy.util.classification.conf_matrix(probs_mean_ep_alt, self.binary_Y)
|
||||||
GPy.util.classification.conf_matrix(probs_mean_ep_nested, self.binary_Y)
|
GPy.util.classification.conf_matrix(probs_mean_ep_nested, self.binary_Y)
|
||||||
|
|
||||||
@pytest.skip(
|
@pytest.mark.skip(
|
||||||
"Fails as a consequence of fixing the DSYR function. Needs to be reviewed!"
|
"Fails as a consequence of fixing the DSYR function. Needs to be reviewed!"
|
||||||
)
|
)
|
||||||
def test_ep_with_studentt(self):
|
def test_ep_with_studentt(self):
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ from .state_space_main_tests import (
|
||||||
generate_brownian_data,
|
generate_brownian_data,
|
||||||
generate_linear_plus_sin,
|
generate_linear_plus_sin,
|
||||||
)
|
)
|
||||||
from nose import SkipTest
|
|
||||||
|
|
||||||
# from state_space_main_tests import generate_x_points, generate_sine_data, \
|
# from state_space_main_tests import generate_x_points, generate_sine_data, \
|
||||||
# generate_linear_data, generate_brownian_data, generate_linear_plus_sin
|
# generate_linear_data, generate_brownian_data, generate_linear_plus_sin
|
||||||
|
|
|
||||||
|
|
@ -870,7 +870,7 @@ class TestKernelNonContinuous:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.skipIf(
|
@pytest.mark.skipif(
|
||||||
not cython_coregionalize_working,
|
not cython_coregionalize_working,
|
||||||
"Cython coregionalize module has not been built on this machine",
|
"Cython coregionalize module has not been built on this machine",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class TestMisc:
|
||||||
Xp[:, 0] = Xp[:, 0] * 15 - 5
|
Xp[:, 0] = Xp[:, 0] * 15 - 5
|
||||||
Xp[:, 1] = Xp[:, 1] * 15
|
Xp[:, 1] = Xp[:, 1] * 15
|
||||||
_, var = m.predict(Xp)
|
_, var = m.predict(Xp)
|
||||||
assert np.all(var >= 0.0))
|
assert np.all(var >= 0.0)
|
||||||
|
|
||||||
def test_raw_predict(self):
|
def test_raw_predict(self):
|
||||||
self.setup()
|
self.setup()
|
||||||
|
|
|
||||||
|
|
@ -141,39 +141,42 @@ def _image_comparison(
|
||||||
if ext == "npz":
|
if ext == "npz":
|
||||||
|
|
||||||
def do_test():
|
def do_test():
|
||||||
with pytest.skip
|
with pytest.skip:
|
||||||
if not os.path.exists(expected):
|
if not os.path.exists(expected):
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
shutil.copy2(actual, expected)
|
shutil.copy2(actual, expected)
|
||||||
# shutil.copy2(os.path.join(result_dir, "{}.{}".format(base, 'png')), os.path.join(baseline_dir, "{}.{}".format(base, 'png')))
|
# shutil.copy2(os.path.join(result_dir, "{}.{}".format(base, 'png')), os.path.join(baseline_dir, "{}.{}".format(base, 'png')))
|
||||||
raise IOError(
|
raise IOError(
|
||||||
"Baseline file {} not found, copying result {}".format(
|
"Baseline file {} not found, copying result {}".format(
|
||||||
expected, actual
|
expected, actual
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
else:
|
exp_dict = dict(np.load(expected).items())
|
||||||
exp_dict = dict(np.load(expected).items())
|
act_dict = dict(np.load(actual).items())
|
||||||
act_dict = dict(np.load(actual).items())
|
for name in act_dict:
|
||||||
for name in act_dict:
|
if name in exp_dict:
|
||||||
if name in exp_dict:
|
try:
|
||||||
try:
|
np.testing.assert_allclose(
|
||||||
np.testing.assert_allclose(
|
exp_dict[name],
|
||||||
exp_dict[name],
|
act_dict[name],
|
||||||
act_dict[name],
|
err_msg="Mismatch in {}.{}".format(
|
||||||
err_msg="Mismatch in {}.{}".format(base, name),
|
base, name
|
||||||
rtol=rtol,
|
),
|
||||||
**kwargs
|
rtol=rtol,
|
||||||
)
|
**kwargs
|
||||||
except AssertionError as e:
|
)
|
||||||
pass
|
except AssertionError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def do_test():
|
def do_test():
|
||||||
err = compare_images(expected, actual, tol, in_decorator=True)
|
err = compare_images(expected, actual, tol, in_decorator=True)
|
||||||
if err:
|
if err:
|
||||||
print("Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(
|
print(
|
||||||
|
"Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(
|
||||||
actual, expected, err["rms"], tol
|
actual, expected, err["rms"], tol
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -319,6 +322,7 @@ def test_figure():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -363,6 +367,7 @@ def test_kernel():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -406,6 +411,7 @@ def test_plot():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -441,6 +447,7 @@ def test_twod():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -477,6 +484,7 @@ def test_threed():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -502,6 +510,7 @@ def test_sparse():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -534,6 +543,7 @@ def test_classification():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -564,6 +574,7 @@ def test_sparse_classification():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
@ -621,6 +632,7 @@ def test_gplvm():
|
||||||
):
|
):
|
||||||
yield (do_test,)
|
yield (do_test,)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
matplotlib is None or baseline_dir is None, reason="Matplotlib not installed"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,9 @@ class TestSerialization:
|
||||||
m2_r = GPy.models.GPClassification.load_model(
|
m2_r = GPy.models.GPClassification.load_model(
|
||||||
"temp_test_gp_classifier_without_data.json.zip", (X, Y)
|
"temp_test_gp_classifier_without_data.json.zip", (X, Y)
|
||||||
)
|
)
|
||||||
assert type(m) == type(m2_r), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m2_r)),
|
assert type(m) == type(
|
||||||
|
m2_r
|
||||||
|
), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m2_r))
|
||||||
os.remove("temp_test_gp_classifier_with_data.json.zip")
|
os.remove("temp_test_gp_classifier_with_data.json.zip")
|
||||||
os.remove("temp_test_gp_classifier_without_data.json.zip")
|
os.remove("temp_test_gp_classifier_without_data.json.zip")
|
||||||
|
|
||||||
|
|
@ -415,11 +417,15 @@ class TestSerialization:
|
||||||
m1_r = GPy.models.SparseGPClassification.load_model(
|
m1_r = GPy.models.SparseGPClassification.load_model(
|
||||||
"temp_test_sparse_gp_classifier_with_data.json.zip"
|
"temp_test_sparse_gp_classifier_with_data.json.zip"
|
||||||
)
|
)
|
||||||
assert type(m) == type(m1_r), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m1_r))
|
assert type(m) == type(
|
||||||
|
m1_r
|
||||||
|
), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m1_r))
|
||||||
m2_r = GPy.models.SparseGPClassification.load_model(
|
m2_r = GPy.models.SparseGPClassification.load_model(
|
||||||
"temp_test_sparse_gp_classifier_without_data.json.zip", (X, Y)
|
"temp_test_sparse_gp_classifier_without_data.json.zip", (X, Y)
|
||||||
)
|
)
|
||||||
assert type(m) == type(m2_r), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m2_r)),
|
assert type(m) == type(
|
||||||
|
m2_r
|
||||||
|
), "Incorrect model type. Expected: {} Actual: {}".format(type(m), type(m2_r))
|
||||||
os.remove("temp_test_sparse_gp_classifier_with_data.json.zip")
|
os.remove("temp_test_sparse_gp_classifier_with_data.json.zip")
|
||||||
os.remove("temp_test_sparse_gp_classifier_without_data.json.zip")
|
os.remove("temp_test_sparse_gp_classifier_without_data.json.zip")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue