test_cpp.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import json
  2. import os
  3. import subprocess
  4. import pytest
  5. import yaml
  6. import yatest
  7. from library.python.testing.style import rules
  8. import library.python.resource as lpr
  9. # keep in sync with the logic in https://a.yandex-team.ru/arcadia/devtools/ya/handlers/style/cpp_style.py?rev=r12543375#L21
  10. STYLE_CONFIG_JSON = json.dumps(yaml.safe_load(lpr.find('resfs/file/config.clang-format')))
  11. RES_FILE_PREFIX = '/cpp_style/files/'
  12. CHECKED_PATHS = list(lpr.iterkeys(RES_FILE_PREFIX, strip_prefix=True))
  13. def check_style(filename, actual_source):
  14. clang_format_binary = yatest.common.binary_path('contrib/libs/clang16/tools/clang-format/clang-format')
  15. config = STYLE_CONFIG_JSON
  16. command = [clang_format_binary, '-assume-filename=' + filename, '-style=' + config]
  17. styled_source = subprocess.check_output(command, input=actual_source)
  18. assert actual_source.decode() == styled_source.decode()
  19. @pytest.mark.parametrize('path', CHECKED_PATHS)
  20. def test_cpp_style(path):
  21. data = lpr.find(RES_FILE_PREFIX + path)
  22. skip_reason = rules.get_skip_reason(path, data, skip_links=False)
  23. if skip_reason:
  24. raise pytest.skip("style check is omitted: {}".format(skip_reason))
  25. else:
  26. check_style(os.path.basename(path), data)