Skip to content

Commit

Permalink
fixed #12308 - adjusted Python test files to match pytest conventions (
Browse files Browse the repository at this point in the history
…#5870)

This allows the tests to be picked up automatically instead of
specifying patterns or filenames.
  • Loading branch information
firewave committed Jan 13, 2024
1 parent ac7a509 commit c1da431
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ jobs:
- name: Run test/cli
run: |
cd test/cli
python3 -m pytest -Werror --strict-markers -vv test-*.py
python3 -m pytest -Werror --strict-markers -vv
cd ../../..
ln -s cppcheck 'cpp check'
cd 'cpp check/test/cli'
python3 -m pytest -Werror --strict-markers -vv test-*.py
python3 -m pytest -Werror --strict-markers -vv
- name: Run cfg tests
if: matrix.os != 'ubuntu-22.04'
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,7 @@ jobs:
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
cd test/cli || exit /b !errorlevel!
:: python -m pytest -Werror --strict-markers -vv --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-helloworld.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-inline-suppress.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-more-projects.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-other.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-proj2.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-suppress-syntaxError.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
- name: Test addons
if: matrix.config == 'release'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Generate dependencies
if: false
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ jobs:
- name: test addons
if: matrix.python-version == '3.9' || matrix.python-version == '3.10'
run: |
python -m pytest --strict-markers -vv addons/test/test-*.py
python -m pytest --strict-markers -vv addons/test
env:
PYTHONPATH: ./addons

- name: test addons
if: matrix.python-version != '3.9' && matrix.python-version != '3.10'
run: |
python -m pytest -Werror --strict-markers -vv addons/test/test-*.py
python -m pytest -Werror --strict-markers -vv addons/test
env:
PYTHONPATH: ./addons

Expand All @@ -162,21 +162,21 @@ jobs:
- name: test reduce
run: |
python -m pytest -Werror --strict-markers -vv tools/test_reduce.py
python -m pytest -Werror --strict-markers -vv tools/reduce_test.py
env:
PYTHONPATH: ./tools

- name: test donate_cpu_lib
if: matrix.python-version != '2.7'
run: |
python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_lib.py
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_lib_test.py
env:
PYTHONPATH: ./tools

- name: test donate_cpu_server
if: matrix.python-version != '2.7'
run: |
python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_server.py
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py
env:
PYTHONPATH: ./tools

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Generate dependencies
if: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
- name: Generate dependencies
run: |
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ bool ImportProject::importSln(std::istream &istr, const std::string &path, const
if (pos1 == std::string::npos)
continue;
std::string vcxproj(line.substr(pos1+1, pos-pos1+7));
vcxproj = Path::toNativeSeparators(std::move(vcxproj));
if (!Path::isAbsolute(vcxproj))
vcxproj = path + vcxproj;
if (!importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString, fileFilters)) {
vcxproj = Path::fromNativeSeparators(std::move(vcxproj));
if (!importVcxproj(vcxproj, variables, emptyString, fileFilters)) {
printError("failed to load '" + vcxproj + "' from Visual Studio solution");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import re
import subprocess
import sys

import pytest
from testutils import cppcheck, assert_cppcheck

Expand All @@ -13,6 +15,11 @@
pytest.skip("'clang' does not exist", allow_module_level=True)


# the IDs differ with Visual Studio
if sys.platform == 'win32':
pytest.skip(allow_module_level=True)


def get_debug_section(title, stdout):
s = re.sub(r'0x[0-9a-fA-F]+', '0x12345678', stdout)
s = re.sub(r'nestedIn: Struct', 'nestedIn: Class', s)
Expand Down Expand Up @@ -129,7 +136,7 @@ def test_log(tmpdir):

args = ['--clang', test_file]
out_lines = [
'Checking {} ...'.format(test_file),
'Checking {} ...'.format(test_file).replace('\\', '/'),
]

assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion test/cli/test-project.py → test/cli/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import os
import json
import sys
from testutils import cppcheck


Expand Down Expand Up @@ -49,6 +50,8 @@ def test_json_entry_file_not_found(tmpdir):
]

expected = "'{}' from compilation database does not exist".format(os.path.join(tmpdir, "bug1.cpp"))
if sys.platform == "win32":
expected = expected.replace('\\', '/')

_test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)

Expand Down Expand Up @@ -117,7 +120,9 @@ def test_sln_project_file_not_found(tmpdir):
"EndProject\r\n"

expected = "Visual Studio project file is not a valid XML - XML_ERROR_FILE_NOT_FOUND\n" \
"cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli\\cli.vcxproj"))
"cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli/cli.vcxproj"))
if sys.platform == "win32":
expected = expected.replace('\\', '/')

_test_project_error(tmpdir, "sln", content, expected)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c1da431

Please sign in to comment.