Skip to content

Fix test refactoring #350

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

Merged
merged 3 commits into from
Mar 23, 2025
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
10 changes: 5 additions & 5 deletions cpplint_clitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ class TemporaryFolderClassSetup:
systemerr output (two blank lines at end).
"""

@pytest.fixture(autouse=True, name="setUpClass()", scope="class")
@pytest.fixture(autouse=True, name="set_up()", scope="class")
@classmethod
def setUpClass(cls):
def set_up(cls):
"""setup tmp folder for testing with samples and custom additions by subclasses"""
try:
cls._root = os.path.realpath(tempfile.mkdtemp())
shutil.copytree("samples", os.path.join(cls._root, "samples"))
cls.prepare_directory(cls._root)
except Exception:
with contextlib.suppress(Exception):
cls.tearDownClass()
cls.tear_down()
raise
# yield
# cls.tearDownClass()
# cls.tear_down()

@classmethod
def tearDownClass(cls):
def tear_down(cls):
if cls._root:
# pass
shutil.rmtree(cls._root)
Expand Down
39 changes: 17 additions & 22 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def codecs_latin_encode(x):
class ErrorCollector:
# These are a global list, covering all categories seen ever.
_ERROR_CATEGORIES = cpplint._ERROR_CATEGORIES
_SEEN_ERROR_CATEGORIES: dict[str, str] = {}
_SEEN_ERROR_CATEGORIES: set[str] = set()

def __init__(self, assert_fn):
"""assert_fn: a function to call when we notice a problem."""
Expand All @@ -74,7 +74,7 @@ def __call__(self, filename, linenum, category, confidence, message):
'Message "%s" has category "%s",'
" which is not in _ERROR_CATEGORIES" % (message, category),
)
self._SEEN_ERROR_CATEGORIES[category] = 1
self._SEEN_ERROR_CATEGORIES.add(category)
if cpplint._ShouldPrintError(category, confidence, filename, linenum):
self._errors.append("%s [%s] [%d]" % (message, category, confidence))

Expand Down Expand Up @@ -257,10 +257,7 @@ def TestMultiLineLint(self, code, expected_message):

def TestMultiLineLintRE(self, code, expected_message_re):
message = self.PerformMultiLineLint(code)
if not re.search(expected_message_re, message):
self.fail(
"Message was:\n" + message + 'Expected match to "' + expected_message_re + '"'
)
assert re.search(expected_message_re, message)

def TestLanguageRulesCheck(self, file_name, code, expected_message):
assert expected_message == self.PerformLanguageRulesCheck(file_name, code)
Expand Down Expand Up @@ -321,7 +318,8 @@ def testNamespaceIndentationForClass(self):
def testNamespaceIndentationIndentedParameter(self):
lines = [
"namespace Test {",
"void foo( SuperLongTypeName d = 418) { }",
"void foo(SuperLongTypeName d = 418,",
" SuperLongTypeName e = 2.71) { }",
"} // namespace Test",
]

Expand Down Expand Up @@ -5260,8 +5258,7 @@ def testBuildHeaderGuard(self):
error_collector,
)
for line in error_collector.ResultList():
if line.find("build/header_guard") != -1:
self.fail("Unexpected error: %s" % line)
assert "build/header_guard" not in line

# No header guard errors for old-style guard
error_collector = ErrorCollector(self.assertTrue)
Expand All @@ -5276,8 +5273,7 @@ def testBuildHeaderGuard(self):
error_collector,
)
for line in error_collector.ResultList():
if line.find("build/header_guard") != -1:
self.fail("Unexpected error: %s" % line)
assert "build/header_guard" not in line

old_verbose_level = cpplint._cpplint_state.verbose_level
try:
Expand Down Expand Up @@ -5721,10 +5717,9 @@ def testRuntimePrintfFormat(self):
def TestLintLogCodeOnError(self, code, expected_message):
# Special TestLint which logs the input code on error.
result = self.PerformSingleLineLint(code)
if result != expected_message:
self.fail(
'For code: "%s"\nGot: "%s"\nExpected: "%s"' % (code, result, expected_message)
)
assert result == expected_message, (
f'For code: "{code}"\nGot: "{result}"\nExpected: "{expected_message}"'
)

def testBuildStorageClass(self):
qualifiers = [None, "const", "volatile"]
Expand Down Expand Up @@ -5822,17 +5817,15 @@ def testLegalCopyright(self):
# Test that warning isn't issued if Copyright line appears early enough.
error_collector = ErrorCollector(self.assertTrue)
cpplint.ProcessFileData(file_path, "cc", [copyright_line], error_collector)
for message in error_collector.ResultList():
if message.find("legal/copyright") != -1:
self.fail("Unexpected error: %s" % message)
for line in error_collector.ResultList():
assert "legal/copyright" not in line

error_collector = ErrorCollector(self.assertTrue)
cpplint.ProcessFileData(
file_path, "cc", ["" for unused_i in range(9)] + [copyright_line], error_collector
)
for message in error_collector.ResultList():
if message.find("legal/copyright") != -1:
self.fail("Unexpected error: %s" % message)
for line in error_collector.ResultList():
assert "legal/copyright" not in line

def testInvalidIncrement(self):
self.TestLint(
Expand Down Expand Up @@ -7183,7 +7176,9 @@ def run_around_tests(pytestconfig: pytest.Config):
# obviously we're not going to see all the error categories. So we
# only run VerifyAllCategoriesAreSeen() when we don't filter for
# specific tests.
if pytestconfig.getoption("-k", default=None) in {None, ""}:
if pytestconfig.getoption("-k", default=None) in {None, ""} and not any(
"::" in arg for arg in pytestconfig.args
):
ErrorCollector(None).VerifyAllCategoriesAreSeen()


Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy