pure.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import codecs
  2. import os
  3. import pytest
  4. import re
  5. import yql_utils
  6. import yatest.common
  7. from yql_utils import execute, get_tables, get_files, get_http_files, \
  8. KSV_ATTR, yql_binary_path, is_xfail, is_canonize_peephole, is_peephole_use_blocks, is_canonize_lineage, \
  9. is_skip_forceblocks, get_param, normalize_source_code_path, replace_vals, get_gateway_cfg_suffix, \
  10. do_custom_query_check, stable_result_file, stable_table_file, is_with_final_result_issues, \
  11. normalize_result
  12. from yqlrun import YQLRun
  13. from test_utils import get_config, get_parameters_json
  14. from test_file_common import run_file, run_file_no_cache, get_gateways_config, get_sql_query
  15. ASTDIFF_PATH = yql_binary_path('yql/essentials/tools/astdiff/astdiff')
  16. MINIRUN_PATH = yql_binary_path('yql/essentials/tools/minirun/minirun')
  17. DATA_PATH = yatest.common.source_path('yql/essentials/tests/s-expressions/suites')
  18. def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
  19. if get_gateway_cfg_suffix() != '' and what not in ('Results','LLVM'):
  20. pytest.skip('non-trivial gateways.conf')
  21. config = get_config(suite, case, cfg, data_path=DATA_PATH)
  22. xfail = is_xfail(config)
  23. if xfail and what != 'Results':
  24. pytest.skip('xfail is not supported in this mode')
  25. program_sql = os.path.join(DATA_PATH, suite, '%s.yqls' % case)
  26. with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
  27. sql_query = program_file_descr.read()
  28. extra_final_args = []
  29. if is_with_final_result_issues(config):
  30. extra_final_args += ['--with-final-issues']
  31. (res, tables_res) = run_file('pure', suite, case, cfg, config, yql_http_file_server, MINIRUN_PATH,
  32. extra_args=extra_final_args, allow_llvm=False, data_path=DATA_PATH, run_sql=False)
  33. to_canonize = []
  34. assert not tables_res
  35. if what == 'Results':
  36. if xfail:
  37. return None
  38. if do_custom_query_check(res, sql_query):
  39. return None
  40. if os.path.exists(res.results_file):
  41. stable_result_file(res)
  42. to_canonize.append(yatest.common.canonical_file(res.results_file))
  43. if res.std_err:
  44. to_canonize.append(normalize_source_code_path(res.std_err))
  45. if what == 'Debug':
  46. to_canonize = [yatest.common.canonical_file(res.opt_file, diff_tool=ASTDIFF_PATH)]
  47. if what == 'RunOnOpt' or what == 'LLVM':
  48. is_llvm = (what == 'LLVM')
  49. files = get_files(suite, config, DATA_PATH)
  50. http_files = get_http_files(suite, config, DATA_PATH)
  51. http_files_urls = yql_http_file_server.register_files({}, http_files)
  52. parameters = get_parameters_json(suite, config, DATA_PATH)
  53. query_sql = get_sql_query('pure', suite, case, config, DATA_PATH, template='.yqls') if is_llvm else None
  54. yqlrun = YQLRun(
  55. prov='pure',
  56. keep_temp=False,
  57. gateway_config=get_gateways_config(http_files, yql_http_file_server, allow_llvm=is_llvm),
  58. udfs_dir=yql_binary_path('yql/essentials/tests/common/test_framework/udfs_deps'),
  59. binary=MINIRUN_PATH
  60. )
  61. opt_res, opt_tables_res = execute(
  62. yqlrun,
  63. program=res.opt if not is_llvm else query_sql,
  64. run_sql=False,
  65. files=files,
  66. urls=http_files_urls,
  67. check_error=True,
  68. verbose=True,
  69. parameters=parameters)
  70. assert os.path.exists(opt_res.results_file) == os.path.exists(res.results_file)
  71. assert not opt_tables_res
  72. if os.path.exists(res.results_file):
  73. base_res_yson = normalize_result(stable_result_file(res), False)
  74. opt_res_yson = normalize_result(stable_result_file(opt_res), False)
  75. # Compare results
  76. assert opt_res_yson == base_res_yson, 'RESULTS_DIFFER\n' \
  77. 'Result:\n %(opt_res_yson)s\n\n' \
  78. 'Base result:\n %(base_res_yson)s\n' % locals()
  79. return None
  80. return to_canonize