Skip to content

Commit

Permalink
[test][NFC] Change from nose to pytest (tools library)
Browse files Browse the repository at this point in the history
Continuation of Ericsson#3926.
  • Loading branch information
Szelethus committed Jun 6, 2023
1 parent c8db700 commit bcd0d9d
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 210 deletions.
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
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
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.
Loading

0 comments on commit bcd0d9d

Please sign in to comment.