diff --git a/tools/bazel/.noserc b/tools/bazel/.noserc deleted file mode 100644 index 512f4e1a08..0000000000 --- a/tools/bazel/.noserc +++ /dev/null @@ -1,13 +0,0 @@ -[nosetests] - -# increase verbosity level -verbosity=3 - -# more detailed error messages on failed asserts -detailed-errors=1 - -# stop running tests on first error -stop=1 - -# do not capture stdout -#nocapture=1 diff --git a/tools/bazel/pytest.ini b/tools/bazel/pytest.ini new file mode 100644 index 0000000000..7ee6b8962d --- /dev/null +++ b/tools/bazel/pytest.ini @@ -0,0 +1,13 @@ +[pytest] + +addopts = +# increase verbosity level + --verbose + +# stop running tests on first error +# FIXME: Pretty please comment this horrible setting out, I hate it with a +# passion +# --maxfail=1 + +# do not capture stdout + --capture=sys diff --git a/tools/bazel/tests/Makefile b/tools/bazel/tests/Makefile index 0b76d82bce..8f32c38a24 100644 --- a/tools/bazel/tests/Makefile +++ b/tools/bazel/tests/Makefile @@ -5,8 +5,8 @@ TEST_PROJECT ?= TEST_PROJ=$(CURRENT_DIR)/tests/projects REPO_ROOT ?= REPO_ROOT=$(ROOT) -# Nose test runner configuration options. -NOSECFG = --config .noserc +# pytest test runner configuration options. +PYTESTCFG = -c pytest.ini test: pycodestyle pylint test_unit @@ -31,7 +31,7 @@ pylint_in_env: venv $(ACTIVATE_DEV_VENV) && $(PYLINT_TEST_CMD) UNIT_TEST_CMD = $(REPO_ROOT) $(TEST_PROJECT) \ - nosetests $(NOSECFG) tests/unit + pytest $(PYTESTCFG) tests/unit test_unit: $(UNIT_TEST_CMD) diff --git a/tools/bazel/tests/unit/__init__.py b/tools/bazel/tests/unit/__init__.py index 4259749345..6f7442b714 100644 --- a/tools/bazel/tests/unit/__init__.py +++ b/tools/bazel/tests/unit/__init__.py @@ -5,3 +5,21 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- +""" +Setup python modules for the unit tests. +""" + + +import os +import sys + +REPO_ROOT = os.path.abspath(os.environ['REPO_ROOT']) +PKG_ROOT = os.path.join(REPO_ROOT, 'build', 'CodeChecker') + +os.environ["CC_DATA_FILES_DIR"] = PKG_ROOT + +sys.path.append(REPO_ROOT) +sys.path.append(os.path.join( + REPO_ROOT, 'analyzer', 'tools', 'statistics_collector')) +sys.path.append(os.path.join(REPO_ROOT, 'tools', 'report-converter')) +sys.path.append(os.path.join(PKG_ROOT, 'lib', 'python3')) diff --git a/tools/report-converter/.noserc b/tools/report-converter/.noserc deleted file mode 100644 index 512f4e1a08..0000000000 --- a/tools/report-converter/.noserc +++ /dev/null @@ -1,13 +0,0 @@ -[nosetests] - -# increase verbosity level -verbosity=3 - -# more detailed error messages on failed asserts -detailed-errors=1 - -# stop running tests on first error -stop=1 - -# do not capture stdout -#nocapture=1 diff --git a/tools/report-converter/pytest.ini b/tools/report-converter/pytest.ini new file mode 100644 index 0000000000..7ee6b8962d --- /dev/null +++ b/tools/report-converter/pytest.ini @@ -0,0 +1,13 @@ +[pytest] + +addopts = +# increase verbosity level + --verbose + +# stop running tests on first error +# FIXME: Pretty please comment this horrible setting out, I hate it with a +# passion +# --maxfail=1 + +# do not capture stdout + --capture=sys diff --git a/tools/report-converter/tests/Makefile b/tools/report-converter/tests/Makefile index 5099dc2ee3..9aa60b8c92 100644 --- a/tools/report-converter/tests/Makefile +++ b/tools/report-converter/tests/Makefile @@ -7,8 +7,8 @@ TEST_PROJECT ?= TEST_PROJ=$(CURRENT_DIR)/tests/projects LAYOUT_DIR ?= LAYOUT_DIR=$(STATIC_DIR) -# Nose test runner configuration options. -NOSECFG = --config .noserc +# pytest test runner configuration options. +PYTESTCFG = -c pytest.ini test: mypy pycodestyle pylint test_unit test_functional @@ -41,7 +41,7 @@ pylint_in_env: venv $(ACTIVATE_DEV_VENV) && $(PYLINT_TEST_CMD) UNIT_TEST_CMD = $(REPO_ROOT) $(TEST_PROJECT) $(LAYOUT_DIR) \ - nosetests $(NOSECFG) tests/unit + pytest $(PYTESTCFG) tests/unit test_unit: $(UNIT_TEST_CMD) @@ -50,7 +50,7 @@ test_unit_in_env: venv_dev $(ACTIVATE_DEV_VENV) && $(UNIT_TEST_CMD) FUNCTIONAL_TEST_CMD = $(REPO_ROOT) $(TEST_PROJECT) \ - nosetests $(NOSECFG) tests/functional + pytest $(PYTESTCFG) tests/functional test_functional: $(FUNCTIONAL_TEST_CMD) diff --git a/tools/report-converter/tests/functional/__init__.py b/tools/report-converter/tests/functional/__init__.py index 4259749345..6f7442b714 100644 --- a/tools/report-converter/tests/functional/__init__.py +++ b/tools/report-converter/tests/functional/__init__.py @@ -5,3 +5,21 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- +""" +Setup python modules for the unit tests. +""" + + +import os +import sys + +REPO_ROOT = os.path.abspath(os.environ['REPO_ROOT']) +PKG_ROOT = os.path.join(REPO_ROOT, 'build', 'CodeChecker') + +os.environ["CC_DATA_FILES_DIR"] = PKG_ROOT + +sys.path.append(REPO_ROOT) +sys.path.append(os.path.join( + REPO_ROOT, 'analyzer', 'tools', 'statistics_collector')) +sys.path.append(os.path.join(REPO_ROOT, 'tools', 'report-converter')) +sys.path.append(os.path.join(PKG_ROOT, 'lib', 'python3')) diff --git a/tools/report-converter/tests/functional/cmdline/test_cmdline.py b/tools/report-converter/tests/functional/cmdline/test_cmdline.py index 8921bf237a..80a12839bf 100644 --- a/tools/report-converter/tests/functional/cmdline/test_cmdline.py +++ b/tools/report-converter/tests/functional/cmdline/test_cmdline.py @@ -23,7 +23,9 @@ class TestCmdline(unittest.TestCase): def test_help(self): """ Get help for report-converter tool. """ - ret = subprocess.call(['report-converter', '--help']) + ret = subprocess.call(['report-converter', '--help'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) self.assertEqual(0, ret) def test_metadata(self): diff --git a/tools/report-converter/tests/unit/__init__.py b/tools/report-converter/tests/unit/__init__.py index 4259749345..6f7442b714 100644 --- a/tools/report-converter/tests/unit/__init__.py +++ b/tools/report-converter/tests/unit/__init__.py @@ -5,3 +5,21 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- +""" +Setup python modules for the unit tests. +""" + + +import os +import sys + +REPO_ROOT = os.path.abspath(os.environ['REPO_ROOT']) +PKG_ROOT = os.path.join(REPO_ROOT, 'build', 'CodeChecker') + +os.environ["CC_DATA_FILES_DIR"] = PKG_ROOT + +sys.path.append(REPO_ROOT) +sys.path.append(os.path.join( + REPO_ROOT, 'analyzer', 'tools', 'statistics_collector')) +sys.path.append(os.path.join(REPO_ROOT, 'tools', 'report-converter')) +sys.path.append(os.path.join(PKG_ROOT, 'lib', 'python3')) diff --git a/tools/report-converter/tests/unit/output/gerrit/__init__.py b/tools/report-converter/tests/unit/output/gerrit/__init__.py index cea05ef6e6..0b0114f7e4 100644 --- a/tools/report-converter/tests/unit/output/gerrit/__init__.py +++ b/tools/report-converter/tests/unit/output/gerrit/__init__.py @@ -6,34 +6,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- -""" Setup for the test package analyze. """ - -import os -import shutil - -from libtest import env - - -# Test workspace should be initialized in this module. -TEST_WORKSPACE = None - - -def setup_package(): - """ Setup the environment for the tests. """ - - global TEST_WORKSPACE - TEST_WORKSPACE = env.get_workspace('plist_to_html') - - os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE - - -def teardown_package(): - """ Delete the workspace associated with this test. """ - - # TODO: If environment variable is set keep the workspace - # and print out the path. - global TEST_WORKSPACE - - print("Removing: " + TEST_WORKSPACE) - shutil.rmtree(TEST_WORKSPACE) +# This file is empty, and is only present so that this directory will form a +# package. diff --git a/tools/report-converter/tests/unit/output/gerrit/test_gerrit_converter.py b/tools/report-converter/tests/unit/output/gerrit/test_gerrit_converter.py index b02593ad5e..daef84a8c7 100644 --- a/tools/report-converter/tests/unit/output/gerrit/test_gerrit_converter.py +++ b/tools/report-converter/tests/unit/output/gerrit/test_gerrit_converter.py @@ -63,7 +63,7 @@ def test_report_to_gerrit_conversion(self): ] }, } - self.assertEquals(res, expected) + self.assertEqual(res, expected) def test_report_to_gerrit_conversion_abs_filepath(self): """ Conversion report with absolute filepath. """ @@ -94,7 +94,7 @@ def test_report_to_gerrit_conversion_abs_filepath(self): ] }, } - self.assertEquals(res, expected) + self.assertEqual(res, expected) def test_report_to_gerrit_conversion_report_url(self): """ Conversion report with absolute filepath and CC_REPORT_URL env. """ @@ -127,7 +127,7 @@ def test_report_to_gerrit_conversion_report_url(self): ] }, } - self.assertEquals(res, expected) + self.assertEqual(res, expected) def test_report_to_gerrit_conversion_filter_changed_files(self): """Conversion report with changed files filter. @@ -173,10 +173,10 @@ def test_report_to_gerrit_conversion_filter_changed_files(self): review_comments = res["comments"] # Reports were found in two source files. - self.assertEquals(len(review_comments), 1) + self.assertEqual(len(review_comments), 1) # Two reports in the main.cpp file. - self.assertEquals(len(review_comments[report.file.path]), 2) + self.assertEqual(len(review_comments[report.file.path]), 2) self.assertIn( "CodeChecker found 3 issue(s) in the code.", res["message"]) diff --git a/tools/report-converter/tests/unit/output/html/__init__.py b/tools/report-converter/tests/unit/output/html/__init__.py index cea05ef6e6..0b0114f7e4 100644 --- a/tools/report-converter/tests/unit/output/html/__init__.py +++ b/tools/report-converter/tests/unit/output/html/__init__.py @@ -6,34 +6,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- -""" Setup for the test package analyze. """ - -import os -import shutil - -from libtest import env - - -# Test workspace should be initialized in this module. -TEST_WORKSPACE = None - - -def setup_package(): - """ Setup the environment for the tests. """ - - global TEST_WORKSPACE - TEST_WORKSPACE = env.get_workspace('plist_to_html') - - os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE - - -def teardown_package(): - """ Delete the workspace associated with this test. """ - - # TODO: If environment variable is set keep the workspace - # and print out the path. - global TEST_WORKSPACE - - print("Removing: " + TEST_WORKSPACE) - shutil.rmtree(TEST_WORKSPACE) +# This file is empty, and is only present so that this directory will form a +# package. diff --git a/tools/report-converter/tests/unit/output/html/plist_to_html_test.py b/tools/report-converter/tests/unit/output/html/plist_to_html_test.py index 356a7c94b3..68bfa75060 100644 --- a/tools/report-converter/tests/unit/output/html/plist_to_html_test.py +++ b/tools/report-converter/tests/unit/output/html/plist_to_html_test.py @@ -31,9 +31,14 @@ class PlistToHtmlTest(unittest.TestCase): test_workspace: ClassVar[str] layout_dir: ClassVar[str] - @classmethod - def setUpClass(self): + def setup_class(self): """ Initialize test files. """ + + global TEST_WORKSPACE + TEST_WORKSPACE = env.get_workspace('plist_to_html') + + os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE + self.test_workspace = os.environ['TEST_WORKSPACE'] self.layout_dir = os.environ['LAYOUT_DIR'] @@ -56,6 +61,16 @@ def setUpClass(self): plist_file.truncate() plist_file.write(new_content) + def teardown_class(self): + """ Delete the workspace associated with this test. """ + + # TODO: If environment variable is set keep the workspace + # and print out the path. + global TEST_WORKSPACE + + print("Removing: " + TEST_WORKSPACE) + shutil.rmtree(TEST_WORKSPACE) + def __test_html_builder(self, proj: str) -> str: """ Test building html file from the given proj's plist file. diff --git a/tools/report-converter/tests/unit/parser/__init__.py b/tools/report-converter/tests/unit/parser/__init__.py index 4259749345..9cfe35318f 100644 --- a/tools/report-converter/tests/unit/parser/__init__.py +++ b/tools/report-converter/tests/unit/parser/__init__.py @@ -5,3 +5,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- + +# This file is empty, and is only present so that this directory will form a +# package. diff --git a/tools/report-converter/tests/unit/parser/plist/__init__.py b/tools/report-converter/tests/unit/parser/plist/__init__.py index 4259749345..9cfe35318f 100644 --- a/tools/report-converter/tests/unit/parser/plist/__init__.py +++ b/tools/report-converter/tests/unit/parser/plist/__init__.py @@ -5,3 +5,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- + +# This file is empty, and is only present so that this directory will form a +# package. diff --git a/tools/report-converter/tests/unit/report_hash/__init__.py b/tools/report-converter/tests/unit/report_hash/__init__.py index 03039caa4b..0b0114f7e4 100644 --- a/tools/report-converter/tests/unit/report_hash/__init__.py +++ b/tools/report-converter/tests/unit/report_hash/__init__.py @@ -6,54 +6,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- -""" Setup for the test package analyze. """ -from __future__ import print_function -from __future__ import division -from __future__ import absolute_import - -import os -import shutil -import tempfile - - -# Test workspace should be initialized in this module. -TEST_WORKSPACE = None - - -def get_workspace(test_id='test'): - """ Return a temporary workspace for the tests. """ - workspace_root = os.environ.get("CC_REPORT_HASH_TEST_WORKSPACE_ROOT") - if not workspace_root: - # if no external workspace is set create under the build dir - workspace_root = os.path.join(os.environ['REPO_ROOT'], 'build', - 'workspace') - - if not os.path.exists(workspace_root): - os.makedirs(workspace_root) - - if test_id: - return tempfile.mkdtemp(prefix=test_id + "-", dir=workspace_root) - else: - return workspace_root - - -def setup_package(): - """ Setup the environment for the tests. """ - - global TEST_WORKSPACE - TEST_WORKSPACE = get_workspace('report_hash') - - print(TEST_WORKSPACE) - os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE - - -def teardown_package(): - """ Delete the workspace associated with this test. """ - - # TODO: If environment variable is set keep the workspace - # and print out the path. - global TEST_WORKSPACE - - print("Removing: " + TEST_WORKSPACE) - shutil.rmtree(TEST_WORKSPACE) +# This file is empty, and is only present so that this directory will form a +# package. diff --git a/tools/tu_collector/.noserc b/tools/tu_collector/.noserc deleted file mode 100644 index 512f4e1a08..0000000000 --- a/tools/tu_collector/.noserc +++ /dev/null @@ -1,13 +0,0 @@ -[nosetests] - -# increase verbosity level -verbosity=3 - -# more detailed error messages on failed asserts -detailed-errors=1 - -# stop running tests on first error -stop=1 - -# do not capture stdout -#nocapture=1 diff --git a/tools/tu_collector/pytest.ini b/tools/tu_collector/pytest.ini new file mode 100644 index 0000000000..7ee6b8962d --- /dev/null +++ b/tools/tu_collector/pytest.ini @@ -0,0 +1,13 @@ +[pytest] + +addopts = +# increase verbosity level + --verbose + +# stop running tests on first error +# FIXME: Pretty please comment this horrible setting out, I hate it with a +# passion +# --maxfail=1 + +# do not capture stdout + --capture=sys diff --git a/tools/tu_collector/tests/Makefile b/tools/tu_collector/tests/Makefile index 4dc2986ad0..c7ee5b7eee 100644 --- a/tools/tu_collector/tests/Makefile +++ b/tools/tu_collector/tests/Makefile @@ -5,8 +5,8 @@ TEST_PROJECT ?= TEST_PROJ=$(CURRENT_DIR)/tests/projects REPO_ROOT ?= REPO_ROOT=$(ROOT) -# Nose test runner configuration options. -NOSECFG = --config .noserc +# pytest test runner configuration options. +PYTESTCFG = -c pytest.ini test: mypy pycodestyle pylint test_unit @@ -38,7 +38,7 @@ pylint_in_env: venv $(ACTIVATE_DEV_VENV) && $(PYLINT_TEST_CMD) UNIT_TEST_CMD = $(REPO_ROOT) $(TEST_PROJECT) \ - nosetests $(NOSECFG) tests/unit + pytest $(PYTESTCFG) tests/unit test_unit: $(UNIT_TEST_CMD) diff --git a/tools/tu_collector/tests/unit/__init__.py b/tools/tu_collector/tests/unit/__init__.py index 9f154b3f21..6f7442b714 100644 --- a/tools/tu_collector/tests/unit/__init__.py +++ b/tools/tu_collector/tests/unit/__init__.py @@ -1,4 +1,3 @@ -# coding=utf-8 # ------------------------------------------------------------------------- # # Part of the CodeChecker project, under the Apache License v2.0 with @@ -6,50 +5,21 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # # ------------------------------------------------------------------------- -""" Setup for the test package tu_collector. """ +""" +Setup python modules for the unit tests. +""" -import os -import shutil -import tempfile - - -# Test workspace should be initialized in this module. -TEST_WORKSPACE = None - - -def get_workspace(test_id='test'): - """ Return a temporary workspace for the tests. """ - workspace_root = os.environ.get("TU_COLLECTOR_TEST_WORKSPACE_ROOT") - if not workspace_root: - # if no external workspace is set create under the build dir - workspace_root = os.path.join(os.environ['REPO_ROOT'], 'build', - 'workspace') - - if not os.path.exists(workspace_root): - os.makedirs(workspace_root) - - if test_id: - return tempfile.mkdtemp(prefix=test_id + "-", dir=workspace_root) - else: - return workspace_root - - -def setup_package(): - """ Setup the environment for the tests. """ - - global TEST_WORKSPACE - TEST_WORKSPACE = get_workspace('tu_collector') - - print(TEST_WORKSPACE) - os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE +import os +import sys -def teardown_package(): - """ Delete the workspace associated with this test. """ +REPO_ROOT = os.path.abspath(os.environ['REPO_ROOT']) +PKG_ROOT = os.path.join(REPO_ROOT, 'build', 'CodeChecker') - # TODO: If environment variable is set keep the workspace - # and print out the path. - global TEST_WORKSPACE +os.environ["CC_DATA_FILES_DIR"] = PKG_ROOT - print("Removing: " + TEST_WORKSPACE) - shutil.rmtree(TEST_WORKSPACE) +sys.path.append(REPO_ROOT) +sys.path.append(os.path.join( + REPO_ROOT, 'analyzer', 'tools', 'statistics_collector')) +sys.path.append(os.path.join(REPO_ROOT, 'tools', 'report-converter')) +sys.path.append(os.path.join(PKG_ROOT, 'lib', 'python3'))