meson: add tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2024-10-25 14:48:27 +02:00 committed by Pavel Hrdina
parent f41deedd52
commit 5f34dea0ed
5 changed files with 80 additions and 72 deletions

View File

@ -59,3 +59,15 @@ if git
meson.add_dist_script(meson_dist_prog.full_path(), spec_file)
endif
if get_option('tests').auto()
use_tests = git
elif get_option('tests').enabled()
use_tests = true
else
use_tests = false
endif
if use_tests
subdir('tests')
endif

View File

@ -3,3 +3,5 @@ option('compile-schemas', type: 'boolean', value: true, description: 'whether to
option('default-graphics', type: 'combo', choices: ['spice', 'vnc'], value: 'spice', description: 'default graphics type')
option('default-hvs', type: 'array', choices: ['qemu', 'xen', 'lxc', 'bhyve', 'vz'], description: 'list of hypervisors shown in "Open Connection" wizard')
option('tests', type: 'feature', value: 'auto', description: 'whether to run tests')

View File

@ -75,76 +75,6 @@ class TestCommand(setuptools.Command):
"See CONTRIBUTING.md for more info.")
class CheckPylint(setuptools.Command):
user_options = [
("jobs=", "j", "use multiple processes to speed up Pylint"),
]
description = "Check code using pylint and pycodestyle"
def initialize_options(self):
self.jobs = None
def finalize_options(self):
if self.jobs is not None:
self.jobs = int(self.jobs)
def run(self):
import pylint.lint
import pycodestyle
lintfiles = [
# Put this first so pylint learns what Gtk version we
# want to lint against
"virtManager/virtmanager.py",
"setup.py",
"tests",
"virtinst",
"virtManager"]
spellfiles = lintfiles[:]
spellfiles += list(glob.glob("*.md"))
spellfiles += list(glob.glob("man/*.rst"))
spellfiles += ["data/virt-manager.appdata.xml.in",
"data/virt-manager.desktop.in",
"data/org.virt-manager.virt-manager.gschema.xml",
"virt-manager.spec"]
spellfiles.remove("NEWS.md")
try:
import codespell_lib
# pylint: disable=protected-access
print("running codespell")
codespell_lib._codespell.main(
'-I', 'tests/data/codespell_dict.txt',
'--skip', '*.pyc,*.iso,*.xml', *spellfiles)
except ImportError:
print("codespell is not installed. skipping...")
except Exception as e:
print("Error running codespell: %s" % e)
output_format = sys.stdout.isatty() and "colorized" or "text"
print("running pycodestyle")
style_guide = pycodestyle.StyleGuide(
config_file='setup.cfg',
format="pylint",
paths=lintfiles,
)
report = style_guide.check_files()
if style_guide.options.count:
sys.stderr.write(str(report.total_errors) + '\n')
print("running pylint")
pylint_opts = [
"--rcfile", ".pylintrc",
"--output-format=%s" % output_format,
]
if self.jobs is not None:
pylint_opts += ["--jobs=%d" % self.jobs]
pylint.lint.Run(lintfiles + pylint_opts)
setuptools.setup(
name="virt-manager",
version=BuildConfig.version,
@ -157,7 +87,6 @@ setuptools.setup(
cmdclass={
'install_egg_info': my_egg_info,
'pylint': CheckPylint,
'rpm': my_rpm,
'test': TestCommand,
},

64
tests/meson.build Normal file
View File

@ -0,0 +1,64 @@
lint_files = [
'tests',
'virtinst',
'virtManager',
]
spell_files = lint_files + [
'*.md',
'man/*.rst',
'data/virt-manager.appdata.xml.in',
'data/virt-manager.desktop.in',
'data/org.virt-manager.virt-manager.gschema.xml',
'virt-manager.spec.in',
]
pylint_prog = find_program(['pylint', 'pylint-3'])
# meson sets this MALLOC_PERTURB_ to random value by default but it
# doesn't work correctly with pylint so we need to override it
nomalloc = environment({'MALLOC_PERTURB_': '0'})
test(
'pylint',
pylint_prog,
args: [
lint_files,
'--rcfile', '.pylintrc',
],
env: nomalloc,
workdir: meson.project_source_root(),
timeout: 300,
)
pytest_prog = find_program(['pytest', 'pytest-3'])
test(
'pytest',
pytest_prog,
workdir: meson.project_source_root(),
timeout: 300,
)
pycodestyle_prog = find_program(['pycodestyle', 'pycodestyle-3'])
test(
'pycodestyle',
pycodestyle_prog,
args: [
'--config', 'setup.cfg',
'--format', 'pylint',
lint_files,
],
workdir: meson.project_source_root(),
)
codespell_prog = find_program('codespell', required:false)
if codespell_prog.found()
test(
'codespell',
codespell_prog,
args: [
'--ignore-words', 'tests/data/codespell_dict.txt',
'--skip', '*.pyc,*.iso,*.xml,NEWS.md',
spell_files,
],
workdir: meson.project_source_root(),
)
endif

View File

@ -107,7 +107,8 @@ machine).
%meson \
-Ddefault-hvs=%{default_hvs} \
-Dupdate-icon-cache=false \
-Dcompile-schemas=false
-Dcompile-schemas=false \
-Dtests=disabled
%meson_build
%install