From c241f0ab39779cb0591be885e92f135360031a65 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 13 May 2014 18:40:43 -0300 Subject: [PATCH] Reorganize unittests and functional tests In order for people to run all avocado tests at once, move and reorganize tests under a directory called selftests. For someone to run all self tests in avocado, one would have to execute: selftests/run selftests/all This is a shortcut for developers. .travis.yml was also updated to run tests based on the new directory structure. Signed-off-by: Lucas Meneghel Rodrigues --- .travis.yml | 19 +---- .nose.cfg => selftests/.nose.cfg | 0 selftests/all/doc/doc_build_test.py | 56 +++++++++++++++ .../all/functional/avocado/basic_tests.py | 57 +++++++++++++++ .../all/functional/avocado/multiplex_tests.py | 65 +++++++++++++++++ .../functional/avocado/standalone_tests.py | 72 +++++++++++++++++++ .../all/unit}/avocado/datadir_unittest.py | 0 .../avocado/multiplex_config_unittest.py | 0 .../all/unit}/avocado/settings_unittest.py | 0 .../all/unit}/avocado/sysinfo_unittest.py | 0 .../all/unit}/avocado/test_unittest.py | 0 .../unit}/avocado/utils_params_unittest.py | 0 .../all/unit}/avocado/xunit_unittest.py | 0 unittests/runtests.py => selftests/run | 13 +--- 14 files changed, 255 insertions(+), 27 deletions(-) rename .nose.cfg => selftests/.nose.cfg (100%) create mode 100755 selftests/all/doc/doc_build_test.py create mode 100644 selftests/all/functional/avocado/basic_tests.py create mode 100644 selftests/all/functional/avocado/multiplex_tests.py create mode 100644 selftests/all/functional/avocado/standalone_tests.py rename {unittests => selftests/all/unit}/avocado/datadir_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/multiplex_config_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/settings_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/sysinfo_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/test_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/utils_params_unittest.py (100%) rename {unittests => selftests/all/unit}/avocado/xunit_unittest.py (100%) rename unittests/runtests.py => selftests/run (95%) diff --git a/.travis.yml b/.travis.yml index 2e2fe7c6..0484ac28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,21 +12,8 @@ install: - pip install -r requirements.txt script: - - ./unittests/runtests.py -c .nose.cfg - inspekt lint - inspekt style - - make -C docs html 2>&1 | grep -E '(ERROR|WARNING)' || test $? -eq 1 - - ./scripts/avocado run "sleeptest sleeptest" - - ./scripts/avocado run "sleeptest failtest sleeptest" || test $? -eq 1 - - ./scripts/avocado run "bogustest" || test $? -ne 3 - - export PYTHONPATH=$PYTHONPATH:. - - ./tests/sleeptest/sleeptest.py - - ./tests/skiptest/skiptest.py - - ./tests/failtest/failtest.py || test $? -eq 1 - - ./tests/errortest/errortest.py || test $? -eq 1 - - ./tests/warntest/warntest.py || test $? -eq 1 - - ./scripts/avocado run --multiplex tests/sleeptest/sleeptest.mplx - - ./scripts/avocado run "sleeptest sleeptest" --multiplex tests/sleeptest/sleeptest.mplx - - ./scripts/avocado run "sleeptest failtest" --multiplex tests/sleeptest/sleeptest.mplx || test $? -eq 1 - - ./scripts/avocado multiplex tests/sleeptest/sleeptest.mplx - - ./scripts/avocado multiplex nonexist || test $? -eq 2 + - ./selftests/run -v selftests/all/doc + - ./selftests/run -v selftests/all/functional + - ./selftests/run selftests/all/unit -c selftests/.nose.cfg diff --git a/.nose.cfg b/selftests/.nose.cfg similarity index 100% rename from .nose.cfg rename to selftests/.nose.cfg diff --git a/selftests/all/doc/doc_build_test.py b/selftests/all/doc/doc_build_test.py new file mode 100755 index 00000000..883f846a --- /dev/null +++ b/selftests/all/doc/doc_build_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/python +""" +Build documentation and report whether we had warning/error messages. + +This is geared towards documentation build regression testing. +""" +import os +import sys + +# simple magic for using scripts within a source tree +basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..') +basedir = os.path.abspath(basedir) +if os.path.isdir(os.path.join(basedir, 'avocado')): + sys.path.append(basedir) + +from avocado.utils import process + + +class DocBuildError(Exception): + pass + + +def test_build_docs(): + """ + Build avocado HTML docs, reporting failures + """ + ignore_list = [] + failure_lines = [] + doc_dir = os.path.join(basedir, 'docs') + process.run('make -C %s clean' % doc_dir) + result = process.run('make -C %s html' % doc_dir) + stdout = result.stdout.splitlines() + stderr = result.stderr.splitlines() + output_lines = stdout + stderr + for line in output_lines: + ignore_msg = False + for ignore in ignore_list: + if ignore in line: + print 'Expected warning ignored: %s' % line + ignore_msg = True + if ignore_msg: + continue + if 'ERROR' in line: + failure_lines.append(line) + if 'WARNING' in line: + failure_lines.append(line) + if failure_lines: + e_msg = ('%s ERRORS and/or WARNINGS detected while building the html docs:\n' % + len(failure_lines)) + for (index, failure_line) in enumerate(failure_lines): + e_msg += "%s) %s\n" % (index + 1, failure_line) + e_msg += 'Please check the output and fix your docstrings/.rst docs' + raise DocBuildError(e_msg) + +if __name__ == '__main__': + test_build_docs() diff --git a/selftests/all/functional/avocado/basic_tests.py b/selftests/all/functional/avocado/basic_tests.py new file mode 100644 index 00000000..1c41a8c9 --- /dev/null +++ b/selftests/all/functional/avocado/basic_tests.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2013-2014 +# Author: Lucas Meneghel Rodrigues + +import unittest +import os +import sys + +# simple magic for using scripts within a source tree +basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..') +basedir = os.path.abspath(basedir) +if os.path.isdir(os.path.join(basedir, 'avocado')): + sys.path.append(basedir) + +from avocado.utils import process + + +class RunnerOperationTest(unittest.TestCase): + + def test_runner_all_ok(self): + os.chdir(basedir) + cmd_line = './scripts/avocado run "sleeptest sleeptest"' + process.run(cmd_line) + + def test_runner_tests_fail(self): + os.chdir(basedir) + cmd_line = './scripts/avocado run "sleeptest failtest sleeptest"' + result = process.run(cmd_line, ignore_status=True) + expected_rc = 1 + self.assertEqual(result.exit_status, expected_rc, + "Avocado did not return rc %d:\n%s" % (expected_rc, result)) + + def test_runner_nonexistent_test(self): + os.chdir(basedir) + cmd_line = './scripts/avocado run bogustest' + result = process.run(cmd_line, ignore_status=True) + expected_rc = 1 + unexpected_rc = 3 + self.assertNotEqual(result.exit_status, unexpected_rc, + "Avocado crashed (rc %d):\n%s" % (unexpected_rc, result)) + self.assertEqual(result.exit_status, expected_rc, + "Avocado did not return rc %d:\n%s" % (expected_rc, result)) + +if __name__ == '__main__': + unittest.main() diff --git a/selftests/all/functional/avocado/multiplex_tests.py b/selftests/all/functional/avocado/multiplex_tests.py new file mode 100644 index 00000000..d5d5cf3f --- /dev/null +++ b/selftests/all/functional/avocado/multiplex_tests.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2013-2014 +# Author: Lucas Meneghel Rodrigues + +import unittest +import os +import sys + +# simple magic for using scripts within a source tree +basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..') +basedir = os.path.abspath(basedir) +if os.path.isdir(os.path.join(basedir, 'avocado')): + sys.path.append(basedir) + +from avocado.utils import process + + +class MultiplexTests(unittest.TestCase): + + def run_and_check(self, cmd_line, expected_rc): + os.chdir(basedir) + result = process.run(cmd_line, ignore_status=True) + self.assertEqual(result.exit_status, expected_rc, + "Command %s did not return rc " + "%d:\n%s" % (cmd_line, expected_rc, result)) + + def test_mplex_plugin(self): + cmd_line = './scripts/avocado multiplex tests/sleeptest/sleeptest.mplx' + expected_rc = 0 + self.run_and_check(cmd_line, expected_rc) + + def test_mplex_plugin_nonexistent(self): + cmd_line = './scripts/avocado multiplex nonexist' + expected_rc = 2 + self.run_and_check(cmd_line, expected_rc) + + def test_run_mplex_sleeptest(self): + cmd_line = './scripts/avocado run sleeptest --multiplex tests/sleeptest/sleeptest.mplx' + expected_rc = 0 + self.run_and_check(cmd_line, expected_rc) + + def test_run_mplex_doublesleep(self): + cmd_line = './scripts/avocado run "sleeptest sleeptest" --multiplex tests/sleeptest/sleeptest.mplx' + expected_rc = 0 + self.run_and_check(cmd_line, expected_rc) + + def test_run_mplex_failtest(self): + cmd_line = './scripts/avocado run "sleeptest failtest" --multiplex tests/sleeptest/sleeptest.mplx' + expected_rc = 1 + self.run_and_check(cmd_line, expected_rc) + +if __name__ == '__main__': + unittest.main() diff --git a/selftests/all/functional/avocado/standalone_tests.py b/selftests/all/functional/avocado/standalone_tests.py new file mode 100644 index 00000000..a6b7c605 --- /dev/null +++ b/selftests/all/functional/avocado/standalone_tests.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2013-2014 +# Author: Lucas Meneghel Rodrigues + +import unittest +import os +import sys + +# simple magic for using scripts within a source tree +basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..') +basedir = os.path.abspath(basedir) +if os.path.isdir(os.path.join(basedir, 'avocado')): + sys.path.append(basedir) + +from avocado.utils import process + + +class StandaloneTests(unittest.TestCase): + + def setUp(self): + self.original_pypath = os.environ.get('PYTHONPATH') + if self.original_pypath is not None: + os.environ['PYTHONPATH'] = '%s:%s' % (basedir, self.original_pypath) + else: + os.environ['PYTHONPATH'] = '%s' % basedir + + def run_and_check(self, cmd_line, expected_rc, tstname): + os.chdir(basedir) + result = process.run(cmd_line, ignore_status=True) + self.assertEqual(result.exit_status, expected_rc, + "Stand alone %s did not return rc " + "%d:\n%s" % (tstname, expected_rc, result)) + + def test_sleeptest(self): + cmd_line = './tests/sleeptest/sleeptest.py' + expected_rc = 0 + self.run_and_check(cmd_line, expected_rc, 'sleeptest') + + def test_skiptest(self): + cmd_line = './tests/skiptest/skiptest.py' + expected_rc = 0 + self.run_and_check(cmd_line, expected_rc, 'skiptest') + + def test_failtest(self): + cmd_line = './tests/failtest/failtest.py' + expected_rc = 1 + self.run_and_check(cmd_line, expected_rc, 'failtest') + + def test_errortest(self): + cmd_line = './tests/errortest/errortest.py' + expected_rc = 1 + self.run_and_check(cmd_line, expected_rc, 'errortest') + + def test_warntest(self): + cmd_line = './tests/warntest/warntest.py' + expected_rc = 1 + self.run_and_check(cmd_line, expected_rc, 'warntest') + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/avocado/datadir_unittest.py b/selftests/all/unit/avocado/datadir_unittest.py similarity index 100% rename from unittests/avocado/datadir_unittest.py rename to selftests/all/unit/avocado/datadir_unittest.py diff --git a/unittests/avocado/multiplex_config_unittest.py b/selftests/all/unit/avocado/multiplex_config_unittest.py similarity index 100% rename from unittests/avocado/multiplex_config_unittest.py rename to selftests/all/unit/avocado/multiplex_config_unittest.py diff --git a/unittests/avocado/settings_unittest.py b/selftests/all/unit/avocado/settings_unittest.py similarity index 100% rename from unittests/avocado/settings_unittest.py rename to selftests/all/unit/avocado/settings_unittest.py diff --git a/unittests/avocado/sysinfo_unittest.py b/selftests/all/unit/avocado/sysinfo_unittest.py similarity index 100% rename from unittests/avocado/sysinfo_unittest.py rename to selftests/all/unit/avocado/sysinfo_unittest.py diff --git a/unittests/avocado/test_unittest.py b/selftests/all/unit/avocado/test_unittest.py similarity index 100% rename from unittests/avocado/test_unittest.py rename to selftests/all/unit/avocado/test_unittest.py diff --git a/unittests/avocado/utils_params_unittest.py b/selftests/all/unit/avocado/utils_params_unittest.py similarity index 100% rename from unittests/avocado/utils_params_unittest.py rename to selftests/all/unit/avocado/utils_params_unittest.py diff --git a/unittests/avocado/xunit_unittest.py b/selftests/all/unit/avocado/xunit_unittest.py similarity index 100% rename from unittests/avocado/xunit_unittest.py rename to selftests/all/unit/avocado/xunit_unittest.py diff --git a/unittests/runtests.py b/selftests/run similarity index 95% rename from unittests/runtests.py rename to selftests/run index f176575e..14966a45 100755 --- a/unittests/runtests.py +++ b/selftests/run @@ -42,7 +42,7 @@ class AvocadoTestSelector(Selector): return True def wantFile(self, filename): - if not filename.endswith('_unittest.py'): + if not filename.endswith('.py'): return False skip_tests = [] @@ -82,17 +82,8 @@ class AvocadoTestRunner(Plugin): def prepareTestLoader(self, loader): loader.selector = AvocadoTestSelector(loader.config) - -def run_test(): +if __name__ == '__main__': nose.main(addplugins=[AvocadoTestRunner(), AttributeSelector(), Xunit(), Coverage()]) - - -def main(): - run_test() - - -if __name__ == '__main__': - main() -- GitLab