diff options
author | exprmntr <exprmntr@yandex-team.ru> | 2022-02-10 16:46:50 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:50 +0300 |
commit | a6396ea4e82c2605dcf9a11ebc4c289d0b1c734c (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library | |
parent | 078ddb2fb76387cae14e8c3ceb5a896009a5a539 (diff) | |
download | ydb-a6396ea4e82c2605dcf9a11ebc4c289d0b1c734c.tar.gz |
Restoring authorship annotation for exprmntr <exprmntr@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
47 files changed, 699 insertions, 699 deletions
diff --git a/library/cpp/codecs/static/tools/tests/ya.make b/library/cpp/codecs/static/tools/tests/ya.make index d770b911c3..c5324eaf53 100644 --- a/library/cpp/codecs/static/tools/tests/ya.make +++ b/library/cpp/codecs/static/tools/tests/ya.make @@ -16,5 +16,5 @@ DEPENDS( ) - + END() diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make index 6a9dacbcbe..5d01ffaad8 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make @@ -6,6 +6,6 @@ SRCS( tvm_client_ut.cpp ) -ENV(YA_TEST_SHORTEN_WINE_PATH=1) - +ENV(YA_TEST_SHORTEN_WINE_PATH=1) + END() diff --git a/library/python/filelock/__init__.py b/library/python/filelock/__init__.py index b68c1d7426..f81ff67f37 100644 --- a/library/python/filelock/__init__.py +++ b/library/python/filelock/__init__.py @@ -3,19 +3,19 @@ import logging import os import sys -import library.python.windows +import library.python.windows logger = logging.getLogger(__name__) -def set_close_on_exec(stream): - if library.python.windows.on_win(): - library.python.windows.set_handle_information(stream, inherit=False) - else: - import fcntl - fcntl.fcntl(stream, fcntl.F_SETFD, fcntl.FD_CLOEXEC) - - +def set_close_on_exec(stream): + if library.python.windows.on_win(): + library.python.windows.set_handle_information(stream, inherit=False) + else: + import fcntl + fcntl.fcntl(stream, fcntl.F_SETFD, fcntl.FD_CLOEXEC) + + class AbstractFileLock(object): def __init__(self, path): @@ -83,12 +83,12 @@ class _WinFileLock(AbstractFileLock): def acquire(self, blocking=True): self._lock = open(self.path) - set_close_on_exec(self._lock) + set_close_on_exec(self._lock) import time locked = False while not locked: - locked = library.python.windows.lock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) + locked = library.python.windows.lock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) if locked: return True if blocking: @@ -98,7 +98,7 @@ class _WinFileLock(AbstractFileLock): def release(self): if self._lock: - library.python.windows.unlock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) + library.python.windows.unlock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) self._lock.close() self._lock = None diff --git a/library/python/filelock/ut/lib/test_filelock.py b/library/python/filelock/ut/lib/test_filelock.py index b80e3db8c2..1b11d89123 100644 --- a/library/python/filelock/ut/lib/test_filelock.py +++ b/library/python/filelock/ut/lib/test_filelock.py @@ -2,59 +2,59 @@ import os import time import logging import multiprocessing -import tempfile +import tempfile import threading -import library.python.filelock +import library.python.filelock def _acquire_lock(lock_path, out_file_path): - with library.python.filelock.FileLock(lock_path): + with library.python.filelock.FileLock(lock_path): with open(out_file_path, "a") as out: out.write("{}:{}\n".format(os.getpid(), time.time())) time.sleep(2) def test_filelock(): - temp_dir = tempfile.mkdtemp() - lock_path = os.path.join(temp_dir, "file.lock") - out_file_path = os.path.join(temp_dir, "out.txt") - - process_count = 5 - processes = [] - for i in range(process_count): - process = multiprocessing.Process(target=_acquire_lock, args=(lock_path, out_file_path)) - process.start() - processes.append(process) - - for process in processes: - process.join() - - pids = [] - times = [] - with open(out_file_path) as out: - content = out.read() - logging.info("Times:\n%s", content) - for line in content.strip().split("\n"): - pid, time_val = line.split(":") - pids.append(pid) - times.append(float(time_val)) - - assert len(set(pids)) == process_count - time1 = times.pop() - while times: - time2 = times.pop() - assert int(time1) - int(time2) >= 2 - time1 = time2 + temp_dir = tempfile.mkdtemp() + lock_path = os.path.join(temp_dir, "file.lock") + out_file_path = os.path.join(temp_dir, "out.txt") + + process_count = 5 + processes = [] + for i in range(process_count): + process = multiprocessing.Process(target=_acquire_lock, args=(lock_path, out_file_path)) + process.start() + processes.append(process) + + for process in processes: + process.join() + + pids = [] + times = [] + with open(out_file_path) as out: + content = out.read() + logging.info("Times:\n%s", content) + for line in content.strip().split("\n"): + pid, time_val = line.split(":") + pids.append(pid) + times.append(float(time_val)) + + assert len(set(pids)) == process_count + time1 = times.pop() + while times: + time2 = times.pop() + assert int(time1) - int(time2) >= 2 + time1 = time2 def test_filelock_init_acquired(): - temp_dir = tempfile.mkdtemp() - lock_path = os.path.join(temp_dir, "file.lock") + temp_dir = tempfile.mkdtemp() + lock_path = os.path.join(temp_dir, "file.lock") - with library.python.filelock.FileLock(lock_path): - sublock = library.python.filelock.FileLock(lock_path) - del sublock + with library.python.filelock.FileLock(lock_path): + sublock = library.python.filelock.FileLock(lock_path) + del sublock def test_concurrent_lock(): diff --git a/library/python/filelock/ut/lib/ya.make b/library/python/filelock/ut/lib/ya.make index 3faf072d91..f3f9da5a67 100644 --- a/library/python/filelock/ut/lib/ya.make +++ b/library/python/filelock/ut/lib/ya.make @@ -1,11 +1,11 @@ -OWNER(g:yatool) - +OWNER(g:yatool) + PY23_LIBRARY() - + TEST_SRCS(test_filelock.py) - -PEERDIR( - library/python/filelock -) - -END() + +PEERDIR( + library/python/filelock +) + +END() diff --git a/library/python/filelock/ut/py2/ya.make b/library/python/filelock/ut/py2/ya.make index f0e05f7d21..30b54e0232 100644 --- a/library/python/filelock/ut/py2/ya.make +++ b/library/python/filelock/ut/py2/ya.make @@ -1,9 +1,9 @@ -OWNER(g:yatool) - +OWNER(g:yatool) + PY2TEST() - -PEERDIR( + +PEERDIR( library/python/filelock/ut/lib -) - -END() +) + +END() diff --git a/library/python/filelock/ya.make b/library/python/filelock/ya.make index 87fe650ce0..958cc1866f 100644 --- a/library/python/filelock/ya.make +++ b/library/python/filelock/ya.make @@ -1,11 +1,11 @@ -OWNER(g:yatool) - -PY23_LIBRARY() - -PY_SRCS(__init__.py) - +OWNER(g:yatool) + +PY23_LIBRARY() + +PY_SRCS(__init__.py) + PEERDIR( library/python/windows ) - -END() + +END() diff --git a/library/python/find_root/__init__.py b/library/python/find_root/__init__.py index d77c54dd88..6da604d62e 100644 --- a/library/python/find_root/__init__.py +++ b/library/python/find_root/__init__.py @@ -2,7 +2,7 @@ import os def is_root(path): - return os.path.exists(os.path.join(path, ".arcadia.root")) or os.path.exists(os.path.join(path, 'devtools', 'ya', 'ya.conf.json')) + return os.path.exists(os.path.join(path, ".arcadia.root")) or os.path.exists(os.path.join(path, 'devtools', 'ya', 'ya.conf.json')) def detect_root(path, detector=is_root): diff --git a/library/python/find_root/ya.make b/library/python/find_root/ya.make index 60876210e6..beaa8e3c52 100644 --- a/library/python/find_root/ya.make +++ b/library/python/find_root/ya.make @@ -1,4 +1,4 @@ -PY23_LIBRARY() +PY23_LIBRARY() OWNER(g:yatool) diff --git a/library/python/fs/__init__.py b/library/python/fs/__init__.py index 15ee485202..b1b7cde079 100644 --- a/library/python/fs/__init__.py +++ b/library/python/fs/__init__.py @@ -10,9 +10,9 @@ import six import stat import sys -import library.python.func -import library.python.strings -import library.python.windows +import library.python.func +import library.python.strings +import library.python.windows logger = logging.getLogger(__name__) @@ -24,7 +24,7 @@ except NameError: _diehard_win_tries = 10 -errorfix_win = library.python.windows.errorfix +errorfix_win = library.python.windows.errorfix class CustomFsError(OSError): @@ -69,7 +69,7 @@ def create_dirs(path): # if src is file and dst is dir - throws OSError (errno EISDIR) # On Windows, if dst exists - throws OSError (errno EEXIST) @errorfix_win -@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) +@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) def move(src, dst): os.rename(src, dst) @@ -87,10 +87,10 @@ def move(src, dst): # if dst is file - replaces it # if dst is dir - throws OSError (errno EACCES) @errorfix_win -@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) +@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) def replace_file(src, dst): - if library.python.windows.on_win(): - library.python.windows.replace_file(src, dst) + if library.python.windows.on_win(): + library.python.windows.replace_file(src, dst) else: os.rename(src, dst) @@ -114,7 +114,7 @@ def replace(src, dst): # Atomic file remove # Throws OSError @errorfix_win -@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) +@library.python.windows.diehard(library.python.windows.RETRIABLE_FILE_ERRORS, tries=_diehard_win_tries) def remove_file(path): os.remove(path) @@ -122,7 +122,7 @@ def remove_file(path): # Atomic empty directory remove # Throws OSError @errorfix_win -@library.python.windows.diehard(library.python.windows.RETRIABLE_DIR_ERRORS, tries=_diehard_win_tries) +@library.python.windows.diehard(library.python.windows.RETRIABLE_DIR_ERRORS, tries=_diehard_win_tries) def remove_dir(path): os.rmdir(path) @@ -136,10 +136,10 @@ def fix_path_encoding(path): # Throws OSError, AssertionError @errorfix_win def remove_tree(path): - @library.python.windows.diehard(library.python.windows.RETRIABLE_DIR_ERRORS, tries=_diehard_win_tries) + @library.python.windows.diehard(library.python.windows.RETRIABLE_DIR_ERRORS, tries=_diehard_win_tries) def rmtree(path): - if library.python.windows.on_win(): - library.python.windows.rmtree(path) + if library.python.windows.on_win(): + library.python.windows.rmtree(path) else: shutil.rmtree(fix_path_encoding(path)) @@ -190,8 +190,8 @@ def ensure_removed(path): # If dst exists - throws OSError (errno EEXIST) @errorfix_win def hardlink(src, lnk): - if library.python.windows.on_win(): - library.python.windows.hardlink(src, lnk) + if library.python.windows.on_win(): + library.python.windows.hardlink(src, lnk) else: os.link(src, lnk) @@ -228,8 +228,8 @@ def hardlink_or_copy(src, lnk): # If dst exists - throws OSError (errno EEXIST) @errorfix_win def symlink(src, lnk): - if library.python.windows.on_win(): - library.python.windows.run_disabled(src, lnk) + if library.python.windows.on_win(): + library.python.windows.run_disabled(src, lnk) else: os.symlink(src, lnk) @@ -306,7 +306,7 @@ def read_file_unicode(path, binary=True, enc='utf-8'): with open(path, 'r', encoding=enc) as f: return f.read() # codecs.open is always binary - with codecs.open(path, 'r', encoding=enc, errors=library.python.strings.ENCODING_ERRORS_POLICY) as f: + with codecs.open(path, 'r', encoding=enc, errors=library.python.strings.ENCODING_ERRORS_POLICY) as f: return f.read() diff --git a/library/python/fs/test/test_fs.py b/library/python/fs/test/test_fs.py index 38e27e4fc8..9e2c70c069 100644 --- a/library/python/fs/test/test_fs.py +++ b/library/python/fs/test/test_fs.py @@ -9,7 +9,7 @@ import six import library.python.fs import library.python.strings import library.python.tmp -import library.python.windows +import library.python.windows import yatest.common @@ -62,7 +62,7 @@ def trees_equal(dir1, dir2): def inodes_unsupported(): - return library.python.windows.on_win() + return library.python.windows.on_win() def inodes_equal(path1, path2): @@ -70,11 +70,11 @@ def inodes_equal(path1, path2): def gen_error_access_denied(): - if library.python.windows.on_win(): + if library.python.windows.on_win(): err = WindowsError() err.errno = errno.EACCES err.strerror = '' - err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] + err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] else: err = OSError() err.errno = errno.EACCES @@ -166,7 +166,7 @@ def test_move_file_no_src(path): def test_move_file_exists(path): mkfile(path('src'), 'SRC') mkfile(path('dst'), 'DST') - if library.python.windows.on_win(): + if library.python.windows.on_win(): # move is platform-dependent, use replace_file for dst replacement on all platforms with pytest.raises(OSError) as errinfo: library.python.fs.move(path('src'), path('dst')) @@ -222,7 +222,7 @@ def test_move_dir_exists_empty(path): os.mkdir(path('src')) mkfile(path('src/src_file')) os.mkdir(path('dst')) - if library.python.windows.on_win(): + if library.python.windows.on_win(): # move is platform-dependent, use non-atomic replace for directory replacement with pytest.raises(OSError) as errinfo: library.python.fs.move(path('src'), path('dst')) @@ -553,7 +553,7 @@ def test_hardlink_dir(path): assert not os.path.isdir(path('dst')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_file(path): mkfile(path('src'), 'SRC') @@ -564,7 +564,7 @@ def test_symlink_file(path): assert file_data(path('dst')) == 'SRC' -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_file_no_src(path): library.python.fs.symlink(path('src'), path('dst')) @@ -573,7 +573,7 @@ def test_symlink_file_no_src(path): assert os.path.islink(path('dst')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_file_exists(path): mkfile(path('src'), 'SRC') @@ -587,7 +587,7 @@ def test_symlink_file_exists(path): assert file_data(path('dst')) == 'DST' -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_file_exists_dir(path): mkfile(path('src'), 'SRC') @@ -601,7 +601,7 @@ def test_symlink_file_exists_dir(path): assert not os.path.isfile(path('dst/src')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_dir(path): os.mkdir(path('src')) @@ -613,7 +613,7 @@ def test_symlink_dir(path): assert os.path.isfile(path('dst/src_file')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_dir_no_src(path): library.python.fs.symlink(path('src'), path('dst')) @@ -622,7 +622,7 @@ def test_symlink_dir_no_src(path): assert os.path.islink(path('dst')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_dir_exists(path): os.mkdir(path('src')) @@ -637,7 +637,7 @@ def test_symlink_dir_exists(path): assert not os.path.isfile(path('dst/src_file')) -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_symlink_dir_exists_file(path): os.mkdir(path('src')) @@ -908,7 +908,7 @@ def test_write_file_multiline(path): library.python.fs.write_file(path('src'), 'SRC line 1\nSRC line 2\n') assert file_data(path('src')) == 'SRC line 1\nSRC line 2\n' library.python.fs.write_file(path('src2'), 'SRC line 1\nSRC line 2\n', binary=False) - if library.python.windows.on_win(): + if library.python.windows.on_win(): assert file_data(path('src2')) == 'SRC line 1\r\nSRC line 2\r\n' else: assert file_data(path('src2')) == 'SRC line 1\nSRC line 2\n' @@ -919,7 +919,7 @@ def test_write_file_multiline_crlf(path): library.python.fs.write_file(path('src'), 'SRC line 1\r\nSRC line 2\r\n') assert file_data(path('src')) == 'SRC line 1\r\nSRC line 2\r\n' library.python.fs.write_file(path('src2'), 'SRC line 1\r\nSRC line 2\r\n', binary=False) - if library.python.windows.on_win(): + if library.python.windows.on_win(): assert file_data(path('src2')) == 'SRC line 1\r\r\nSRC line 2\r\r\n' else: assert file_data(path('src2')) == 'SRC line 1\r\nSRC line 2\r\n' @@ -947,7 +947,7 @@ def test_get_tree_size(path): assert library.python.fs.get_tree_size(path(''), recursive=True) == 3 -@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') +@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows') @in_env def test_get_tree_size_dangling_symlink(path): os.makedirs(path('deeper')) @@ -959,7 +959,7 @@ def test_get_tree_size_dangling_symlink(path): assert library.python.fs.get_tree_size(path(''), recursive=True) == 1 -@pytest.mark.skipif(not library.python.windows.on_win(), reason='Test hardlinks on windows') +@pytest.mark.skipif(not library.python.windows.on_win(), reason='Test hardlinks on windows') def test_hardlink_or_copy(): max_allowed_hard_links = 1023 diff --git a/library/python/func/ut/test_func.py b/library/python/func/ut/test_func.py index d2b680dd53..3c4fad1a07 100644 --- a/library/python/func/ut/test_func.py +++ b/library/python/func/ut/test_func.py @@ -1,7 +1,7 @@ import pytest import threading -import library.python.func as func +import library.python.func as func def test_map0(): diff --git a/library/python/func/ya.make b/library/python/func/ya.make index 2c4691ee5a..9d414a976e 100644 --- a/library/python/func/ya.make +++ b/library/python/func/ya.make @@ -1,10 +1,10 @@ -OWNER(g:yatool) - -PY23_LIBRARY() - -PY_SRCS(__init__.py) - -END() +OWNER(g:yatool) + +PY23_LIBRARY() + +PY_SRCS(__init__.py) + +END() RECURSE_FOR_TESTS( ut diff --git a/library/python/pytest/allure/ya.make b/library/python/pytest/allure/ya.make index bbde4934e3..ab3f449c7f 100644 --- a/library/python/pytest/allure/ya.make +++ b/library/python/pytest/allure/ya.make @@ -1,11 +1,11 @@ PY23_LIBRARY() -OWNER(exprmntr) - +OWNER(exprmntr) + PY_SRCS(conftest.py) PEERDIR( contrib/python/pytest-allure-adaptor -) - -END() +) + +END() diff --git a/library/python/pytest/main.py b/library/python/pytest/main.py index 7f9e4bf05e..6296bd6f0f 100644 --- a/library/python/pytest/main.py +++ b/library/python/pytest/main.py @@ -25,11 +25,11 @@ def main(): if FORCE_EXIT_TESTSFAILED_ENV in os.environ: del os.environ[FORCE_EXIT_TESTSFAILED_ENV] - if "Y_PYTHON_CLEAR_ENTRY_POINT" in os.environ: - if "Y_PYTHON_ENTRY_POINT" in os.environ: - del os.environ["Y_PYTHON_ENTRY_POINT"] - del os.environ["Y_PYTHON_CLEAR_ENTRY_POINT"] - + if "Y_PYTHON_CLEAR_ENTRY_POINT" in os.environ: + if "Y_PYTHON_ENTRY_POINT" in os.environ: + del os.environ["Y_PYTHON_ENTRY_POINT"] + del os.environ["Y_PYTHON_CLEAR_ENTRY_POINT"] + listing_mode = '--collect-only' in sys.argv yatest_runner = os.environ.get('YA_TEST_RUNNER') == '1' diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index 626a90d830..e36f47a78f 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -3,8 +3,8 @@ import sys from six import reraise import py - -import pytest # noqa + +import pytest # noqa import _pytest.python import _pytest.doctest import json diff --git a/library/python/pytest/plugins/conftests.py b/library/python/pytest/plugins/conftests.py index 57b5068778..522041f5a7 100644 --- a/library/python/pytest/plugins/conftests.py +++ b/library/python/pytest/plugins/conftests.py @@ -5,7 +5,7 @@ import inspect from pytest import hookimpl -from .fixtures import metrics, links # noqa +from .fixtures import metrics, links # noqa orig_getfile = inspect.getfile diff --git a/library/python/pytest/plugins/ya.make b/library/python/pytest/plugins/ya.make index 845233a945..c15d6f759d 100644 --- a/library/python/pytest/plugins/ya.make +++ b/library/python/pytest/plugins/ya.make @@ -1,6 +1,6 @@ OWNER(g:yatest) -PY23_LIBRARY() +PY23_LIBRARY() PY_SRCS( ya.py diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py index e5be206542..1bde03042d 100644 --- a/library/python/pytest/plugins/ya.py +++ b/library/python/pytest/plugins/ya.py @@ -52,8 +52,8 @@ import yatest_lib.tools import yatest_lib.external as canon -import yatest_lib.ya - +import yatest_lib.ya + from library.python.pytest import context console_logger = logging.getLogger("console") @@ -150,7 +150,7 @@ def pytest_addoption(parser): parser.addoption("--test-file-filter", action="store", dest="test_file_filter", default=None, help="test file filter") parser.addoption("--test-param", action="append", dest="test_params", default=None, help="test parameters") parser.addoption("--test-log-level", action="store", dest="test_log_level", choices=["critical", "error", "warning", "info", "debug"], default="debug", help="test log level") - parser.addoption("--mode", action="store", choices=[yatest_lib.ya.RunMode.List, yatest_lib.ya.RunMode.Run], dest="mode", default=yatest_lib.ya.RunMode.Run, help="testing mode") + parser.addoption("--mode", action="store", choices=[yatest_lib.ya.RunMode.List, yatest_lib.ya.RunMode.Run], dest="mode", default=yatest_lib.ya.RunMode.Run, help="testing mode") parser.addoption("--test-list-file", action="store", dest="test_list_file") parser.addoption("--modulo", default=1, type=int) parser.addoption("--modulo-index", default=0, type=int) @@ -159,9 +159,9 @@ def pytest_addoption(parser): parser.addoption("--project-path", action="store", default="", help="path to CMakeList where test is declared") parser.addoption("--build-type", action="store", default="", help="build type") parser.addoption("--flags", action="append", dest="flags", default=[], help="build flags (-D)") - parser.addoption("--sanitize", action="store", default="", help="sanitize mode") + parser.addoption("--sanitize", action="store", default="", help="sanitize mode") parser.addoption("--test-stderr", action="store_true", default=False, help="test stderr") - parser.addoption("--test-debug", action="store_true", default=False, help="test debug mode") + parser.addoption("--test-debug", action="store_true", default=False, help="test debug mode") parser.addoption("--root-dir", action="store", default=None) parser.addoption("--ya-trace", action="store", dest="ya_trace_path", default=None, help="path to ya trace report") parser.addoption("--ya-version", action="store", dest="ya_version", default=0, type=int, help="allows to be compatible with ya and the new changes in ya-dev") @@ -197,17 +197,17 @@ def pytest_configure(config): context = { "project_path": config.option.project_path, "test_stderr": config.option.test_stderr, - "test_debug": config.option.test_debug, + "test_debug": config.option.test_debug, "build_type": config.option.build_type, "test_traceback": config.option.tbstyle, - "flags": config.option.flags, - "sanitize": config.option.sanitize, + "flags": config.option.flags, + "sanitize": config.option.sanitize, } - - if config.option.collectonly: - config.option.mode = yatest_lib.ya.RunMode.List - - config.ya = yatest_lib.ya.Ya( + + if config.option.collectonly: + config.option.mode = yatest_lib.ya.RunMode.List + + config.ya = yatest_lib.ya.Ya( config.option.mode, config.option.source_root, config.option.build_root, @@ -491,13 +491,13 @@ def pytest_collection_modifyitems(items, config): items.extend(item) yatest_logger.info("Modulo %s tests are: %s", modulo_index, chunk_items) - if config.option.mode == yatest_lib.ya.RunMode.Run: + if config.option.mode == yatest_lib.ya.RunMode.Run: for item in items: test_item = NotLaunchedTestItem(item.nodeid, config.option.test_suffix) config.ya_trace_reporter.on_start_test_class(test_item) config.ya_trace_reporter.on_finish_test_case(test_item) config.ya_trace_reporter.on_finish_test_class(test_item) - elif config.option.mode == yatest_lib.ya.RunMode.List: + elif config.option.mode == yatest_lib.ya.RunMode.List: tests = [] for item in items: item = CustomTestItem(item.nodeid, pytest_config.option.test_suffix, item.keywords) @@ -695,7 +695,7 @@ class TestItem(object): if isinstance(entry, _pytest.reports.BaseReport): self._error = get_formatted_error(entry) else: - self._error = "[[{}]]{}".format(yatest_lib.tools.to_str(marker), yatest_lib.tools.to_str(entry)) + self._error = "[[{}]]{}".format(yatest_lib.tools.to_str(marker), yatest_lib.tools.to_str(entry)) @property def duration(self): @@ -811,7 +811,7 @@ class TraceReportGenerator(object): def on_finish_test_class(self, test_item): pytest_config.ya.set_test_item_node_id(test_item.nodeid) - self.trace('test-finished', {'class': test_item.class_name.decode('utf-8') if sys.version_info[0] < 3 else test_item.class_name}) + self.trace('test-finished', {'class': test_item.class_name.decode('utf-8') if sys.version_info[0] < 3 else test_item.class_name}) def on_start_test_case(self, test_item): class_name = yatest_lib.tools.to_utf8(test_item.class_name) @@ -888,7 +888,7 @@ class TraceReportGenerator(object): 'name': name } - data = yatest_lib.tools.to_str(json.dumps(event, ensure_ascii=False)) + data = yatest_lib.tools.to_str(json.dumps(event, ensure_ascii=False)) self._file.write(data + '\n') self._file.flush() diff --git a/library/python/pytest/ya.make b/library/python/pytest/ya.make index e68402e7c1..060c92c313 100644 --- a/library/python/pytest/ya.make +++ b/library/python/pytest/ya.make @@ -1,4 +1,4 @@ -PY23_LIBRARY() +PY23_LIBRARY() OWNER( g:yatool diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py index f7b084193d..6b8b896394 100644 --- a/library/python/pytest/yatest_tools.py +++ b/library/python/pytest/yatest_tools.py @@ -257,7 +257,7 @@ def normalize_filename(filename): :param some_string: string to be converted to a valid file name :return: valid file name """ - not_allowed_pattern = r"[\[\]\/:*?\"\'<>|+\0\\\s\x0b\x0c]" + not_allowed_pattern = r"[\[\]\/:*?\"\'<>|+\0\\\s\x0b\x0c]" filename = re.sub(not_allowed_pattern, ".", filename) return re.sub(r"\.{2,}", ".", filename) diff --git a/library/python/strings/strings.py b/library/python/strings/strings.py index 0482c3eb17..5bfddfe78a 100644 --- a/library/python/strings/strings.py +++ b/library/python/strings/strings.py @@ -4,7 +4,7 @@ import six import sys import codecs -import library.python.func +import library.python.func logger = logging.getLogger(__name__) diff --git a/library/python/strings/ut/test_strings.py b/library/python/strings/ut/test_strings.py index 88fd41cd89..dd0c694ee1 100644 --- a/library/python/strings/ut/test_strings.py +++ b/library/python/strings/ut/test_strings.py @@ -3,7 +3,7 @@ import pytest import six -import library.python.strings +import library.python.strings class Convertible(object): @@ -32,8 +32,8 @@ class NonConvertible(ConvertibleToUnicodeOnly, ConvertibleToStrOnly): def test_to_basestring(): - assert library.python.strings.to_basestring('str') == 'str' - assert library.python.strings.to_basestring(u'юникод') == u'юникод' + assert library.python.strings.to_basestring('str') == 'str' + assert library.python.strings.to_basestring(u'юникод') == u'юникод' if six.PY2: # __str__ should return str not bytes in Python3 assert library.python.strings.to_basestring(Convertible()) == Convertible.text assert library.python.strings.to_basestring(ConvertibleToUnicodeOnly()) == Convertible.text @@ -42,10 +42,10 @@ def test_to_basestring(): def test_to_unicode(): - assert library.python.strings.to_unicode(u'юникод') == u'юникод' - assert library.python.strings.to_unicode('str') == u'str' - assert library.python.strings.to_unicode(u'строка'.encode('utf-8')) == u'строка' - assert library.python.strings.to_unicode(u'строка'.encode('cp1251'), 'cp1251') == u'строка' + assert library.python.strings.to_unicode(u'юникод') == u'юникод' + assert library.python.strings.to_unicode('str') == u'str' + assert library.python.strings.to_unicode(u'строка'.encode('utf-8')) == u'строка' + assert library.python.strings.to_unicode(u'строка'.encode('cp1251'), 'cp1251') == u'строка' if six.PY2: # __str__ should return str not bytes in Python3 assert library.python.strings.to_unicode(Convertible()) == Convertible.text assert library.python.strings.to_unicode(ConvertibleToUnicodeOnly()) == Convertible.text @@ -56,15 +56,15 @@ def test_to_unicode(): def test_to_unicode_errors_replace(): - assert library.python.strings.to_unicode(u'abcабв'.encode('utf-8'), 'ascii') - assert library.python.strings.to_unicode(u'абв'.encode('utf-8'), 'ascii') + assert library.python.strings.to_unicode(u'abcабв'.encode('utf-8'), 'ascii') + assert library.python.strings.to_unicode(u'абв'.encode('utf-8'), 'ascii') def test_to_str(): assert library.python.strings.to_str('str') == 'str' if six.PY2 else b'str' assert library.python.strings.to_str(u'unicode') == 'unicode' if six.PY2 else b'unicode' - assert library.python.strings.to_str(u'юникод') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод', 'cp1251') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод', 'cp1251') == u'юникод'.encode('cp1251') if six.PY2: assert library.python.strings.to_str(Convertible()) == Convertible.text_utf8 with pytest.raises(UnicodeEncodeError): @@ -75,44 +75,44 @@ def test_to_str(): def test_to_str_errors_replace(): - assert library.python.strings.to_str(u'abcабв', 'ascii') - assert library.python.strings.to_str(u'абв', 'ascii') + assert library.python.strings.to_str(u'abcабв', 'ascii') + assert library.python.strings.to_str(u'абв', 'ascii') def test_to_str_transcode(): assert library.python.strings.to_str('str', from_enc='ascii') == 'str' if six.PY2 else b'str' assert library.python.strings.to_str('str', from_enc='utf-8') == 'str' if six.PY2 else b'str' - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), from_enc='utf-8') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='utf-8', from_enc='utf-8') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='cp1251', from_enc='utf-8') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), from_enc='utf-8') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='utf-8', from_enc='utf-8') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='cp1251', from_enc='utf-8') == u'юникод'.encode('cp1251') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), from_enc='cp1251') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='cp1251', from_enc='cp1251') == u'юникод'.encode('cp1251') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='utf-8', from_enc='cp1251') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), from_enc='cp1251') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='cp1251', from_enc='cp1251') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='utf-8', from_enc='cp1251') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), from_enc='koi8-r') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='koi8-r', from_enc='koi8-r') == u'юникод'.encode('koi8-r') - assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='cp1251', from_enc='koi8-r') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), from_enc='koi8-r') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='koi8-r', from_enc='koi8-r') == u'юникод'.encode('koi8-r') + assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='cp1251', from_enc='koi8-r') == u'юникод'.encode('cp1251') def test_to_str_transcode_wrong(): - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), from_enc='cp1251') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), from_enc='utf-8') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), from_enc='cp1251') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), from_enc='utf-8') def test_to_str_transcode_disabled(): # No transcoding enabled, set from_enc to enable - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='utf-8') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='cp1251') == u'юникод'.encode('utf-8') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='utf-8') == u'юникод'.encode('cp1251') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='cp1251') == u'юникод'.encode('cp1251') - assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='koi8-r') == u'юникод'.encode('cp1251') - assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='cp1251') == u'юникод'.encode('koi8-r') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='utf-8') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('utf-8'), to_enc='cp1251') == u'юникод'.encode('utf-8') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='utf-8') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='cp1251') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('cp1251'), to_enc='koi8-r') == u'юникод'.encode('cp1251') + assert library.python.strings.to_str(u'юникод'.encode('koi8-r'), to_enc='cp1251') == u'юникод'.encode('koi8-r') def test_stringize_deep(): - assert library.python.strings.stringize_deep({ + assert library.python.strings.stringize_deep({ 'key 1': 'value 1', u'ключ 2': u'значение 2', 'list': [u'ключ 2', 'key 1', (u'к', 2)] @@ -124,7 +124,7 @@ def test_stringize_deep(): def test_stringize_deep_doesnt_transcode(): - assert library.python.strings.stringize_deep({ + assert library.python.strings.stringize_deep({ u'ключ 1'.encode('utf-8'): u'значение 1'.encode('utf-8'), u'ключ 2'.encode('cp1251'): u'значение 2'.encode('cp1251'), }) == { @@ -134,7 +134,7 @@ def test_stringize_deep_doesnt_transcode(): def test_stringize_deep_nested(): - assert library.python.strings.stringize_deep({ + assert library.python.strings.stringize_deep({ 'key 1': 'value 1', u'ключ 2': { 'subkey 1': 'value 1', @@ -151,8 +151,8 @@ def test_stringize_deep_nested(): def test_stringize_deep_plain(): assert library.python.strings.stringize_deep('str') == 'str' if six.PY2 else b'str' - assert library.python.strings.stringize_deep(u'юникод') == u'юникод'.encode('utf-8') - assert library.python.strings.stringize_deep(u'юникод'.encode('utf-8')) == u'юникод'.encode('utf-8') + assert library.python.strings.stringize_deep(u'юникод') == u'юникод'.encode('utf-8') + assert library.python.strings.stringize_deep(u'юникод'.encode('utf-8')) == u'юникод'.encode('utf-8') def test_stringize_deep_nonstr(): @@ -163,7 +163,7 @@ def test_stringize_deep_nonstr(): def test_unicodize_deep(): - assert library.python.strings.unicodize_deep({ + assert library.python.strings.unicodize_deep({ 'key 1': 'value 1', u'ключ 2': u'значение 2', u'ключ 3'.encode('utf-8'): u'значение 3'.encode('utf-8'), @@ -175,7 +175,7 @@ def test_unicodize_deep(): def test_unicodize_deep_nested(): - assert library.python.strings.unicodize_deep({ + assert library.python.strings.unicodize_deep({ 'key 1': 'value 1', u'ключ 2': { 'subkey 1': 'value 1', @@ -193,9 +193,9 @@ def test_unicodize_deep_nested(): def test_unicodize_deep_plain(): - assert library.python.strings.unicodize_deep('str') == u'str' - assert library.python.strings.unicodize_deep(u'юникод') == u'юникод' - assert library.python.strings.unicodize_deep(u'юникод'.encode('utf-8')) == u'юникод' + assert library.python.strings.unicodize_deep('str') == u'str' + assert library.python.strings.unicodize_deep(u'юникод') == u'юникод' + assert library.python.strings.unicodize_deep(u'юникод'.encode('utf-8')) == u'юникод' def test_unicodize_deep_nonstr(): diff --git a/library/python/strings/ut/ya.make b/library/python/strings/ut/ya.make index 177525a7ab..dfacb226c7 100644 --- a/library/python/strings/ut/ya.make +++ b/library/python/strings/ut/ya.make @@ -1,11 +1,11 @@ -OWNER(g:yatool) - +OWNER(g:yatool) + PY23_TEST() - + TEST_SRCS(test_strings.py) - -PEERDIR( - library/python/strings -) - -END() + +PEERDIR( + library/python/strings +) + +END() diff --git a/library/python/strings/ya.make b/library/python/strings/ya.make index 89d388fd3a..7e0b033717 100644 --- a/library/python/strings/ya.make +++ b/library/python/strings/ya.make @@ -1,16 +1,16 @@ -OWNER(g:yatool) - -PY23_LIBRARY() - +OWNER(g:yatool) + +PY23_LIBRARY() + PY_SRCS( __init__.py CYTHONIZE_PY strings.py ) - + PEERDIR( library/python/func contrib/python/six ) - -END() + +END() diff --git a/library/python/testing/import_test/import_test.py b/library/python/testing/import_test/import_test.py index 4981be1298..3e3b7234ef 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 707f7c6c87..fae36ffe8f 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 4e9c736dc7..5ef9c5c189 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 be673f8289..dd323aa245 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 0a964eb4d1..883bc8d7ab 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 113a05ff37..5662db4c5d 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 fc2829b095..b846b3317a 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 41661c6fbf..cf57779e27 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 d664aa389d..c3784cbe4c 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 b684604edd..b6a136d3e9 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 22320b79c7..8c038fc381 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 655aa81b44..459972d253 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 94dbd074a4..a8bcc21f51 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 37b848cf15..e55e193446 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 985124fbba..b72d79c162 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 c273e9d143..342bae82ba 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 df763489ca..c13b58a19f 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 diff --git a/library/python/windows/__init__.py b/library/python/windows/__init__.py index 0b43073e35..62861b3309 100644 --- a/library/python/windows/__init__.py +++ b/library/python/windows/__init__.py @@ -6,10 +6,10 @@ import sys import shutil import logging -from six import reraise - -import library.python.func -import library.python.strings +from six import reraise + +import library.python.func +import library.python.strings logger = logging.getLogger(__name__) @@ -28,7 +28,7 @@ RETRIABLE_DIR_ERRORS = (ERRORS['ACCESS_DENIED'], ERRORS['DIR_NOT_EMPTY'], ERRORS # Check if on Windows -@library.python.func.lazy +@library.python.func.lazy def on_win(): return os.name == 'nt' @@ -78,7 +78,7 @@ def errorfix(f): except WindowsError: tp, value, tb = sys.exc_info() fix_error(value) - reraise(tp, value, tb) + reraise(tp, value, tb) return f_wrapped @@ -100,7 +100,7 @@ if on_win(): import msvcrt import time - import library.python.strings + import library.python.strings _has_ctypes = True try: @@ -153,7 +153,7 @@ if on_win(): raise ei = sys.exc_info() time.sleep(delay) - reraise(ei[0], ei[1], ei[2]) + reraise(ei[0], ei[1], ei[2]) # Placeholder for disabled functions @win_only @@ -170,7 +170,7 @@ if on_win(): @win_only def unicode_path(path): - return library.python.strings.to_unicode(path, library.python.strings.fs_encoding()) + return library.python.strings.to_unicode(path, library.python.strings.fs_encoding()) @win_only @require_ctypes @@ -189,9 +189,9 @@ if on_win(): @win_only def transcode_error(windows_error, to_enc='utf-8'): - from_enc = 'utf-8' if getattr(windows_error, 'utf8', False) else library.python.strings.guess_default_encoding() + from_enc = 'utf-8' if getattr(windows_error, 'utf8', False) else library.python.strings.guess_default_encoding() if from_enc != to_enc: - windows_error.strerror = library.python.strings.to_str(windows_error.strerror, to_enc=to_enc, from_enc=from_enc) + windows_error.strerror = library.python.strings.to_str(windows_error.strerror, to_enc=to_enc, from_enc=from_enc) setattr(windows_error, 'utf8', to_enc == 'utf-8') class Transaction(object): @@ -236,7 +236,7 @@ if on_win(): @win_only @require_ctypes def replace_file_across_devices(src, dst): - with Transaction(timeout=_ATOMIC_RENAME_FILE_TRANSACTION_DEFAULT_TIMEOUT, description='ya library.python.windows replace_file_across_devices') as transaction: + with Transaction(timeout=_ATOMIC_RENAME_FILE_TRANSACTION_DEFAULT_TIMEOUT, description='ya library.python.windows replace_file_across_devices') as transaction: if not ctypes.windll.kernel32.MoveFileTransactedW(unicode_path(src), unicode_path(dst), None, None, _MOVEFILE_REPLACE_EXISTING | _MOVEFILE_WRITE_THROUGH, transaction): raise ctypes.WinError() diff --git a/library/python/windows/ut/test_windows.py b/library/python/windows/ut/test_windows.py index e255d0560e..bef3ec2dc5 100644 --- a/library/python/windows/ut/test_windows.py +++ b/library/python/windows/ut/test_windows.py @@ -4,16 +4,16 @@ import errno import os import pytest -import library.python.strings -import library.python.windows +import library.python.strings +import library.python.windows def gen_error_access_denied(): - if library.python.windows.on_win(): + if library.python.windows.on_win(): err = WindowsError() err.errno = errno.EACCES err.strerror = '' - err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] + err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] else: err = OSError() err.errno = errno.EACCES @@ -23,7 +23,7 @@ def gen_error_access_denied(): def test_errorfix_buggy(): - @library.python.windows.errorfix + @library.python.windows.errorfix def erroneous_func(): gen_error_access_denied() @@ -36,11 +36,11 @@ def test_errorfix_buggy(): def test_errorfix_explicit(): - @library.python.windows.errorfix + @library.python.windows.errorfix def erroneous_func(): - if library.python.windows.on_win(): + if library.python.windows.on_win(): err = WindowsError() - err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] + err.winerror = library.python.windows.ERRORS['ACCESS_DENIED'] else: err = OSError() err.errno = errno.EACCES @@ -56,27 +56,27 @@ def test_errorfix_explicit(): def test_errorfix_decoding_cp1251(): - @library.python.windows.errorfix + @library.python.windows.errorfix def erroneous_func(): model_msg = u'Какое-то описание ошибки' - if library.python.windows.on_win(): + if library.python.windows.on_win(): err = WindowsError() - err.strerror = library.python.strings.to_str(model_msg, 'cp1251') + err.strerror = library.python.strings.to_str(model_msg, 'cp1251') else: err = OSError() - err.strerror = library.python.strings.to_str(model_msg) + err.strerror = library.python.strings.to_str(model_msg) raise err with pytest.raises(OSError) as errinfo: erroneous_func() error_msg = errinfo.value.strerror if not isinstance(errinfo.value.strerror, unicode): - error_msg = library.python.strings.to_unicode(error_msg) + error_msg = library.python.strings.to_unicode(error_msg) assert error_msg == u'Какое-то описание ошибки' def test_diehard(): - @library.python.windows.diehard(library.python.windows.ERRORS['ACCESS_DENIED'], tries=5) + @library.python.windows.diehard(library.python.windows.ERRORS['ACCESS_DENIED'], tries=5) def erroneous_func(errors): try: gen_error_access_denied() @@ -90,7 +90,7 @@ def test_diehard(): assert errinfo.value.errno == errno.EACCES assert any(e.errno == errno.EACCES for e in raised_errors) assert raised_errors and errinfo.value == raised_errors[-1] - if library.python.windows.on_win(): + if library.python.windows.on_win(): assert len(raised_errors) == 5 else: assert len(raised_errors) == 1 diff --git a/library/python/windows/ut/ya.make b/library/python/windows/ut/ya.make index 5045153b93..c39f1797b8 100644 --- a/library/python/windows/ut/ya.make +++ b/library/python/windows/ut/ya.make @@ -1,11 +1,11 @@ -OWNER(g:yatool) - +OWNER(g:yatool) + PY2TEST() - + TEST_SRCS(test_windows.py) - -PEERDIR( - library/python/windows -) - -END() + +PEERDIR( + library/python/windows +) + +END() diff --git a/library/python/windows/ya.make b/library/python/windows/ya.make index 3b80fb944f..e17f86b67e 100644 --- a/library/python/windows/ya.make +++ b/library/python/windows/ya.make @@ -1,13 +1,13 @@ -OWNER(g:yatool) - -PY23_LIBRARY() - -PY_SRCS(__init__.py) - -PEERDIR( - library/python/func - library/python/strings - contrib/python/six -) - -END() +OWNER(g:yatool) + +PY23_LIBRARY() + +PY_SRCS(__init__.py) + +PEERDIR( + library/python/func + library/python/strings + contrib/python/six +) + +END() diff --git a/library/python/ya.make b/library/python/ya.make index ef12ddec23..2e1eb6e0e1 100644 --- a/library/python/ya.make +++ b/library/python/ya.make @@ -68,8 +68,8 @@ RECURSE( dump_dict edit_distance errorboosterclient - filelock - filelock/ut + filelock + filelock/ut filesys filesys/ut find_root @@ -79,8 +79,8 @@ RECURSE( fnvhash/test framing framing/ut - func - func/ut + func + func/ut fs geolocation geolocation/ut @@ -142,7 +142,7 @@ RECURSE( pyscopg2 pytest pytest-mongodb - pytest/allure + pytest/allure pytest/empty pytest/plugins python-blackboxer @@ -178,8 +178,8 @@ RECURSE( startrek_python_client/tests_int statface_client step - strings - strings/ut + strings + strings/ut svn_ssh svn_version svn_version/ut @@ -204,8 +204,8 @@ RECURSE( watch_dog watch_dog/example wiki - windows - windows/ut + windows + windows/ut yandex_tracker_client yenv yt |