aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/testing
diff options
context:
space:
mode:
authorexprmntr <exprmntr@yandex-team.ru>2022-02-10 16:46:50 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:50 +0300
commit078ddb2fb76387cae14e8c3ceb5a896009a5a539 (patch)
treedda2d61bf8f818c76b5602b79366b5fcbcf2e479 /library/python/testing
parent5085152b94bf621933243a498def7f37d2e76b58 (diff)
downloadydb-078ddb2fb76387cae14e8c3ceb5a896009a5a539.tar.gz
Restoring authorship annotation for exprmntr <exprmntr@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/testing')
-rw-r--r--library/python/testing/import_test/import_test.py36
-rw-r--r--library/python/testing/import_test/ya.make12
-rw-r--r--library/python/testing/recipe/__init__.py158
-rw-r--r--library/python/testing/recipe/ya.make10
-rw-r--r--library/python/testing/ya.make2
-rw-r--r--library/python/testing/yatest_common/ya.make4
-rw-r--r--library/python/testing/yatest_common/yatest/__init__.py2
-rw-r--r--library/python/testing/yatest_common/yatest/common/__init__.py6
-rw-r--r--library/python/testing/yatest_common/yatest/common/benchmark.py4
-rw-r--r--library/python/testing/yatest_common/yatest/common/canonical.py6
-rw-r--r--library/python/testing/yatest_common/yatest/common/errors.py4
-rw-r--r--library/python/testing/yatest_common/yatest/common/legacy.py2
-rw-r--r--library/python/testing/yatest_common/yatest/common/process.py46
-rw-r--r--library/python/testing/yatest_common/yatest/common/runtime.py70
-rw-r--r--library/python/testing/yatest_lib/tools.py32
-rw-r--r--library/python/testing/yatest_lib/ya.make4
-rw-r--r--library/python/testing/yatest_lib/ya.py456
17 files changed, 427 insertions, 427 deletions
diff --git a/library/python/testing/import_test/import_test.py b/library/python/testing/import_test/import_test.py
index 3e3b7234ef..4981be1298 100644
--- a/library/python/testing/import_test/import_test.py
+++ b/library/python/testing/import_test/import_test.py
@@ -1,5 +1,5 @@
-from __future__ import print_function
-
+from __future__ import print_function
+
import os
import re
import sys
@@ -10,7 +10,7 @@ import __res
from __res import importer
-def check_imports(no_check=(), extra=(), skip_func=None, py_main=None):
+def check_imports(no_check=(), extra=(), skip_func=None, py_main=None):
"""
tests all bundled modules are importable
just add
@@ -35,13 +35,13 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None):
import_times = {}
norm = lambda s: s[:-9] if s.endswith('.__init__') else s
-
- modules = sys.extra_modules | set(extra)
- modules = sorted(modules, key=norm)
- if py_main:
- modules = [py_main] + modules
-
- for module in modules:
+
+ modules = sys.extra_modules | set(extra)
+ modules = sorted(modules, key=norm)
+ if py_main:
+ modules = [py_main] + modules
+
+ for module in modules:
if module not in extra and (rx.search(module) or skip_func and skip_func(module)):
print('SKIP', module)
continue
@@ -111,14 +111,14 @@ def main():
else:
django.setup()
- py_main = __res.find('PY_MAIN')
-
- if py_main:
- py_main_module = py_main.split(b':', 1)[0].decode('UTF-8')
- else:
- py_main_module = None
-
+ py_main = __res.find('PY_MAIN')
+
+ if py_main:
+ py_main_module = py_main.split(b':', 1)[0].decode('UTF-8')
+ else:
+ py_main_module = None
+
try:
- check_imports(no_check=skip_names, py_main=py_main_module)
+ check_imports(no_check=skip_names, py_main=py_main_module)
except:
sys.exit(1)
diff --git a/library/python/testing/import_test/ya.make b/library/python/testing/import_test/ya.make
index fae36ffe8f..707f7c6c87 100644
--- a/library/python/testing/import_test/ya.make
+++ b/library/python/testing/import_test/ya.make
@@ -2,9 +2,9 @@ OWNER(
g:yatest
exprmntr
)
-
-PY23_LIBRARY()
-
-PY_SRCS(import_test.py)
-
-END()
+
+PY23_LIBRARY()
+
+PY_SRCS(import_test.py)
+
+END()
diff --git a/library/python/testing/recipe/__init__.py b/library/python/testing/recipe/__init__.py
index 5ef9c5c189..4e9c736dc7 100644
--- a/library/python/testing/recipe/__init__.py
+++ b/library/python/testing/recipe/__init__.py
@@ -1,21 +1,21 @@
from __future__ import print_function
-import os
-import sys
+import os
+import sys
import json
import logging
-import argparse
-
-from yatest_lib.ya import Ya
-
-RECIPE_START_OPTION = "start"
-RECIPE_STOP_OPTION = "stop"
-
-ya = None
-collect_cores = None
-sanitizer_extra_checks = None
-
-
+import argparse
+
+from yatest_lib.ya import Ya
+
+RECIPE_START_OPTION = "start"
+RECIPE_STOP_OPTION = "stop"
+
+ya = None
+collect_cores = None
+sanitizer_extra_checks = None
+
+
def _setup_logging(level=logging.DEBUG):
root_logger = logging.getLogger()
root_logger.setLevel(level)
@@ -29,74 +29,74 @@ def _setup_logging(level=logging.DEBUG):
root_logger.addHandler(stdout_handler)
-def get_options():
- parser = argparse.ArgumentParser()
- parser.add_argument("--show-cwd", action="store_true", dest="show_cwd", default=False, help="show recipe cwd")
+def get_options():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--show-cwd", action="store_true", dest="show_cwd", default=False, help="show recipe cwd")
parser.add_argument("--test-debug", action="store_true", dest="test_debug", default=False, help="test debug mode")
- parser.add_argument("--test-stderr", action="store_true", dest="test_stderr", default=False, help="test stderr")
- parser.add_argument("--pdb", action="store_true", dest="pdb", default=False, help="run pdb on error")
- parser.add_argument("--sanitizer-extra-checks", dest="sanitizer_extra_checks", action="store_true", default=False, help="enables extra checks for tests built with sanitizers")
- parser.add_argument("--collect-cores", dest="collect_cores", action="store_true", default=False, help="allows core dump file recovering during test")
-
- args, opts = parser.parse_known_args()
-
- global ya, sanitizer_extra_checks, collect_cores
+ parser.add_argument("--test-stderr", action="store_true", dest="test_stderr", default=False, help="test stderr")
+ parser.add_argument("--pdb", action="store_true", dest="pdb", default=False, help="run pdb on error")
+ parser.add_argument("--sanitizer-extra-checks", dest="sanitizer_extra_checks", action="store_true", default=False, help="enables extra checks for tests built with sanitizers")
+ parser.add_argument("--collect-cores", dest="collect_cores", action="store_true", default=False, help="allows core dump file recovering during test")
+
+ args, opts = parser.parse_known_args()
+
+ global ya, sanitizer_extra_checks, collect_cores
_setup_logging()
- context = {
- "test_stderr": args.test_stderr,
- }
-
- ya = Ya(context=context)
-
- ya._data_root = "" # XXX remove
-
- sanitizer_extra_checks = args.sanitizer_extra_checks
- if sanitizer_extra_checks:
- for envvar in ['LSAN_OPTIONS', 'ASAN_OPTIONS']:
- if envvar in os.environ:
- os.environ.pop(envvar)
- if envvar + '_ORIGINAL' in os.environ:
- os.environ[envvar] = os.environ[envvar + '_ORIGINAL']
- collect_cores = args.collect_cores
-
- for recipe_option in RECIPE_START_OPTION, RECIPE_STOP_OPTION:
- if recipe_option in opts:
- return args, opts[opts.index(recipe_option):]
-
-
-def set_env(key, value):
- with open(ya.env_file, "a") as f:
- json.dump({key: value}, f)
- f.write("\n")
-
-
-def tty():
- if os.isatty(1):
- return
-
- f = open('/dev/tty', 'w+')
- fd = f.fileno()
- os.dup2(fd, 0)
- os.dup2(fd, 1)
- os.dup2(fd, 2)
-
-
-def declare_recipe(start, stop):
- parsed_args, argv = get_options()
-
- if parsed_args.show_cwd:
+ context = {
+ "test_stderr": args.test_stderr,
+ }
+
+ ya = Ya(context=context)
+
+ ya._data_root = "" # XXX remove
+
+ sanitizer_extra_checks = args.sanitizer_extra_checks
+ if sanitizer_extra_checks:
+ for envvar in ['LSAN_OPTIONS', 'ASAN_OPTIONS']:
+ if envvar in os.environ:
+ os.environ.pop(envvar)
+ if envvar + '_ORIGINAL' in os.environ:
+ os.environ[envvar] = os.environ[envvar + '_ORIGINAL']
+ collect_cores = args.collect_cores
+
+ for recipe_option in RECIPE_START_OPTION, RECIPE_STOP_OPTION:
+ if recipe_option in opts:
+ return args, opts[opts.index(recipe_option):]
+
+
+def set_env(key, value):
+ with open(ya.env_file, "a") as f:
+ json.dump({key: value}, f)
+ f.write("\n")
+
+
+def tty():
+ if os.isatty(1):
+ return
+
+ f = open('/dev/tty', 'w+')
+ fd = f.fileno()
+ os.dup2(fd, 0)
+ os.dup2(fd, 1)
+ os.dup2(fd, 2)
+
+
+def declare_recipe(start, stop):
+ parsed_args, argv = get_options()
+
+ if parsed_args.show_cwd:
print("Recipe \"{} {}\" working dir is {}".format(sys.argv[0], " ".join(argv), os.getcwd()))
-
- try:
- if argv[0] == RECIPE_START_OPTION:
- start(argv[1:])
- elif argv[0] == RECIPE_STOP_OPTION:
- stop(argv[1:])
- except Exception:
- if parsed_args.pdb:
- tty()
+
+ try:
+ if argv[0] == RECIPE_START_OPTION:
+ start(argv[1:])
+ elif argv[0] == RECIPE_STOP_OPTION:
+ stop(argv[1:])
+ except Exception:
+ if parsed_args.pdb:
+ tty()
import ipdb
ipdb.post_mortem()
- else:
- raise
+ else:
+ raise
diff --git a/library/python/testing/recipe/ya.make b/library/python/testing/recipe/ya.make
index dd323aa245..be673f8289 100644
--- a/library/python/testing/recipe/ya.make
+++ b/library/python/testing/recipe/ya.make
@@ -2,18 +2,18 @@ OWNER(
exprmntr
g:yatest
)
-
+
PY23_LIBRARY()
-
+
PY_SRCS(
__init__.py
ports.py
)
-
+
PEERDIR(
contrib/python/ipdb
library/python/testing/yatest_common
- library/python/testing/yatest_lib
+ library/python/testing/yatest_lib
)
-END()
+END()
diff --git a/library/python/testing/ya.make b/library/python/testing/ya.make
index 883bc8d7ab..0a964eb4d1 100644
--- a/library/python/testing/ya.make
+++ b/library/python/testing/ya.make
@@ -12,7 +12,7 @@ RECURSE(
pytest_runner
pytest_runner/example
pytest_runner/test
- recipe
+ recipe
system_info
types_test
yapackage
diff --git a/library/python/testing/yatest_common/ya.make b/library/python/testing/yatest_common/ya.make
index 5662db4c5d..113a05ff37 100644
--- a/library/python/testing/yatest_common/ya.make
+++ b/library/python/testing/yatest_common/ya.make
@@ -1,6 +1,6 @@
OWNER(g:yatest)
-PY23_LIBRARY()
+PY23_LIBRARY()
OWNER(g:yatest)
@@ -27,7 +27,7 @@ PY_SRCS(
PEERDIR(
contrib/python/six
library/python/cores
- library/python/filelock
+ library/python/filelock
library/python/fs
)
diff --git a/library/python/testing/yatest_common/yatest/__init__.py b/library/python/testing/yatest_common/yatest/__init__.py
index b846b3317a..fc2829b095 100644
--- a/library/python/testing/yatest_common/yatest/__init__.py
+++ b/library/python/testing/yatest_common/yatest/__init__.py
@@ -1,3 +1,3 @@
__all__ = ["common"]
-from . import common
+from . import common
diff --git a/library/python/testing/yatest_common/yatest/common/__init__.py b/library/python/testing/yatest_common/yatest/common/__init__.py
index cf57779e27..41661c6fbf 100644
--- a/library/python/testing/yatest_common/yatest/common/__init__.py
+++ b/library/python/testing/yatest_common/yatest/common/__init__.py
@@ -2,7 +2,7 @@ from .benchmark import * # noqa
from .canonical import * # noqa
from .errors import * # noqa
from .misc import * # noqa
-from .path import * # noqa
-from .process import * # noqa
+from .path import * # noqa
+from .process import * # noqa
from .runtime import * # noqa
-from .tags import * # noqa
+from .tags import * # noqa
diff --git a/library/python/testing/yatest_common/yatest/common/benchmark.py b/library/python/testing/yatest_common/yatest/common/benchmark.py
index c3784cbe4c..d664aa389d 100644
--- a/library/python/testing/yatest_common/yatest/common/benchmark.py
+++ b/library/python/testing/yatest_common/yatest/common/benchmark.py
@@ -1,7 +1,7 @@
import json
-from . import process
-from . import runtime
+from . import process
+from . import runtime
def execute_benchmark(path, budget=None, threads=None):
diff --git a/library/python/testing/yatest_common/yatest/common/canonical.py b/library/python/testing/yatest_common/yatest/common/canonical.py
index b6a136d3e9..b684604edd 100644
--- a/library/python/testing/yatest_common/yatest/common/canonical.py
+++ b/library/python/testing/yatest_common/yatest/common/canonical.py
@@ -5,9 +5,9 @@ import tempfile
import six
-from . import process
-from . import runtime
-from . import path
+from . import process
+from . import runtime
+from . import path
yatest_logger = logging.getLogger("ya.test")
diff --git a/library/python/testing/yatest_common/yatest/common/errors.py b/library/python/testing/yatest_common/yatest/common/errors.py
index 8c038fc381..22320b79c7 100644
--- a/library/python/testing/yatest_common/yatest/common/errors.py
+++ b/library/python/testing/yatest_common/yatest/common/errors.py
@@ -5,7 +5,7 @@ import sys
class RestartTestException(Exception):
def __init__(self, *args, **kwargs):
- super(RestartTestException, self).__init__(*args, **kwargs)
+ super(RestartTestException, self).__init__(*args, **kwargs)
sys.stderr.write("##restart-test##\n")
sys.stderr.flush()
os.environ["FORCE_EXIT_TESTSFAILED"] = "1"
@@ -14,7 +14,7 @@ class RestartTestException(Exception):
class InfrastructureException(Exception):
def __init__(self, *args, **kwargs):
- super(InfrastructureException, self).__init__(*args, **kwargs)
+ super(InfrastructureException, self).__init__(*args, **kwargs)
sys.stderr.write("##infrastructure-error##\n")
sys.stderr.flush()
os.environ["FORCE_EXIT_TESTSFAILED"] = "1"
diff --git a/library/python/testing/yatest_common/yatest/common/legacy.py b/library/python/testing/yatest_common/yatest/common/legacy.py
index 459972d253..655aa81b44 100644
--- a/library/python/testing/yatest_common/yatest/common/legacy.py
+++ b/library/python/testing/yatest_common/yatest/common/legacy.py
@@ -1,4 +1,4 @@
-from . import canonical
+from . import canonical
def old_canonical_file(output_file_name, storage_md5):
diff --git a/library/python/testing/yatest_common/yatest/common/process.py b/library/python/testing/yatest_common/yatest/common/process.py
index a8bcc21f51..94dbd074a4 100644
--- a/library/python/testing/yatest_common/yatest/common/process.py
+++ b/library/python/testing/yatest_common/yatest/common/process.py
@@ -19,9 +19,9 @@ try:
except ImportError:
cores = None
-from . import runtime
-from . import path
-from . import environment
+from . import runtime
+from . import path
+from . import environment
MAX_OUT_LEN = 1000 * 1000 # 1 mb
@@ -48,11 +48,11 @@ class ExecutionError(Exception):
def __init__(self, execution_result):
if not isinstance(execution_result.command, six.string_types):
- command = " ".join(str(arg) for arg in execution_result.command)
- else:
- command = execution_result.command
+ command = " ".join(str(arg) for arg in execution_result.command)
+ else:
+ command = execution_result.command
message = "Command '{command}' has failed with code {code}.\nErrors:\n{err}\n".format(
- command=command,
+ command=command,
code=execution_result.exit_code,
err=_format_error(execution_result.std_err))
if cores:
@@ -62,7 +62,7 @@ class ExecutionError(Exception):
message += "Backtrace is not available: module cores isn't available"
super(ExecutionError, self).__init__(message)
- self.execution_result = execution_result
+ self.execution_result = execution_result
class TimeoutError(Exception):
@@ -274,7 +274,7 @@ class _Execution(object):
afile.write(six.ensure_binary(self._backtrace))
# generate pretty html version of backtrace aka Tri Korochki
pbt_filename = bt_filename + ".html"
- backtrace_to_html(bt_filename, pbt_filename)
+ backtrace_to_html(bt_filename, pbt_filename)
if store_cores:
runtime._register_core(os.path.basename(self.command[0]), self.command[0], core_path, bt_filename, pbt_filename)
@@ -288,11 +288,11 @@ class _Execution(object):
try:
if hasattr(os, "wait4"):
try:
- if hasattr(subprocess, "_eintr_retry_call"):
- pid, sts, rusage = subprocess._eintr_retry_call(os.wait4, self._process.pid, 0)
- else:
- # PEP 475
- pid, sts, rusage = os.wait4(self._process.pid, 0)
+ if hasattr(subprocess, "_eintr_retry_call"):
+ pid, sts, rusage = subprocess._eintr_retry_call(os.wait4, self._process.pid, 0)
+ else:
+ # PEP 475
+ pid, sts, rusage = os.wait4(self._process.pid, 0)
finished = time.time()
self._process._handle_exitstatus(sts)
for field in [
@@ -447,7 +447,7 @@ def execute(
"""
if env is None:
env = os.environ.copy()
- else:
+ else:
# Certain environment variables must be present for programs to work properly.
# For more info see DEVTOOLSSUPPORT-4907
mandatory_env_name = 'YA_MANDATORY_ENV_VARS'
@@ -458,10 +458,10 @@ def execute(
else:
mandatory_system_vars = ['TMPDIR']
- for var in mandatory_system_vars:
- if var not in env and var in os.environ:
- env[var] = os.environ[var]
-
+ for var in mandatory_system_vars:
+ if var not in env and var in os.environ:
+ env[var] = os.environ[var]
+
if not wait and timeout is not None:
raise ValueError("Incompatible arguments 'timeout' and wait=False")
@@ -518,7 +518,7 @@ def execute(
else:
yatest_logger.debug("Executing '%s' in '%s'", command, cwd)
# XXX
-
+
started = time.time()
process = subprocess.Popen(
command, shell=shell, universal_newlines=True,
@@ -703,9 +703,9 @@ def check_glibc_version(binary_path):
if not match:
continue
assert distutils.version.LooseVersion(match.group(1)) <= lucid_glibc_version, match.group(0)
-
-
-def backtrace_to_html(bt_filename, output):
+
+
+def backtrace_to_html(bt_filename, output):
try:
from library.python import coredump_filter
with open(output, "wb") as afile:
diff --git a/library/python/testing/yatest_common/yatest/common/runtime.py b/library/python/testing/yatest_common/yatest/common/runtime.py
index e55e193446..37b848cf15 100644
--- a/library/python/testing/yatest_common/yatest/common/runtime.py
+++ b/library/python/testing/yatest_common/yatest/common/runtime.py
@@ -18,12 +18,12 @@ def _get_ya_config():
import pytest
return pytest.config
except (ImportError, AttributeError):
- try:
- import library.python.testing.recipe
- if library.python.testing.recipe.ya:
- return library.python.testing.recipe
- except (ImportError, AttributeError):
- pass
+ try:
+ import library.python.testing.recipe
+ if library.python.testing.recipe.ya:
+ return library.python.testing.recipe
+ except (ImportError, AttributeError):
+ pass
raise NotImplementedError("yatest.common.* is only available from the testing runtime")
@@ -160,11 +160,11 @@ def work_path(path=None):
:param path: path relative to the test suite working dir
:return: absolute path inside the test suite working dir
"""
- return _join_path(
- os.environ.get("TEST_WORK_PATH") or
- _get_ya_plugin_instance().get_context("work_path") or
- os.getcwd(),
- path)
+ return _join_path(
+ os.environ.get("TEST_WORK_PATH") or
+ _get_ya_plugin_instance().get_context("work_path") or
+ os.getcwd(),
+ path)
def python_path():
@@ -304,10 +304,10 @@ class Context(object):
return _get_ya_plugin_instance().get_context("test_stderr")
@property
- def test_debug(self):
- return _get_ya_plugin_instance().get_context("test_debug")
-
- @property
+ def test_debug(self):
+ return _get_ya_plugin_instance().get_context("test_debug")
+
+ @property
def test_traceback(self):
return _get_ya_plugin_instance().get_context("test_traceback")
@@ -315,29 +315,29 @@ class Context(object):
def test_name(self):
return _get_ya_config().current_test_name
- @property
- def sanitize(self):
+ @property
+ def sanitize(self):
"""
Detect if current test run is under sanitizer
:return: one of `None`, 'address', 'memory', 'thread', 'undefined'
"""
- return _get_ya_plugin_instance().get_context("sanitize")
-
- @property
- def flags(self):
- _flags = _get_ya_plugin_instance().get_context("flags")
- if _flags:
- _flags_dict = dict()
- for f in _flags:
- key, value = f.split('=', 1)
- _flags_dict[key] = value
- return _flags_dict
- else:
- return dict()
-
- def get_context_key(self, key):
- return _get_ya_plugin_instance().get_context(key)
-
-
+ return _get_ya_plugin_instance().get_context("sanitize")
+
+ @property
+ def flags(self):
+ _flags = _get_ya_plugin_instance().get_context("flags")
+ if _flags:
+ _flags_dict = dict()
+ for f in _flags:
+ key, value = f.split('=', 1)
+ _flags_dict[key] = value
+ return _flags_dict
+ else:
+ return dict()
+
+ def get_context_key(self, key):
+ return _get_ya_plugin_instance().get_context(key)
+
+
context = Context()
diff --git a/library/python/testing/yatest_lib/tools.py b/library/python/testing/yatest_lib/tools.py
index b72d79c162..985124fbba 100644
--- a/library/python/testing/yatest_lib/tools.py
+++ b/library/python/testing/yatest_lib/tools.py
@@ -1,21 +1,21 @@
import six
-import sys
-
+import sys
+
def to_utf8(value):
"""
Converts value to string encoded into utf-8
:param value:
:return:
"""
- if sys.version_info[0] < 3:
- if not isinstance(value, basestring): # noqa
- value = unicode(value) # noqa
- if type(value) == str:
- value = value.decode("utf-8", errors="ignore")
- return value.encode('utf-8', 'ignore')
- else:
- return str(value)
+ if sys.version_info[0] < 3:
+ if not isinstance(value, basestring): # noqa
+ value = unicode(value) # noqa
+ if type(value) == str:
+ value = value.decode("utf-8", errors="ignore")
+ return value.encode('utf-8', 'ignore')
+ else:
+ return str(value)
def trim_string(s, max_bytes):
@@ -56,9 +56,9 @@ def _trim_unicode_string(s, max_bytes):
result.append(ch)
return ''.join(result)
-
-
-def to_str(s):
- if six.PY2 and isinstance(s, six.text_type):
- return s.encode('utf8')
- return s
+
+
+def to_str(s):
+ if six.PY2 and isinstance(s, six.text_type):
+ return s.encode('utf8')
+ return s
diff --git a/library/python/testing/yatest_lib/ya.make b/library/python/testing/yatest_lib/ya.make
index 342bae82ba..c273e9d143 100644
--- a/library/python/testing/yatest_lib/ya.make
+++ b/library/python/testing/yatest_lib/ya.make
@@ -1,6 +1,6 @@
OWNER(g:yatest)
-PY23_LIBRARY()
+PY23_LIBRARY()
PY_SRCS(
NAMESPACE
@@ -8,7 +8,7 @@ PY_SRCS(
external.py
test_splitter.py
tools.py
- ya.py
+ ya.py
)
PEERDIR(
diff --git a/library/python/testing/yatest_lib/ya.py b/library/python/testing/yatest_lib/ya.py
index c13b58a19f..df763489ca 100644
--- a/library/python/testing/yatest_lib/ya.py
+++ b/library/python/testing/yatest_lib/ya.py
@@ -1,223 +1,223 @@
-import os
-import sys
-import logging
-import json
-
-from .tools import to_str
-from .external import ExternalDataInfo
-
-
-TESTING_OUT_DIR_NAME = "testing_out_stuff" # XXX import from test.const
-
-yatest_logger = logging.getLogger("ya.test")
-
-
-class RunMode(object):
- Run = "run"
- List = "list"
-
-
-class TestMisconfigurationException(Exception):
- pass
-
-
-class Ya(object):
- """
- Adds integration with ya, helps in finding dependencies
- """
-
- def __init__(
- self,
- mode=None,
- source_root=None,
- build_root=None,
- dep_roots=None,
- output_dir=None,
- test_params=None,
- context=None,
- python_path=None,
- valgrind_path=None,
- gdb_path=None,
- data_root=None,
- ):
- context_file_path = os.environ.get("YA_TEST_CONTEXT_FILE", None)
- if context_file_path:
- with open(context_file_path, 'r') as afile:
- test_context = json.load(afile)
- context_runtime = test_context["runtime"]
- context_internal = test_context.get("internal", {})
- context_build = test_context.get("build", {})
- else:
- context_runtime = {}
- context_internal = {}
- context_build = {}
- self._mode = mode
- self._build_root = to_str(context_runtime.get("build_root", "")) or build_root
- self._source_root = to_str(context_runtime.get("source_root", "")) or source_root or self._detect_source_root()
- self._output_dir = to_str(context_runtime.get("output_path", "")) or output_dir or self._detect_output_root()
- if not self._output_dir:
- raise Exception("Run ya make -t before running test binary")
- if not self._source_root:
- logging.warning("Source root was not set neither determined, use --source-root to set it explicitly")
- if not self._build_root:
- if self._source_root:
- self._build_root = self._source_root
- else:
- logging.warning("Build root was not set neither determined, use --build-root to set it explicitly")
-
- if data_root:
- self._data_root = data_root
- elif self._source_root:
- self._data_root = os.path.abspath(os.path.join(self._source_root, "..", "arcadia_tests_data"))
-
- self._dep_roots = dep_roots
-
- self._python_path = to_str(context_runtime.get("python_bin", "")) or python_path
- self._valgrind_path = valgrind_path
- self._gdb_path = to_str(context_runtime.get("gdb_bin", "")) or gdb_path
- self._test_params = {}
- self._context = {}
- self._test_item_node_id = None
-
- ram_drive_path = to_str(context_runtime.get("ram_drive_path", ""))
- if ram_drive_path:
- self._test_params["ram_drive_path"] = ram_drive_path
- if test_params:
- self._test_params.update(dict(x.split('=', 1) for x in test_params))
- self._test_params.update(context_runtime.get("test_params", {}))
-
- self._context["project_path"] = context_runtime.get("project_path")
- self._context["modulo"] = context_runtime.get("split_count", 1)
- self._context["modulo_index"] = context_runtime.get("split_index", 0)
- self._context["work_path"] = context_runtime.get("work_path")
-
- self._context["sanitize"] = context_build.get("sanitizer")
- self._context["ya_trace_path"] = context_internal.get("trace_file")
-
- self._env_file = context_internal.get("env_file")
-
- if context:
- self._context.update(context)
-
- @property
- def source_root(self):
- return self._source_root
-
- @property
- def data_root(self):
- return self._data_root
-
- @property
- def build_root(self):
- return self._build_root
-
- @property
- def dep_roots(self):
- return self._dep_roots
-
- @property
- def output_dir(self):
- return self._output_dir
-
- @property
- def python_path(self):
- return self._python_path or sys.executable
-
- @property
- def valgrind_path(self):
- if not self._valgrind_path:
- raise ValueError("path to valgrind was not pass correctly, use --valgrind-path to fix it")
- return self._valgrind_path
-
- @property
- def gdb_path(self):
- return self._gdb_path
-
- @property
- def env_file(self):
- return self._env_file
-
- def get_binary(self, *path):
- assert self._build_root, "Build root was not set neither determined, use --build-root to set it explicitly"
- path = list(path)
- if os.name == "nt":
- if not path[-1].endswith(".exe"):
- path[-1] += ".exe"
-
- target_dirs = [self.build_root]
- # Search for binaries within PATH dirs to be able to get path to the binaries specified by basename for exectests
- if 'PATH' in os.environ:
- target_dirs += os.environ['PATH'].split(':')
-
- for target_dir in target_dirs:
- binary_path = os.path.join(target_dir, *path)
- if os.path.exists(binary_path):
- yatest_logger.debug("Binary was found by %s", binary_path)
- return binary_path
-
- error_message = "Cannot find binary '{binary}': make sure it was added in the DEPENDS section".format(binary=path)
- yatest_logger.debug(error_message)
- if self._mode == RunMode.Run:
- raise TestMisconfigurationException(error_message)
-
- def file(self, path, diff_tool=None, local=False, diff_file_name=None, diff_tool_timeout=None):
- return ExternalDataInfo.serialize_file(path, diff_tool=diff_tool, local=local, diff_file_name=diff_file_name, diff_tool_timeout=diff_tool_timeout)
-
- def get_param(self, key, default=None):
- return self._test_params.get(key, default)
-
- def get_param_dict_copy(self):
- return dict(self._test_params)
-
- def get_context(self, key):
- return self._context.get(key)
-
- def _detect_source_root(self):
- root = None
- try:
- import library.python.find_root
- # try to determine source root from cwd
- cwd = os.getcwd()
- root = library.python.find_root.detect_root(cwd)
-
- if not root:
- # try to determine root pretending we are in the test work dir made from --keep-temps run
- env_subdir = os.path.join("environment", "arcadia")
- root = library.python.find_root.detect_root(cwd, detector=lambda p: os.path.exists(os.path.join(p, env_subdir)))
- except ImportError:
- logging.warning("Unable to import library.python.find_root")
-
- return root
-
- def _detect_output_root(self):
-
- # if run from kept test working dir
- if os.path.exists(TESTING_OUT_DIR_NAME):
- return TESTING_OUT_DIR_NAME
-
- # if run from source dir
- if sys.version_info.major == 3:
- test_results_dir = "py3test"
- else:
- test_results_dir = "pytest"
-
- test_results_output_path = os.path.join("test-results", test_results_dir, TESTING_OUT_DIR_NAME)
- if os.path.exists(test_results_output_path):
- return test_results_output_path
-
- if os.path.exists(os.path.dirname(test_results_output_path)):
- os.mkdir(test_results_output_path)
- return test_results_output_path
-
- return None
-
- def set_test_item_node_id(self, node_id):
- self._test_item_node_id = node_id
-
- def get_test_item_node_id(self):
- assert self._test_item_node_id
- return self._test_item_node_id
-
+import os
+import sys
+import logging
+import json
+
+from .tools import to_str
+from .external import ExternalDataInfo
+
+
+TESTING_OUT_DIR_NAME = "testing_out_stuff" # XXX import from test.const
+
+yatest_logger = logging.getLogger("ya.test")
+
+
+class RunMode(object):
+ Run = "run"
+ List = "list"
+
+
+class TestMisconfigurationException(Exception):
+ pass
+
+
+class Ya(object):
+ """
+ Adds integration with ya, helps in finding dependencies
+ """
+
+ def __init__(
+ self,
+ mode=None,
+ source_root=None,
+ build_root=None,
+ dep_roots=None,
+ output_dir=None,
+ test_params=None,
+ context=None,
+ python_path=None,
+ valgrind_path=None,
+ gdb_path=None,
+ data_root=None,
+ ):
+ context_file_path = os.environ.get("YA_TEST_CONTEXT_FILE", None)
+ if context_file_path:
+ with open(context_file_path, 'r') as afile:
+ test_context = json.load(afile)
+ context_runtime = test_context["runtime"]
+ context_internal = test_context.get("internal", {})
+ context_build = test_context.get("build", {})
+ else:
+ context_runtime = {}
+ context_internal = {}
+ context_build = {}
+ self._mode = mode
+ self._build_root = to_str(context_runtime.get("build_root", "")) or build_root
+ self._source_root = to_str(context_runtime.get("source_root", "")) or source_root or self._detect_source_root()
+ self._output_dir = to_str(context_runtime.get("output_path", "")) or output_dir or self._detect_output_root()
+ if not self._output_dir:
+ raise Exception("Run ya make -t before running test binary")
+ if not self._source_root:
+ logging.warning("Source root was not set neither determined, use --source-root to set it explicitly")
+ if not self._build_root:
+ if self._source_root:
+ self._build_root = self._source_root
+ else:
+ logging.warning("Build root was not set neither determined, use --build-root to set it explicitly")
+
+ if data_root:
+ self._data_root = data_root
+ elif self._source_root:
+ self._data_root = os.path.abspath(os.path.join(self._source_root, "..", "arcadia_tests_data"))
+
+ self._dep_roots = dep_roots
+
+ self._python_path = to_str(context_runtime.get("python_bin", "")) or python_path
+ self._valgrind_path = valgrind_path
+ self._gdb_path = to_str(context_runtime.get("gdb_bin", "")) or gdb_path
+ self._test_params = {}
+ self._context = {}
+ self._test_item_node_id = None
+
+ ram_drive_path = to_str(context_runtime.get("ram_drive_path", ""))
+ if ram_drive_path:
+ self._test_params["ram_drive_path"] = ram_drive_path
+ if test_params:
+ self._test_params.update(dict(x.split('=', 1) for x in test_params))
+ self._test_params.update(context_runtime.get("test_params", {}))
+
+ self._context["project_path"] = context_runtime.get("project_path")
+ self._context["modulo"] = context_runtime.get("split_count", 1)
+ self._context["modulo_index"] = context_runtime.get("split_index", 0)
+ self._context["work_path"] = context_runtime.get("work_path")
+
+ self._context["sanitize"] = context_build.get("sanitizer")
+ self._context["ya_trace_path"] = context_internal.get("trace_file")
+
+ self._env_file = context_internal.get("env_file")
+
+ if context:
+ self._context.update(context)
+
+ @property
+ def source_root(self):
+ return self._source_root
+
+ @property
+ def data_root(self):
+ return self._data_root
+
+ @property
+ def build_root(self):
+ return self._build_root
+
+ @property
+ def dep_roots(self):
+ return self._dep_roots
+
+ @property
+ def output_dir(self):
+ return self._output_dir
+
+ @property
+ def python_path(self):
+ return self._python_path or sys.executable
+
+ @property
+ def valgrind_path(self):
+ if not self._valgrind_path:
+ raise ValueError("path to valgrind was not pass correctly, use --valgrind-path to fix it")
+ return self._valgrind_path
+
+ @property
+ def gdb_path(self):
+ return self._gdb_path
+
+ @property
+ def env_file(self):
+ return self._env_file
+
+ def get_binary(self, *path):
+ assert self._build_root, "Build root was not set neither determined, use --build-root to set it explicitly"
+ path = list(path)
+ if os.name == "nt":
+ if not path[-1].endswith(".exe"):
+ path[-1] += ".exe"
+
+ target_dirs = [self.build_root]
+ # Search for binaries within PATH dirs to be able to get path to the binaries specified by basename for exectests
+ if 'PATH' in os.environ:
+ target_dirs += os.environ['PATH'].split(':')
+
+ for target_dir in target_dirs:
+ binary_path = os.path.join(target_dir, *path)
+ if os.path.exists(binary_path):
+ yatest_logger.debug("Binary was found by %s", binary_path)
+ return binary_path
+
+ error_message = "Cannot find binary '{binary}': make sure it was added in the DEPENDS section".format(binary=path)
+ yatest_logger.debug(error_message)
+ if self._mode == RunMode.Run:
+ raise TestMisconfigurationException(error_message)
+
+ def file(self, path, diff_tool=None, local=False, diff_file_name=None, diff_tool_timeout=None):
+ return ExternalDataInfo.serialize_file(path, diff_tool=diff_tool, local=local, diff_file_name=diff_file_name, diff_tool_timeout=diff_tool_timeout)
+
+ def get_param(self, key, default=None):
+ return self._test_params.get(key, default)
+
+ def get_param_dict_copy(self):
+ return dict(self._test_params)
+
+ def get_context(self, key):
+ return self._context.get(key)
+
+ def _detect_source_root(self):
+ root = None
+ try:
+ import library.python.find_root
+ # try to determine source root from cwd
+ cwd = os.getcwd()
+ root = library.python.find_root.detect_root(cwd)
+
+ if not root:
+ # try to determine root pretending we are in the test work dir made from --keep-temps run
+ env_subdir = os.path.join("environment", "arcadia")
+ root = library.python.find_root.detect_root(cwd, detector=lambda p: os.path.exists(os.path.join(p, env_subdir)))
+ except ImportError:
+ logging.warning("Unable to import library.python.find_root")
+
+ return root
+
+ def _detect_output_root(self):
+
+ # if run from kept test working dir
+ if os.path.exists(TESTING_OUT_DIR_NAME):
+ return TESTING_OUT_DIR_NAME
+
+ # if run from source dir
+ if sys.version_info.major == 3:
+ test_results_dir = "py3test"
+ else:
+ test_results_dir = "pytest"
+
+ test_results_output_path = os.path.join("test-results", test_results_dir, TESTING_OUT_DIR_NAME)
+ if os.path.exists(test_results_output_path):
+ return test_results_output_path
+
+ if os.path.exists(os.path.dirname(test_results_output_path)):
+ os.mkdir(test_results_output_path)
+ return test_results_output_path
+
+ return None
+
+ def set_test_item_node_id(self, node_id):
+ self._test_item_node_id = node_id
+
+ def get_test_item_node_id(self):
+ assert self._test_item_node_id
+ return self._test_item_node_id
+
@property
def pytest_config(self):
if not hasattr(self, "_pytest_config"):
@@ -225,15 +225,15 @@ class Ya(object):
self._pytest_config = ya_plugin.pytest_config
return self._pytest_config
- def set_metric_value(self, name, val):
- node_id = self.get_test_item_node_id()
+ def set_metric_value(self, name, val):
+ node_id = self.get_test_item_node_id()
if node_id not in self.pytest_config.test_metrics:
self.pytest_config.test_metrics[node_id] = {}
-
+
self.pytest_config.test_metrics[node_id][name] = val
-
- def get_metric_value(self, name, default=None):
+
+ def get_metric_value(self, name, default=None):
res = self.pytest_config.test_metrics.get(self.get_test_item_node_id(), {}).get(name)
- if res is None:
- return default
- return res
+ if res is None:
+ return default
+ return res