diff options
Diffstat (limited to 'library/python')
| -rw-r--r-- | library/python/cpp_test/conftest.py | 18 | ||||
| -rw-r--r-- | library/python/cpp_test/test_cpp.py | 37 | ||||
| -rw-r--r-- | library/python/cpp_test/ya.make | 15 | ||||
| -rw-r--r-- | library/python/testing/custom_linter_util/tests/test_params.py | 83 | ||||
| -rw-r--r-- | library/python/testing/custom_linter_util/tests/test_reporter.py | 68 | ||||
| -rw-r--r-- | library/python/testing/custom_linter_util/tests/ya.make | 12 |
6 files changed, 163 insertions, 70 deletions
diff --git a/library/python/cpp_test/conftest.py b/library/python/cpp_test/conftest.py deleted file mode 100644 index 5e9a0fbf9a9..00000000000 --- a/library/python/cpp_test/conftest.py +++ /dev/null @@ -1,18 +0,0 @@ -import difflib - - -def iter_diff(fr, to): - for line in difflib.unified_diff(fr.splitlines(), to.splitlines(), fromfile='L', tofile='R'): - line = line.rstrip('\n') - - if line: - if line[0] == '-': - line = '[[bad]]' + line + '[[rst]]' - elif line[0] == '+': - line = '[[good]]' + line + '[[rst]]' - - yield line - - -def pytest_assertrepr_compare(op, left, right): - return ['failed, show diff'] + list(iter_diff(left, right)) diff --git a/library/python/cpp_test/test_cpp.py b/library/python/cpp_test/test_cpp.py deleted file mode 100644 index b4c78f82716..00000000000 --- a/library/python/cpp_test/test_cpp.py +++ /dev/null @@ -1,37 +0,0 @@ -import json -import os -import subprocess - -import pytest -import yaml -import yatest - -from library.python.testing.style import rules -import library.python.resource as lpr - - -# keep in sync with the logic in https://a.yandex-team.ru/arcadia/devtools/ya/handlers/style/cpp_style.py?rev=r12543375#L21 -STYLE_CONFIG_JSON = json.dumps(yaml.safe_load(lpr.find('resfs/file/config.clang-format'))) - -RES_FILE_PREFIX = '/cpp_style/files/' -CHECKED_PATHS = list(lpr.iterkeys(RES_FILE_PREFIX, strip_prefix=True)) - - -def check_style(filename, actual_source): - clang_format_binary = yatest.common.binary_path('contrib/libs/clang16/tools/clang-format/clang-format') - config = STYLE_CONFIG_JSON - - command = [clang_format_binary, '-assume-filename=' + filename, '-style=' + config] - styled_source = subprocess.check_output(command, input=actual_source) - - assert actual_source.decode() == styled_source.decode() - - [email protected]('path', CHECKED_PATHS) -def test_cpp_style(path): - data = lpr.find(RES_FILE_PREFIX + path) - skip_reason = rules.get_skip_reason(path, data, skip_links=False) - if skip_reason: - raise pytest.skip("style check is omitted: {}".format(skip_reason)) - else: - check_style(os.path.basename(path), data) diff --git a/library/python/cpp_test/ya.make b/library/python/cpp_test/ya.make deleted file mode 100644 index 9fbc9212987..00000000000 --- a/library/python/cpp_test/ya.make +++ /dev/null @@ -1,15 +0,0 @@ -PY3_LIBRARY() - -PEERDIR( - build/config/tests/cpp_style - contrib/python/PyYAML - library/python/resource - library/python/testing/style -) - -TEST_SRCS( - conftest.py - test_cpp.py -) - -END() diff --git a/library/python/testing/custom_linter_util/tests/test_params.py b/library/python/testing/custom_linter_util/tests/test_params.py new file mode 100644 index 00000000000..025bb3eef22 --- /dev/null +++ b/library/python/testing/custom_linter_util/tests/test_params.py @@ -0,0 +1,83 @@ +import json + +from library.python.testing.custom_linter_util import linter_params +from yatest.common import work_path + + +SOURCE_ROOT = "TEST_SOURCE_ROOT" +PROJECT_PATH = "TEST_PROJECT_PATH" +OUTPUT_PATH = "TEST_OUTPUT_PATH" +REPORT_FILE = "TEST_REPORT_FILE" +LINT_NAME = "important-lint" +DEPS = { + "dep1": "/path/to/dep1", + "dep2": "/path/to/dep2", +} +GLOBAL_RESOURCES = { + "TOOL1_GLOBAL_RESOURCES": "/path/to/resource1", + "TOOL2_GLOBAL_RESOURCES": "/path/to/resource2", +} +CONFIGS = ["path/to/config1", "path/to/config2"] +EXTRA_PARAMS = { + "var1": "val1", + "var2": "val2", +} +FILES = ["file1.cpp", "file2.cpp"] + +EXPECTED = linter_params.LinterArgs( + source_root=SOURCE_ROOT, + project_path=PROJECT_PATH, + output_path=OUTPUT_PATH, + report_file=REPORT_FILE, + lint_name=LINT_NAME, + depends=DEPS, + global_resources=GLOBAL_RESOURCES, + configs=CONFIGS, + extra_params=EXTRA_PARAMS, + files=FILES, +) + + +def test_cmd_line_params(): + raw_args = [ + "--source-root", SOURCE_ROOT, + "--project-path", PROJECT_PATH, + "--output-path", OUTPUT_PATH, + "--report-file", REPORT_FILE, + "--lint-name", LINT_NAME, + ] + for rel, abs in DEPS.items(): + raw_args += ["--depends", ":".join([rel, abs])] + for var, path in GLOBAL_RESOURCES.items(): + raw_args += ["--global-resource", ":".join([var, path])] + for cfg in CONFIGS: + raw_args += ["--config", cfg] + for var, val in EXTRA_PARAMS.items(): + raw_args += ["--extra-param", "=".join([var, val])] + raw_args += FILES + + got = linter_params.get_params(raw_args) + + assert got == EXPECTED + + +def test_json_params(): + params_file = work_path("params.josn") + params = { + "source_root": SOURCE_ROOT, + "project_path": PROJECT_PATH, + "output_path": OUTPUT_PATH, + "report_file": REPORT_FILE, + "lint_name": LINT_NAME, + "depends": DEPS, + "global_resources": GLOBAL_RESOURCES, + "configs": CONFIGS, + "extra_params": EXTRA_PARAMS, + "files": FILES, + } + with open(params_file, "w") as f: + json.dump(params, f) + + got = linter_params.get_params(["--params", params_file]) + + assert got == EXPECTED diff --git a/library/python/testing/custom_linter_util/tests/test_reporter.py b/library/python/testing/custom_linter_util/tests/test_reporter.py new file mode 100644 index 00000000000..81bfa3c9ef0 --- /dev/null +++ b/library/python/testing/custom_linter_util/tests/test_reporter.py @@ -0,0 +1,68 @@ +import json + +from library.python.testing.custom_linter_util.reporter import LintReport, LintStatus +from yatest.common import output_path, context + + +def dump_and_load(report): + report_file = output_path(context.test_name) + report.dump(report_file=report_file) + with open(report_file) as f: + return json.load(f) + + +def test_empty_report(): + report = LintReport() + got = dump_and_load(report) + assert got == {"report": {}} + + +def test_good_test(): + report = LintReport() + report.add("file.cpp", LintStatus.GOOD) + + got = dump_and_load(report) + + assert got == { + "report": { + "file.cpp": { + "status": "GOOD", + "message": "", + "elapsed": 0.0, + } + } + } + + +def test_skipped_test(): + report = LintReport() + report.add("file.cpp", LintStatus.SKIPPED, "Generated file", elapsed=1.0) + + got = dump_and_load(report) + + assert got == { + "report": { + "file.cpp": { + "status": "SKIPPED", + "message": "Generated file", + "elapsed": 1.0, + } + } + } + + +def test_failed_test(): + report = LintReport() + report.add("file.cpp", LintStatus.FAIL, "Test failed", elapsed=2.0) + + got = dump_and_load(report) + + assert got == { + "report": { + "file.cpp": { + "status": "FAIL", + "message": "Test failed", + "elapsed": 2.0, + } + } + } diff --git a/library/python/testing/custom_linter_util/tests/ya.make b/library/python/testing/custom_linter_util/tests/ya.make new file mode 100644 index 00000000000..1fde32d937a --- /dev/null +++ b/library/python/testing/custom_linter_util/tests/ya.make @@ -0,0 +1,12 @@ +PY3TEST() + +TEST_SRCS( + test_params.py + test_reporter.py +) + +PEERDIR( + library/python/testing/custom_linter_util +) + +END() |
