aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/sql2yql/test_sql_negative.py
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-11-20 11:14:58 +0000
commit31773f157bf8164364649b5f470f52dece0a4317 (patch)
tree33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /yql/essentials/tests/sql/sql2yql/test_sql_negative.py
parent2c7938962d8689e175574fc1e817c05049f27905 (diff)
parenteff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff)
downloadydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz
Merge branch 'rightlib' into mergelibs-241120-1113
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]