From 5f34dea0ed3900e29e7084c114a68b30963aac95 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 25 Oct 2024 14:48:27 +0200 Subject: [PATCH] meson: add tests Signed-off-by: Pavel Hrdina --- meson.build | 12 ++++++++ meson_options.txt | 2 ++ setup.py | 71 -------------------------------------------- tests/meson.build | 64 +++++++++++++++++++++++++++++++++++++++ virt-manager.spec.in | 3 +- 5 files changed, 80 insertions(+), 72 deletions(-) create mode 100644 tests/meson.build diff --git a/meson.build b/meson.build index d46911db7..f95bdd708 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/meson_options.txt b/meson_options.txt index 912fc98c6..6d2696391 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') diff --git a/setup.py b/setup.py index 3a459f559..a15c6b3a8 100755 --- a/setup.py +++ b/setup.py @@ -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, }, diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 000000000..a53b6e14d --- /dev/null +++ b/tests/meson.build @@ -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 diff --git a/virt-manager.spec.in b/virt-manager.spec.in index e7a3f78fc..c22ed32b5 100644 --- a/virt-manager.spec.in +++ b/virt-manager.spec.in @@ -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