aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/sql2yql/test_sql_negative.py
diff options
context:
space:
mode:
authorudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 19:21:17 +0300
committerudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 19:32:13 +0300
commit321925491e7ee4c1fddd0294839f35d2104d637d (patch)
tree44e52a209154e8cb86f653ee059f42d5326faec3 /yql/essentials/tests/sql/sql2yql/test_sql_negative.py
parentee98714b4bafd7ac4bc0b68e563b752cbdb7af52 (diff)
downloadydb-321925491e7ee4c1fddd0294839f35d2104d637d.tar.gz
YQL-19206 Move contrib/ydb/library/yql/tests/sql/sql2yql -> yql/essentials/tests/sql/sql2yql
commit_hash:137ab446f8ed4df274d02b251cbe5e2bb08c8194
Diffstat (limited to 'yql/essentials/tests/sql/sql2yql/test_sql_negative.py')
-rw-r--r--yql/essentials/tests/sql/sql2yql/test_sql_negative.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/sql2yql/test_sql_negative.py b/yql/essentials/tests/sql/sql2yql/test_sql_negative.py
new file mode 100644
index 0000000000..bf43ed43f1
--- /dev/null
+++ b/yql/essentials/tests/sql/sql2yql/test_sql_negative.py
@@ -0,0 +1,68 @@
+import os
+import pytest
+import yatest.common
+from yql_utils import get_supported_providers, get_param
+
+from test_utils import pytest_generate_tests_for_run, get_config, SQLRUN_PATH, DATA_PATH
+
+NEGATIVE_TEMPLATE = '.sqlx'
+
+
+def pytest_generate_tests(metafunc):
+ pytest_generate_tests_for_run(metafunc, NEGATIVE_TEMPLATE)
+
+
+def run_sql2yql(program_sql, out_dir, err_file_path):
+ def out_file(name):
+ return os.path.join(out_dir, name)
+
+ # translate sql to yql
+ program_yql = out_file('program.yql')
+
+ cmd_sql = [
+ SQLRUN_PATH,
+ '--yql',
+ '--output=' + program_yql,
+ '--syntax-version=1',
+ '/dev/stdin',
+ ]
+ with open(program_sql) as f:
+ sql_res = yatest.common.process.execute(cmd_sql, check_exit_code=False, stdin=f, env={'YQL_DETERMINISTIC_MODE': '1'})
+
+ if sql_res.exit_code:
+ sql_stderr = sql_res.std_err.strip()
+ assert sql_stderr
+ with open(err_file_path, 'wb') as err_file:
+ err_file.write(sql_stderr)
+
+ return sql_res
+
+
+def test(suite, case, cfg, tmpdir):
+ config = get_config(suite, case, cfg)
+
+ if 'yt' not in get_supported_providers(config):
+ pytest.skip('YT provider is not supported here')
+
+ if get_param('TARGET_PLATFORM'):
+ if "yson" in case:
+ pytest.skip('yson is not supported on non-default target platform')
+
+ program_sql = os.path.join(DATA_PATH, suite, case + NEGATIVE_TEMPLATE)
+ out_dir = tmpdir.mkdir(suite).mkdir(case).dirname
+ files = []
+
+ err_file_path = os.path.join(out_dir, 'err_file.out')
+ res = run_sql2yql(program_sql, out_dir, err_file_path)
+
+ with open(program_sql) as f:
+ program_sql_content = f.read()
+
+ assert res.exit_code != 0, 'execute finished without error, on file: %s, query:\n%s' % \
+ (program_sql, program_sql_content)
+ assert os.path.getsize(err_file_path) > 0, 'exit code is %d, but error is empty, on file: %s, query:\n%s' % \
+ (res.exit_code, program_sql, program_sql_content)
+
+ files.append(err_file_path)
+
+ return [yatest.common.canonical_file(file_name) for file_name in files]