Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81a65e6

Browse files
committed
1 parent af30092 commit 81a65e6

File tree

4 files changed

+863
-915
lines changed

4 files changed

+863
-915
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
- tomli
1616

1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.10.0
18+
rev: v0.11.0
1919
hooks:
2020
- id: ruff
2121
- id: ruff-format

cpplint_clitest.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
import subprocess
3838
import sys
3939
import tempfile
40-
import unittest
4140

41+
import pytest
4242
from parameterized import parameterized
43-
from pytest import mark
4443
from testfixtures import compare
4544

45+
import cpplint # noqa: F401
46+
4647
BASE_CMD = sys.executable + " " + os.path.abspath("./cpplint.py ")
4748

4849

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

7677

77-
class UsageTest(unittest.TestCase):
78+
class TestUsage:
7879
def testHelp(self):
7980
(status, out, err) = run_shell_command(BASE_CMD, "--help")
80-
self.assertEqual(0, status)
81-
self.assertEqual(b"", out)
82-
self.assertTrue(err.startswith(b"\nSyntax: cpplint"))
81+
assert status == 0
82+
assert out == b""
83+
assert err.startswith(b"\nSyntax: cpplint")
8384

8485

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

96+
@pytest.fixture(autouse=True, name="setUpClass()", scope="class")
9597
@classmethod
9698
def setUpClass(cls):
9799
"""setup tmp folder for testing with samples and custom additions by subclasses"""
@@ -103,6 +105,8 @@ def setUpClass(cls):
103105
with contextlib.suppress(Exception):
104106
cls.tearDownClass()
105107
raise
108+
# yield
109+
# cls.tearDownClass()
106110

107111
@classmethod
108112
def tearDownClass(cls):
@@ -128,7 +132,7 @@ def check_all_in_folder(self, folder_name, expected_defs):
128132
if f.endswith(".def"):
129133
count += 1
130134
self.check_def(os.path.join(dirpath, f))
131-
self.assertEqual(count, expected_defs)
135+
assert count == expected_defs
132136

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

168172

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

172176
def get_extra_command_args(self, cwd):
@@ -185,12 +189,12 @@ def _test_name_func(fun, _, x):
185189
],
186190
name_func=_test_name_func,
187191
)
188-
@mark.timeout(180)
192+
@pytest.mark.timeout(180)
189193
def testSamples(self, folder, case):
190194
self.check_def(os.path.join(f"./samples/{folder}-sample", case + ".def"))
191195

192196

193-
class GitRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
197+
class TestGitRepoSignature(TemporaryFolderClassSetup):
194198
"""runs in a temporary folder with .git file"""
195199

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

204208

205-
class MercurialRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
209+
class TestMercurialRepoSignature(TemporaryFolderClassSetup):
206210
"""runs in a temporary folder with .hg file"""
207211

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

216220

217-
class SvnRepoSignatureTests(TemporaryFolderClassSetup, unittest.TestCase):
221+
class TestSvnRepoSignature(TemporaryFolderClassSetup):
218222
"""runs in a temporary folder with .svn file"""
219223

220224
@classmethod
@@ -227,4 +231,4 @@ def testCodeliteSample(self):
227231

228232

229233
if __name__ == "__main__":
230-
unittest.main()
234+
pytest.main([__file__])

0 commit comments

Comments
 (0)