Skip to content

Commit bbba111

Browse files
Some test refactoring (#357)
* increase default pytest timeout to 481s for debugging room * [remove duplicate boost sample for testing inspect headers](1e39bff) * [use pytest parametrized instead of parameterized & google todo credit](c0eb131) * add script to update CLI test definitions --------- Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 777a8a7 commit bbba111

File tree

6 files changed

+57
-141
lines changed

6 files changed

+57
-141
lines changed

cpplint_clitest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import tempfile
4040

4141
import pytest
42-
from parameterized import parameterized # type: ignore[import-untyped]
4342
from testfixtures import compare # type: ignore[import-untyped]
4443

4544
import cpplint # noqa: F401
@@ -55,7 +54,7 @@ def run_shell_command(cmd: str, args: str, cwd: str = ".") -> tuple[int, bytes,
5554
args: A string with arguments to the command.
5655
cwd: from which folder to run.
5756
"""
58-
cmd, args = cmd.split(), args.split() # type: ignore[assignment]
57+
cmd, args = cmd.split(), args.replace('"', "").split() # type: ignore[assignment]
5958
proc = subprocess.run(cmd + args, cwd=cwd, capture_output=True, check=False)
6059
out, err = proc.stdout, proc.stderr
6160

@@ -175,14 +174,14 @@ class TestNoRepoSignature(TemporaryFolderClassSetup):
175174
def get_extra_command_args(self, cwd):
176175
return f" --repository {self._root} "
177176

178-
@parameterized.expand(
177+
@pytest.mark.parametrize(
178+
("folder", "case"),
179179
[
180180
(folder, case[:-4])
181181
for folder in ["chromium", "vlc", "silly", "boost", "protobuf", "codelite", "v8"]
182182
for case in os.listdir(f"./samples/{folder}-sample")
183183
if case.endswith(".def")
184184
],
185-
name_func=lambda fun, _, x: f"test_{x.args[0]}_sample-{x.args[1]}",
186185
)
187186
@pytest.mark.timeout(180)
188187
def test_samples(self, folder, case):

cpplint_unittest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
"""Unit test for cpplint.py."""
3232

33-
# TODO(unknown): Add a good test that tests UpdateIncludeState.
33+
# TODO(google): Add a good test that tests UpdateIncludeState.
3434

3535
import codecs
3636
import os
@@ -43,7 +43,6 @@
4343
import tempfile
4444

4545
import pytest
46-
from parameterized import parameterized # type: ignore[import-untyped]
4746

4847
import cpplint
4948

@@ -2230,7 +2229,7 @@ def testConstStringReferenceMembers(self):
22302229
"const string &turing",
22312230
"const string & godel",
22322231
]
2233-
# TODO(unknown): Enable also these tests if and when we ever
2232+
# TODO(google): Enable also these tests if and when we ever
22342233
# decide to check for arbitrary member references.
22352234
# "const Turing & a",
22362235
# "const Church& a",
@@ -4604,7 +4603,7 @@ def testConditionals(self):
46044603
"",
46054604
)
46064605

4607-
@parameterized.expand(["else if", "if", "while", "for", "switch"])
4606+
@pytest.mark.parametrize("keyword", ["else if", "if", "while", "for", "switch"])
46084607
def testControlClauseWithParensNewline(self, keyword):
46094608
# The % 2 part is pseudorandom whitespace-support testing
46104609
self.TestLintContains(
@@ -4616,7 +4615,7 @@ def testControlClauseWithParensNewline(self, keyword):
46164615
f" should be on a separate line [whitespace/newline] [5]",
46174616
)
46184617

4619-
@parameterized.expand(["else", "do", "try"])
4618+
@pytest.mark.parametrize("keyword", ["else", "do", "try"])
46204619
def testControlClauseWithoutParensNewline(self, keyword):
46214620
# The % 2 part is pseudorandom whitespace-support testing
46224621
self.TestLintContains(

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies = [ ]
4141

4242
optional-dependencies.dev = [
4343
"mypy",
44-
"parameterized",
4544
"pylint>=3.3.4",
4645
"pytest",
4746
"pytest-cov",
@@ -206,4 +205,4 @@ addopts = "--color=yes --cov-fail-under=90 --cov=cpplint"
206205
python_files = [ "*test.py" ]
207206
required_plugins = [ "pytest-cov", "pytest-timeout" ]
208207
testpaths = [ "." ]
209-
timeout = 60
208+
timeout = 481

regen-defs.zsh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/zsh
2+
3+
# Input the path of cpplint here
4+
cpplint="$HOME/Documents/cpplint/cpplint.py"
5+
6+
cd samples/ || exit 74 # EX_IOERROR
7+
8+
# Loop through all .def files in the given directories
9+
folders=(${(f)"$(cat)"})
10+
for folder in $folders; do
11+
cd "$folder-sample/" || exit 66 # EX_NOINPUT
12+
for file in ./*.def; do
13+
if [[ ! -s "$file" ]]; then
14+
echo "Skipping empty file: $file"
15+
continue
16+
fi
17+
echo "Processing $file..."
18+
19+
# Extract the command from the first line of the file
20+
cmd=$(head -n 1 "$file")
21+
22+
# Create temporary files for stdout and stderr
23+
stdout_file=$(mktemp)
24+
stderr_file=$(mktemp)
25+
26+
# Execute the command and capture stdout and stderr
27+
uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
28+
ret_code=$?
29+
30+
# Count the number of lines in stdout
31+
(( num_lines=$(wc -l < "$stdout_file") + 1 ))
32+
33+
# Overwrite the original definition file
34+
{
35+
echo "$cmd"
36+
echo "$ret_code"
37+
echo "$num_lines"
38+
cat "$stdout_file"
39+
echo
40+
cat "$stderr_file"
41+
echo
42+
} > "$file"
43+
44+
# Clean up temporary files
45+
rm "$stdout_file" "$stderr_file"
46+
done
47+
cd ..
48+
done

samples/boost-sample/exclude.def

Lines changed: 0 additions & 129 deletions
This file was deleted.

samples/boost-sample/headers_inspect.def renamed to samples/boost-sample/headers_inspect_exclude.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
src/inspect/*
1+
--recursive "--exclude=src/tr1/*" src
22
1
33
3
44
Done processing src/inspect/unnamed_namespace_check.hpp

0 commit comments

Comments
 (0)
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