parameterize library installer tests
import os
import platform
import tempfile
-import unittest
import urllib
from cupy import testing
@@ -10,28 +9,48 @@ from cupyx.tools import install_library
import pytest
-@testing.parameterize(
- {'library': 'cudnn'},
- {'library': 'cutensor'},
- {'library': 'nccl'},
-)
-class TestInstallLibrary(unittest.TestCase):
+_libraries = ['cudnn', 'nccl', 'cutensor']
+
+def _get_supported_cuda_versions(lib):
+ return sorted(set([
+ rec['cuda'] for rec in install_library.library_records[lib]]))
+
+
+class TestInstallLibrary:
+
+ @pytest.mark.parametrize('cuda', _get_supported_cuda_versions('cudnn'))
@testing.slow
- def test_install(self):
- system = platform.system()
- if system == 'Windows' and self.library == 'nccl':
- pytest.skip('NCCL is only available for Linux')
+ def test_install_cudnn(self, cuda):
+ self._test_install('cudnn', cuda)
- # Try installing library for all supported CUDA versions
- for rec in install_library.library_records[self.library]:
- cuda = rec['cuda']
- version = rec[self.library]
+ @pytest.mark.skipif(
+ platform.system() == 'Windows',
+ reason='NCCL is only available for Linux')
+ @pytest.mark.parametrize('cuda', _get_supported_cuda_versions('nccl'))
+ @testing.slow
+ def test_install_nccl(self, cuda):
+ self._test_install('nccl', cuda)
+
+ @pytest.mark.parametrize('cuda', _get_supported_cuda_versions('cutensor'))
+ @testing.slow
+ def test_install_cutensor(self, cuda):
+ self._test_install('cutensor', cuda)
+
+ def _test_install(self, library, cuda):
+ system = platform.system()
+ for rec in install_library.library_records[library]:
+ if rec['cuda'] != cuda:
+ continue
+ version = rec[library]
filenames = rec['assets'][system]['filenames']
with tempfile.TemporaryDirectory() as d:
- install_library.install_lib(cuda, d, self.library)
+ install_library.install_lib(cuda, d, library)
self._check_installed(
- d, cuda, self.library, version, filenames)
+ d, cuda, library, version, filenames)
+ break
+ else:
+ pytest.fail(f'unexpected CUDA version {cuda} for {library}')
def _check_installed(self, prefix, cuda, lib, version, filenames):
install_root = os.path.join(prefix, cuda, lib, version)
@@ -42,9 +61,10 @@ class TestInstallLibrary(unittest.TestCase):
return
pytest.fail('expected file cound not be found')
- def test_urls(self):
+ @pytest.mark.parametrize('library', _libraries)
+ def test_urls(self, library):
assets = [r['assets']
- for r in install_library.library_records[self.library]]
+ for r in install_library.library_records[library]]
for asset in assets:
for system in asset.keys():
url = asset[system]['url']
@@ -52,6 +72,7 @@ class TestInstallLibrary(unittest.TestCase):
urllib.request.Request(url, method='HEAD')) as resp:
assert resp.getcode() == 200
- def test_main(self):
+ @pytest.mark.parametrize('library', _libraries)
+ def test_main(self, library):
install_library.main(
- ['--library', self.library, '--action', 'dump', '--cuda', 'null'])
+ ['--library', library, '--action', 'dump', '--cuda', 'null'])
