aboutsummaryrefslogtreecommitdiffstats
path: root/library/python
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
committervitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
commit6ffe9e53658409f212834330e13564e4952558f6 (patch)
tree85b1e00183517648b228aafa7c8fb07f5276f419 /library/python
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'library/python')
-rw-r--r--library/python/cpp_test/conftest.py18
-rw-r--r--library/python/cpp_test/test_cpp.py41
-rw-r--r--library/python/cpp_test/ya.make19
-rw-r--r--library/python/testing/style/rules.py40
-rw-r--r--library/python/testing/style/ya.make11
5 files changed, 129 insertions, 0 deletions
diff --git a/library/python/cpp_test/conftest.py b/library/python/cpp_test/conftest.py
new file mode 100644
index 0000000000..40576c3aac
--- /dev/null
+++ b/library/python/cpp_test/conftest.py
@@ -0,0 +1,18 @@
+import difflib
+
+
+def iter_diff(fr, to):
+ for l in difflib.unified_diff(fr.splitlines(), to.splitlines(), fromfile='L', tofile='R'):
+ l = l.rstrip('\n')
+
+ if l:
+ if l[0] == '-':
+ l = '[[bad]]' + l + '[[rst]]'
+ elif l[0] == '+':
+ l = '[[good]]' + l + '[[rst]]'
+
+ yield l
+
+
+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
new file mode 100644
index 0000000000..0882dd541b
--- /dev/null
+++ b/library/python/cpp_test/test_cpp.py
@@ -0,0 +1,41 @@
+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
+
+
+STYLE_CONFIG_JSON_12 = json.dumps(yaml.safe_load(lpr.find('/cpp_style/config/12')))
+STYLE_CONFIG_JSON_14 = json.dumps(yaml.safe_load(lpr.find('/cpp_style/config/14')))
+
+RES_FILE_PREFIX = '/cpp_style/files/'
+CHECKED_PATHS = list(lpr.iterkeys(RES_FILE_PREFIX, strip_prefix=True))
+
+
+def check_style(filename, actual_source):
+ try:
+ clang_format_binary = yatest.common.binary_path('contrib/libs/clang12/tools/clang-format/clang-format')
+ config = STYLE_CONFIG_JSON_12
+ except Exception:
+ clang_format_binary = yatest.common.binary_path('contrib/libs/clang14/tools/clang-format/clang-format')
+ config = STYLE_CONFIG_JSON_14
+
+ 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()
+
+
+@pytest.mark.parametrize('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
new file mode 100644
index 0000000000..c325e2ad5f
--- /dev/null
+++ b/library/python/cpp_test/ya.make
@@ -0,0 +1,19 @@
+PY3_LIBRARY()
+
+PEERDIR(
+ contrib/python/PyYAML
+ library/python/resource
+ library/python/testing/style
+)
+
+TEST_SRCS(
+ conftest.py
+ test_cpp.py
+)
+
+RESOURCE(
+ devtools/ya/handlers/style/style_config /cpp_style/config/12
+ devtools/ya/handlers/style/style_config_14 /cpp_style/config/14
+)
+
+END()
diff --git a/library/python/testing/style/rules.py b/library/python/testing/style/rules.py
new file mode 100644
index 0000000000..1f4d283769
--- /dev/null
+++ b/library/python/testing/style/rules.py
@@ -0,0 +1,40 @@
+import os
+import six
+
+
+def style_required(path, data, skip_links=True):
+ if get_skip_reason(path, data, skip_links):
+ return False
+ return True
+
+
+def get_skip_reason(path, data, skip_links=True):
+ return _path_skip_reason(path, skip_links) or _content_skip_reason(path, data)
+
+
+def _path_skip_reason(path, skip_links=True):
+ if '/generated/' in path:
+ return "path '{}' contains '/generated/'".format(path)
+
+ if path and '/contrib/' in path:
+ return "path '{}' contains '/contrib/'".format(path)
+
+ if path and '/vendor/' in path:
+ return "path '{}' contains '/vendor/'".format(path)
+
+ if skip_links and os.path.islink(path):
+ return "path '{}' is a symlink".format(path)
+
+
+def _content_skip_reason(path, data):
+ if not isinstance(data, six.string_types):
+ data = data.decode()
+
+ for substr in [
+ '# DO_NOT_STYLE',
+ '// DO_NOT_STYLE',
+ 'THIS SOFTWARE',
+ 'WITHOUT WARRANTY',
+ ]:
+ if substr in data:
+ return "file '{}' contains '{}'".format(path, substr)
diff --git a/library/python/testing/style/ya.make b/library/python/testing/style/ya.make
new file mode 100644
index 0000000000..7d3e9efd6b
--- /dev/null
+++ b/library/python/testing/style/ya.make
@@ -0,0 +1,11 @@
+PY23_LIBRARY()
+
+PY_SRCS(
+ rules.py
+)
+
+PEERDIR(
+ contrib/python/six
+)
+
+END()