Skip to content

Commit

Permalink
test: Make run-time dependencies for tests optional
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
  • Loading branch information
Martin Belanger committed Oct 27, 2022
1 parent ead9120 commit bcf8cfd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
option('man', type: 'boolean', value: false, description: 'build and install man pages')
option('html', type: 'boolean', value: false, description: 'build and install html pages')
option('readthedocs', type: 'boolean', value: false, description: 'to be used by Read-The-Docs documentation builder')
option('rt_pymods_reqd', type: 'boolean', value: false, description: 'Make sure all runti python modules are installed')
option('rt_pymods_reqd', type: 'boolean', value: false, description: 'Make sure all run-time python modules are installed')
125 changes: 64 additions & 61 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,81 @@
#
# Authors: Martin Belanger <Martin.Belanger@dell.com>
#
test_env = environment({'MALLOC_PERTURB_': '0'})
test_env.prepend('PYTHONPATH', PYTHONPATH)
#libnvme_dep = dependency('python3-libnvme', fallback: ['libnvme', 'libnvme_dep'], version : '>= 1.2', required: false) # Only required to run the tests
libnvme_dep = dependency('python3-libnvme', fallback: ['libnvme', 'libnvme_dep'], required: false) # Only required to run the tests

# pylint and pyflakes
if modules_to_lint.length() != 0
#libnvme_dep = dependency('python3-libnvme', fallback : ['libnvme', 'libnvme_dep'], version : '>= 1.2')
libnvme_dep = dependency('python3-libnvme', fallback : ['libnvme', 'libnvme_dep'])
pylint = find_program('pylint', required: false)
pyflakes = find_program('pyflakes3', required: false)
if not pyflakes.found()
temp = find_program('pyflakes', required: false)
if temp.found() and run_command(temp, '--version', check: false).stdout().contains('Python 3')
pyflakes = temp
if libnvme_dep.found()
test_env = environment({'MALLOC_PERTURB_': '0'})
test_env.prepend('PYTHONPATH', PYTHONPATH)

# pylint and pyflakes
if modules_to_lint.length() != 0
pylint = find_program('pylint', required: false)
pyflakes = find_program('pyflakes3', required: false)
if not pyflakes.found()
temp = find_program('pyflakes', required: false)
if temp.found() and run_command(temp, '--version', check: false).stdout().contains('Python 3')
pyflakes = temp
endif
endif
endif

rcfile = join_paths(meson.current_source_dir(), 'pylint.rc')
rcfile = join_paths(meson.current_source_dir(), 'pylint.rc')

if pylint.found()
test('pylint', pylint, args: ['--rcfile=' + rcfile] + modules_to_lint, env: test_env)
endif
if pyflakes.found()
test('pyflakes', pyflakes, args: modules_to_lint, env: test_env)
if pylint.found()
test('pylint', pylint, args: ['--rcfile=' + rcfile] + modules_to_lint, env: test_env)
endif
if pyflakes.found()
test('pyflakes', pyflakes, args: modules_to_lint, env: test_env)
endif
endif
endif


# Unit tests
things_to_test = [
['Test Avahi', 'test-avahi.py', []],
['Test Configuration', 'test-config.py', []],
['Test Controller', 'test-controller.py', ['pyfakefs']],
['Test GTimer', 'test-gtimer.py', []],
['Test iputil', 'test-iputil.py', []],
['Test KernelVersion', 'test-version.py', []],
['Test log', 'test-log.py', ['pyfakefs']],
['Test NvmeOptions', 'test-nvme_options.py', ['pyfakefs']],
['Test Service', 'test-service.py', ['pyfakefs']],
['Test TID', 'test-transport_id.py', []],
['Test Udev', 'test-udev.py', []],
]
# Unit tests
things_to_test = [
['Test Avahi', 'test-avahi.py', []],
['Test Configuration', 'test-config.py', []],
['Test Controller', 'test-controller.py', ['pyfakefs']],
['Test GTimer', 'test-gtimer.py', []],
['Test iputil', 'test-iputil.py', []],
['Test KernelVersion', 'test-version.py', []],
['Test log', 'test-log.py', ['pyfakefs']],
['Test NvmeOptions', 'test-nvme_options.py', ['pyfakefs']],
['Test Service', 'test-service.py', ['pyfakefs']],
['Test TID', 'test-transport_id.py', []],
['Test Udev', 'test-udev.py', []],
]

foreach thing: things_to_test
msg = thing[0]

foreach thing: things_to_test
msg = thing[0]
# Check whether all dependencies can be found
missing_deps = []
deps = thing[2]
foreach dep : deps
if run_command(python3, '-c', 'import @0@'.format(dep), check: false).returncode() != 0
missing_deps += [dep]
endif
endforeach

# Check whether all dependencies can be found
missing_deps = []
deps = thing[2]
foreach dep : deps
if run_command(python3, '-c', 'import @0@'.format(dep), check: false).returncode() != 0
missing_deps += [dep]
if missing_deps.length() == 0
# Run the test if all dependencies are available
script = join_paths(meson.current_source_dir(), thing[1])
test(msg, python3, args: script, env: test_env)
else
warning('"@0@" requires python module "@1@"'.format(msg, missing_deps))
endif
endforeach

if missing_deps.length() == 0
# Run the test if all dependencies are available
script = join_paths(meson.current_source_dir(), thing[1])
test(msg, python3, args: script, env: test_env)
else
warning('"@0@" requires python module "@1@"'.format(msg, missing_deps))
endif
endforeach

# Make sure code complies with minimum Python version requirement.
tools = [
join_paths(meson.current_source_dir(), '../man'),
join_paths(meson.current_source_dir(), '../utils'),
]
vermin = find_program('vermin', required: false)
if vermin.found()
if modules_to_lint.length() != 0
test('vermin code', vermin, args: ['--config-file', join_paths(meson.current_source_dir(), 'vermin.conf')] + modules_to_lint, env: test_env)
# Make sure code complies with minimum Python version requirement.
tools = [
join_paths(meson.current_source_dir(), '../man'),
join_paths(meson.current_source_dir(), '../utils'),
]
vermin = find_program('vermin', required: false)
if vermin.found()
if modules_to_lint.length() != 0
test('vermin code', vermin, args: ['--config-file', join_paths(meson.current_source_dir(), 'vermin.conf')] + modules_to_lint, env: test_env)
endif
test('vermin tools', vermin, args: ['--config-file', join_paths(meson.current_source_dir(), 'vermin-tools.conf')] + tools, env: test_env)
endif
test('vermin tools', vermin, args: ['--config-file', join_paths(meson.current_source_dir(), 'vermin-tools.conf')] + tools, env: test_env)
endif

0 comments on commit bcf8cfd

Please sign in to comment.