diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 245d14fa..259a5479 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v3 diff --git a/tests/distributions/_utils.py b/tests/distributions/_utils.py index 40ac0890..89fdd187 100644 --- a/tests/distributions/_utils.py +++ b/tests/distributions/_utils.py @@ -4,7 +4,7 @@ import numpy import torch -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_bernoulli.py b/tests/distributions/test_bernoulli.py index 0efb377a..8bf41b1b 100644 --- a/tests/distributions/test_bernoulli.py +++ b/tests/distributions/test_bernoulli.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_categorical.py b/tests/distributions/test_categorical.py index c9b6fa66..bb31a9d5 100644 --- a/tests/distributions/test_categorical.py +++ b/tests/distributions/test_categorical.py @@ -12,7 +12,7 @@ from ._utils import _test_predictions from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_conditional_categorical.py b/tests/distributions/test_conditional_categorical.py index 411f2787..e4fd022d 100644 --- a/tests/distributions/test_conditional_categorical.py +++ b/tests/distributions/test_conditional_categorical.py @@ -12,7 +12,7 @@ from ._utils import _test_predictions from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_dirac_delta.py b/tests/distributions/test_dirac_delta.py index bba646a9..9cab7e37 100644 --- a/tests/distributions/test_dirac_delta.py +++ b/tests/distributions/test_dirac_delta.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_exponential.py b/tests/distributions/test_exponential.py index efbe4e46..db0bc445 100644 --- a/tests/distributions/test_exponential.py +++ b/tests/distributions/test_exponential.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_gamma.py b/tests/distributions/test_gamma.py index 98384b39..df41bebb 100644 --- a/tests/distributions/test_gamma.py +++ b/tests/distributions/test_gamma.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_independent_component.py b/tests/distributions/test_independent_component.py index 011da497..9bd3266c 100644 --- a/tests/distributions/test_independent_component.py +++ b/tests/distributions/test_independent_component.py @@ -17,7 +17,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_joint_categorical.py b/tests/distributions/test_joint_categorical.py index f70d969d..1956f9c2 100644 --- a/tests/distributions/test_joint_categorical.py +++ b/tests/distributions/test_joint_categorical.py @@ -12,7 +12,7 @@ from ._utils import _test_predictions from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_normal_diagonal.py b/tests/distributions/test_normal_diagonal.py index 3d545ba3..129c18e5 100644 --- a/tests/distributions/test_normal_diagonal.py +++ b/tests/distributions/test_normal_diagonal.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal SQRT_2_PI = 2.50662827463 diff --git a/tests/distributions/test_normal_full.py b/tests/distributions/test_normal_full.py index 899df644..823521d5 100644 --- a/tests/distributions/test_normal_full.py +++ b/tests/distributions/test_normal_full.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal SQRT_2_PI = 2.50662827463 diff --git a/tests/distributions/test_poisson.py b/tests/distributions/test_poisson.py index 78859745..e5562b61 100644 --- a/tests/distributions/test_poisson.py +++ b/tests/distributions/test_poisson.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/distributions/test_student_t.py b/tests/distributions/test_student_t.py index eec3e9c9..b0c1aece 100644 --- a/tests/distributions/test_student_t.py +++ b/tests/distributions/test_student_t.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal SQRT_2_PI = 2.50662827463 diff --git a/tests/distributions/test_uniform.py b/tests/distributions/test_uniform.py index b50cbbdb..d7bab5ef 100644 --- a/tests/distributions/test_uniform.py +++ b/tests/distributions/test_uniform.py @@ -14,7 +14,7 @@ from ._utils import _test_efd_from_summaries from ._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/hmm/test_dense_hmm.py b/tests/hmm/test_dense_hmm.py index 65e7218a..f1517686 100644 --- a/tests/hmm/test_dense_hmm.py +++ b/tests/hmm/test_dense_hmm.py @@ -15,7 +15,7 @@ from ..distributions._utils import _test_efd_from_summaries from ..distributions._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal from numpy.testing import assert_array_equal diff --git a/tests/hmm/test_sparse_hmm.py b/tests/hmm/test_sparse_hmm.py index feaeb632..76c5464d 100644 --- a/tests/hmm/test_sparse_hmm.py +++ b/tests/hmm/test_sparse_hmm.py @@ -15,7 +15,7 @@ from ..distributions._utils import _test_efd_from_summaries from ..distributions._utils import _test_raises -from nose.tools import assert_raises +from ..tools import assert_raises from numpy.testing import assert_array_almost_equal from numpy.testing import assert_array_equal diff --git a/tests/test_bayes_classifier.py b/tests/test_bayes_classifier.py index 5ff48e8b..d35043ee 100644 --- a/tests/test_bayes_classifier.py +++ b/tests/test_bayes_classifier.py @@ -15,7 +15,7 @@ from .distributions._utils import _test_efd_from_summaries from .distributions._utils import _test_raises -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_bayesian_network.py b/tests/test_bayesian_network.py index d8945c2c..94521934 100644 --- a/tests/test_bayesian_network.py +++ b/tests/test_bayesian_network.py @@ -11,7 +11,7 @@ from pomegranate.distributions import ConditionalCategorical -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_equal from numpy.testing import assert_array_almost_equal diff --git a/tests/test_bayesian_network_structure_learning.py b/tests/test_bayesian_network_structure_learning.py index 174e0d8d..91480b9a 100644 --- a/tests/test_bayesian_network_structure_learning.py +++ b/tests/test_bayesian_network_structure_learning.py @@ -15,7 +15,7 @@ from pomegranate.distributions import Categorical from pomegranate.distributions import ConditionalCategorical -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_factor_graph.py b/tests/test_factor_graph.py index 22891e12..5696ef67 100644 --- a/tests/test_factor_graph.py +++ b/tests/test_factor_graph.py @@ -10,7 +10,7 @@ from pomegranate.distributions import Categorical from pomegranate.distributions import JointCategorical -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_gmm.py b/tests/test_gmm.py index 09990b9d..ee4c4418 100644 --- a/tests/test_gmm.py +++ b/tests/test_gmm.py @@ -15,7 +15,7 @@ from .distributions._utils import _test_efd_from_summaries from .distributions._utils import _test_raises -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_kmeans.py b/tests/test_kmeans.py index f39ea44b..87e24760 100644 --- a/tests/test_kmeans.py +++ b/tests/test_kmeans.py @@ -14,7 +14,7 @@ from .distributions._utils import _test_efd_from_summaries from .distributions._utils import _test_raises -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_markov_chain.py b/tests/test_markov_chain.py index b21eae2c..88c1f1c4 100644 --- a/tests/test_markov_chain.py +++ b/tests/test_markov_chain.py @@ -15,7 +15,7 @@ from .distributions._utils import _test_efd_from_summaries from .distributions._utils import _test_raises -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_almost_equal diff --git a/tests/test_semisupervised.py b/tests/test_semisupervised.py index e2823fec..f74fd31e 100644 --- a/tests/test_semisupervised.py +++ b/tests/test_semisupervised.py @@ -10,7 +10,7 @@ from pomegranate.hmm import DenseHMM from pomegranate.distributions import Exponential -from nose.tools import assert_raises +from .tools import assert_raises from numpy.testing import assert_array_equal from numpy.testing import assert_array_almost_equal diff --git a/tests/test_utils.py b/tests/test_utils.py index b839d7fd..c759b3d9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,9 +10,9 @@ from pomegranate._utils import _check_parameter from pomegranate._utils import partition_sequences -from nose.tools import assert_almost_equal -from nose.tools import assert_equal -from nose.tools import assert_raises +from .tools import assert_almost_equal +from .tools import assert_equal +from .tools import assert_raises from numpy.testing import assert_array_equal from numpy.testing import assert_array_almost_equal diff --git a/tests/tools.py b/tests/tools.py new file mode 100644 index 00000000..4afe6b56 --- /dev/null +++ b/tests/tools.py @@ -0,0 +1,55 @@ +# tools.py +# Author: Jacob Schreiber + +''' +Tools taken from nose since it can no longer be installed after Py3.12. +''' + + +import re +import unittest + + +__all__ = ['ok_', 'eq_'] + +# Use the same flag as unittest itself to prevent descent into these functions: +__unittest = 1 + + +def ok_(expr, msg=None): + """Shorthand for assert. Saves 3 whole characters! + """ + if not expr: + raise AssertionError(msg) + + +def eq_(a, b, msg=None): + """Shorthand for 'assert a == b, "%r != %r" % (a, b) + """ + if not a == b: + raise AssertionError(msg or "%r != %r" % (a, b)) + + +# +# Expose assert* from unittest.TestCase +# - give them pep8 style names +# +caps = re.compile('([A-Z])') + +def pep8(name): + return caps.sub(lambda m: '_' + m.groups()[0].lower(), name) + +class Dummy(unittest.TestCase): + def nop(): + pass +_t = Dummy('nop') + +for at in [ at for at in dir(_t) + if at.startswith('assert') and not '_' in at ]: + pepd = pep8(at) + vars()[pepd] = getattr(_t, at) + __all__.append(pepd) + +del Dummy +del _t +del pep8