From 66f1048ab3baf5a44b5e457a3b8db9c62139a0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 29 Aug 2023 14:09:10 +0200 Subject: [PATCH] Fix test suite to account for beta numpy versions (#10723) Fix the numpy version check in the test suite to account for the possibility that `numpy.__version__` may contain letters. Prior to this change, running tests on numpy 1.26.0b1 would result in the following error: ``` test/python/algorithms/optimizers/test_optimizers_scikitquant.py:72: in TestOptimizers tuple(map(int, numpy.__version__.split("."))) >= (1, 24, 0), E ValueError: invalid literal for int() with base 10: '0b1' ``` Since the third component is matched against zero, the simplest solution is to check only the first two components, since we can expect that the first two split elements will be integers. --- .../algorithms/optimizers/test_optimizers_scikitquant.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/python/algorithms/optimizers/test_optimizers_scikitquant.py b/test/python/algorithms/optimizers/test_optimizers_scikitquant.py index a980b046e758..0707d1c48b2c 100644 --- a/test/python/algorithms/optimizers/test_optimizers_scikitquant.py +++ b/test/python/algorithms/optimizers/test_optimizers_scikitquant.py @@ -69,7 +69,8 @@ def test_bobyqa(self): self.skipTest(str(ex)) @unittest.skipIf( - tuple(map(int, numpy.__version__.split("."))) >= (1, 24, 0), + # NB: numpy.__version__ may contain letters, e.g. "1.26.0b1" + tuple(map(int, numpy.__version__.split(".")[:2])) >= (1, 24), "scikit's SnobFit currently incompatible with NumPy 1.24.0.", ) def test_snobfit(self): @@ -81,7 +82,8 @@ def test_snobfit(self): self.skipTest(str(ex)) @unittest.skipIf( - tuple(map(int, numpy.__version__.split("."))) >= (1, 24, 0), + # NB: numpy.__version__ may contain letters, e.g. "1.26.0b1" + tuple(map(int, numpy.__version__.split(".")[:2])) >= (1, 24), "scikit's SnobFit currently incompatible with NumPy 1.24.0.", ) @data((None,), ([(-1, 1), (None, None)],))