Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test][NFC] Change from nose to pytest (tools library) #3931

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions tools/bazel/.noserc

This file was deleted.

13 changes: 13 additions & 0 deletions tools/bazel/pytest.ini
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tools/bazel/requirements_py/dev/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nose==1.3.7
pytest==7.3.1
pycodestyle==2.7.0
pylint==2.8.2
mypy==0.812
Expand Down
6 changes: 3 additions & 3 deletions tools/bazel/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tools/bazel/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
13 changes: 0 additions & 13 deletions tools/report-converter/.noserc

This file was deleted.

13 changes: 13 additions & 0 deletions tools/report-converter/pytest.ini
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nose==1.3.7
pytest==7.3.1
pycodestyle==2.7.0
pylint==2.8.2
portalocker==2.2.1
Expand Down
8 changes: 4 additions & 4 deletions tools/report-converter/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tools/report-converter/tests/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions tools/report-converter/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
32 changes: 2 additions & 30 deletions tools/report-converter/tests/unit/output/gerrit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"])
Expand Down
32 changes: 2 additions & 30 deletions tools/report-converter/tests/unit/output/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tools/report-converter/tests/unit/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions tools/report-converter/tests/unit/parser/plist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
macro_expansions=[])


class PlistParserTestCaseNose(unittest.TestCase):
class PlistParserTestCase(unittest.TestCase):
"""Test the parsing of the plist generated by multiple clang versions."""

@classmethod
Expand Down
Loading