37
37
import subprocess
38
38
import sys
39
39
import tempfile
40
- import unittest
41
40
41
+ import pytest
42
42
from parameterized import parameterized
43
- from pytest import mark
44
43
from testfixtures import compare
45
44
45
+ import cpplint # noqa: F401
46
+
46
47
BASE_CMD = sys .executable + " " + os .path .abspath ("./cpplint.py " )
47
48
48
49
@@ -74,15 +75,15 @@ def run_shell_command(cmd: str, args: str, cwd="."):
74
75
return proc .returncode , out , err
75
76
76
77
77
- class UsageTest ( unittest . TestCase ) :
78
+ class TestUsage :
78
79
def testHelp (self ):
79
80
(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"\n Syntax: cpplint" ) )
81
+ assert status == 0
82
+ assert out == b""
83
+ assert err .startswith (b"\n Syntax: cpplint" )
83
84
84
85
85
- class TemporaryFolderClassSetup ( unittest . TestCase ) :
86
+ class TemporaryFolderClassSetup :
86
87
"""
87
88
Regression tests: The test starts a filetreewalker scanning for files name *.def
88
89
Such files are expected to have as first line the argument
@@ -92,6 +93,7 @@ class TemporaryFolderClassSetup(unittest.TestCase):
92
93
systemerr output (two blank lines at end).
93
94
"""
94
95
96
+ @pytest .fixture (autouse = True , name = "setUpClass()" , scope = "class" )
95
97
@classmethod
96
98
def setUpClass (cls ):
97
99
"""setup tmp folder for testing with samples and custom additions by subclasses"""
@@ -103,6 +105,8 @@ def setUpClass(cls):
103
105
with contextlib .suppress (Exception ):
104
106
cls .tearDownClass ()
105
107
raise
108
+ # yield
109
+ # cls.tearDownClass()
106
110
107
111
@classmethod
108
112
def tearDownClass (cls ):
@@ -128,7 +132,7 @@ def check_all_in_folder(self, folder_name, expected_defs):
128
132
if f .endswith (".def" ):
129
133
count += 1
130
134
self .check_def (os .path .join (dirpath , f ))
131
- self . assertEqual ( count , expected_defs )
135
+ assert count == expected_defs
132
136
133
137
def check_def (self , path ):
134
138
"""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,
160
164
# command to reproduce, do not forget first two lines have special meaning
161
165
print ("\n cd " + cwd + " && " + cmd + " " + args + " 2> <filename>" )
162
166
(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 } "
164
168
prefix = f"Failed check in { cwd } comparing to { definition_file } for command: { cmd } "
165
169
compare ("\n " .join (expected_err ), err .decode ("utf8" ), prefix = prefix , show_whitespace = True )
166
170
compare ("\n " .join (expected_out ), out .decode ("utf8" ), prefix = prefix , show_whitespace = True )
167
171
168
172
169
- class NoRepoSignatureTests (TemporaryFolderClassSetup , unittest . TestCase ):
173
+ class TestNoRepoSignature (TemporaryFolderClassSetup ):
170
174
"""runs in a temporary folder (under /tmp in linux) without any .git/.hg/.svn file"""
171
175
172
176
def get_extra_command_args (self , cwd ):
@@ -185,12 +189,12 @@ def _test_name_func(fun, _, x):
185
189
],
186
190
name_func = _test_name_func ,
187
191
)
188
- @mark .timeout (180 )
192
+ @pytest . mark .timeout (180 )
189
193
def testSamples (self , folder , case ):
190
194
self .check_def (os .path .join (f"./samples/{ folder } -sample" , case + ".def" ))
191
195
192
196
193
- class GitRepoSignatureTests (TemporaryFolderClassSetup , unittest . TestCase ):
197
+ class TestGitRepoSignature (TemporaryFolderClassSetup ):
194
198
"""runs in a temporary folder with .git file"""
195
199
196
200
@classmethod
@@ -202,7 +206,7 @@ def testCodeliteSample(self):
202
206
self .check_all_in_folder ("./samples/codelite-sample" , 1 )
203
207
204
208
205
- class MercurialRepoSignatureTests (TemporaryFolderClassSetup , unittest . TestCase ):
209
+ class TestMercurialRepoSignature (TemporaryFolderClassSetup ):
206
210
"""runs in a temporary folder with .hg file"""
207
211
208
212
@classmethod
@@ -214,7 +218,7 @@ def testCodeliteSample(self):
214
218
self .check_all_in_folder ("./samples/codelite-sample" , 1 )
215
219
216
220
217
- class SvnRepoSignatureTests (TemporaryFolderClassSetup , unittest . TestCase ):
221
+ class TestSvnRepoSignature (TemporaryFolderClassSetup ):
218
222
"""runs in a temporary folder with .svn file"""
219
223
220
224
@classmethod
@@ -227,4 +231,4 @@ def testCodeliteSample(self):
227
231
228
232
229
233
if __name__ == "__main__" :
230
- unittest .main ()
234
+ pytest .main ([ __file__ ] )
0 commit comments