migrate examples_tests to pytest

This commit is contained in:
Martin Bubel 2023-10-04 21:24:08 +02:00
parent f48837e01d
commit d82100278b

View file

@ -1,24 +1,18 @@
# 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 unittest
import numpy as np
import GPy import GPy
import inspect import inspect
import pkgutil import pkgutil
import os import os
import random
from nose.tools import nottest
import sys
import itertools
class ExamplesTests(unittest.TestCase): def check_grad(Model):
def _checkgrad(self, Model): assert Model.checkgrad(), "Gradient check failed!"
self.assertTrue(Model.checkgrad())
def _model_instance(self, Model):
self.assertTrue(isinstance(Model, GPy.models)) def check_model_instance(Model):
assert isinstance(Model, GPy.models), "Wrong type!"
def model_checkgrads(model): def model_checkgrads(model):
@ -41,14 +35,14 @@ def flatten_nested(lst):
return result return result
@nottest
def test_models(): def test_models():
# TODO: testing setup is not that clear to me yet...
optimize = False optimize = False
plot = True plot = True
examples_path = os.path.dirname(GPy.examples.__file__) examples_path = os.path.dirname(GPy.examples.__file__)
# Load modules # Load modules
failing_models = {} failing_models = {}
for loader, module_name, is_pkg in pkgutil.iter_modules([examples_path]): for loader, module_name, _is_pkg in pkgutil.iter_modules([examples_path]):
# Load examples # Load examples
module_examples = loader.find_module(module_name).load_module(module_name) module_examples = loader.find_module(module_name).load_module(module_name)
print("MODULE", module_examples) print("MODULE", module_examples)
@ -108,9 +102,3 @@ def test_models():
if len(failing_models.keys()) > 0: if len(failing_models.keys()) > 0:
print(failing_models) print(failing_models)
raise Exception(failing_models) raise Exception(failing_models)
if __name__ == "__main__":
print("Running unit tests, please be (very) patient...")
# unittest.main()
test_models()