Skip to content

Ruff rules PT for pytest style #332

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 16, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.10.0
rev: v0.11.0
hooks:
- id: ruff
- id: ruff-format
Expand Down
1 change: 0 additions & 1 deletion cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@
"readability/namespace",
"readability/nolint",
"readability/nul",
"readability/strings",
"readability/todo",
"readability/utf8",
"runtime/arrays",
Expand Down
34 changes: 19 additions & 15 deletions cpplint_clitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
import subprocess
import sys
import tempfile
import unittest

import pytest
from parameterized import parameterized
from pytest import mark
from testfixtures import compare

import cpplint # noqa: F401

BASE_CMD = sys.executable + " " + os.path.abspath("./cpplint.py ")


Expand Down Expand Up @@ -74,15 +75,15 @@ def run_shell_command(cmd: str, args: str, cwd="."):
return proc.returncode, out, err


class UsageTest(unittest.TestCase):
class TestUsage:
def testHelp(self):
(status, out, err) = run_shell_command(BASE_CMD, "--help")
self.assertEqual(0, status)
self.assertEqual(b"", out)
self.assertTrue(err.startswith(b"\nSyntax: cpplint"))
assert status == 0
assert out == b""
assert err.startswith(b"\nSyntax: cpplint")


class TemporaryFolderClassSetup(unittest.TestCase):
class TemporaryFolderClassSetup:
"""
Regression tests: The test starts a filetreewalker scanning for files name *.def
Such files are expected to have as first line the argument
Expand All @@ -92,6 +93,7 @@ class TemporaryFolderClassSetup(unittest.TestCase):
systemerr output (two blank lines at end).
"""

@pytest.fixture(autouse=True, name="setUpClass()", scope="class")
@classmethod
def setUpClass(cls):
"""setup tmp folder for testing with samples and custom additions by subclasses"""
Expand All @@ -103,6 +105,8 @@ def setUpClass(cls):
with contextlib.suppress(Exception):
cls.tearDownClass()
raise
# yield
# cls.tearDownClass()

@classmethod
def tearDownClass(cls):
Expand All @@ -128,7 +132,7 @@ def check_all_in_folder(self, folder_name, expected_defs):
if f.endswith(".def"):
count += 1
self.check_def(os.path.join(dirpath, f))
self.assertEqual(count, expected_defs)
assert count == expected_defs

def check_def(self, path):
"""runs command and compares to expected output from def file"""
Expand Down Expand Up @@ -160,13 +164,13 @@ def _run_and_compare(self, definition_file, args, expected_status, expected_out,
# command to reproduce, do not forget first two lines have special meaning
print("\ncd " + cwd + " && " + cmd + " " + args + " 2> <filename>")
(status, out, err) = run_shell_command(cmd, args, cwd)
self.assertEqual(expected_status, status, f"bad command status {status}")
assert expected_status == status, f"bad command status {status}"
prefix = f"Failed check in {cwd} comparing to {definition_file} for command: {cmd}"
compare("\n".join(expected_err), err.decode("utf8"), prefix=prefix, show_whitespace=True)
compare("\n".join(expected_out), out.decode("utf8"), prefix=prefix, show_whitespace=True)


class NoRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
class TestNoRepoSignature(TemporaryFolderClassSetup):
"""runs in a temporary folder (under /tmp in linux) without any .git/.hg/.svn file"""

def get_extra_command_args(self, cwd):
Expand All @@ -185,12 +189,12 @@ def _test_name_func(fun, _, x):
],
name_func=_test_name_func,
)
@mark.timeout(180)
@pytest.mark.timeout(180)
def testSamples(self, folder, case):
self.check_def(os.path.join(f"./samples/{folder}-sample", case + ".def"))


class GitRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
class TestGitRepoSignature(TemporaryFolderClassSetup):
"""runs in a temporary folder with .git file"""

@classmethod
Expand All @@ -202,7 +206,7 @@ def testCodeliteSample(self):
self.check_all_in_folder("./samples/codelite-sample", 1)


class MercurialRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
class TestMercurialRepoSignature(TemporaryFolderClassSetup):
"""runs in a temporary folder with .hg file"""

@classmethod
Expand All @@ -214,7 +218,7 @@ def testCodeliteSample(self):
self.check_all_in_folder("./samples/codelite-sample", 1)


class SvnRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
class TestSvnRepoSignature(TemporaryFolderClassSetup):
"""runs in a temporary folder with .svn file"""

@classmethod
Expand All @@ -227,4 +231,4 @@ def testCodeliteSample(self):


if __name__ == "__main__":
unittest.main()
pytest.main([__file__])
Loading
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