From 43d45a4608b8294e99e51c2b909a52dee91e3245 Mon Sep 17 00:00:00 2001 From: David Hadka Date: Thu, 26 Sep 2024 06:19:22 -0600 Subject: [PATCH] Add add and remove extension tests --- platypus/tests/test_algorithms.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/platypus/tests/test_algorithms.py b/platypus/tests/test_algorithms.py index 6b1bbc2c..59a38fc2 100644 --- a/platypus/tests/test_algorithms.py +++ b/platypus/tests/test_algorithms.py @@ -26,6 +26,7 @@ EpsNSGAII, ParticleSwarm) from ..core import Direction, Problem from ..errors import PlatypusError +from ..extensions import LoggingExtension from ..problems import CF1, DTLZ2 from ..weights import normal_boundary_weights, pbi from ._utils import similar @@ -100,3 +101,22 @@ def maximized_problem(): def test_fail_maximization(maximized_problem, algorithm): with pytest.raises(PlatypusError): algorithm(maximized_problem, **algorithms[algorithm][0]) + +def test_extensions(): + algorithm = NSGAII(DTLZ2()) + + # always start with the LoggingExtension + assert len(algorithm._extensions) == 1 + + algorithm.remove_extension(LoggingExtension) + assert len(algorithm._extensions) == 0 + + l1 = LoggingExtension() + l2 = LoggingExtension() + + algorithm.add_extension(l1) + algorithm.add_extension(l2) + assert [l2, l1] == algorithm._extensions + + algorithm.remove_extension(l2) + assert [l1] == algorithm._extensions