diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /library/python/testing | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/testing')
-rw-r--r-- | library/python/testing/import_test/import_test.py | 106 | ||||
-rw-r--r-- | library/python/testing/yatest_common/yatest/common/process.py | 8 |
2 files changed, 57 insertions, 57 deletions
diff --git a/library/python/testing/import_test/import_test.py b/library/python/testing/import_test/import_test.py index 3e3b7234ef..720a972ea3 100644 --- a/library/python/testing/import_test/import_test.py +++ b/library/python/testing/import_test/import_test.py @@ -1,15 +1,15 @@ from __future__ import print_function -import os -import re +import os +import re import sys import time import traceback -import __res -from __res import importer - +import __res +from __res import importer + def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): """ tests all bundled modules are importable @@ -17,24 +17,24 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): "PEERDIR(library/python/import_test)" to your CMakeLists.txt and "from import_test import test_imports" to your python test source file. """ - str_ = lambda s: s - if not isinstance(b'', str): - str_ = lambda s: s.decode('UTF-8') - - exceptions = list(no_check) - for key, _ in __res.iter_keys(b'py/no_check_imports/'): - exceptions += str_(__res.find(key)).split() - if exceptions: - exceptions.sort() - print('NO_CHECK_IMPORTS', ' '.join(exceptions)) - - patterns = [re.escape(s).replace(r'\*', r'.*') for s in exceptions] - rx = re.compile('^({})$'.format('|'.join(patterns))) - - failed = [] + str_ = lambda s: s + if not isinstance(b'', str): + str_ = lambda s: s.decode('UTF-8') + + exceptions = list(no_check) + for key, _ in __res.iter_keys(b'py/no_check_imports/'): + exceptions += str_(__res.find(key)).split() + if exceptions: + exceptions.sort() + print('NO_CHECK_IMPORTS', ' '.join(exceptions)) + + patterns = [re.escape(s).replace(r'\*', r'.*') for s in exceptions] + rx = re.compile('^({})$'.format('|'.join(patterns))) + + failed = [] import_times = {} - norm = lambda s: s[:-9] if s.endswith('.__init__') else s + norm = lambda s: s[:-9] if s.endswith('.__init__') else s modules = sys.extra_modules | set(extra) modules = sorted(modules, key=norm) @@ -42,15 +42,15 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): 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 - - name = module.rsplit('.', 1)[-1] - if name == '__main__' and 'if __name__ ==' not in importer.get_source(module): - print('SKIP', module, '''without "if __name__ == '__main__'" check''') + if module not in extra and (rx.search(module) or skip_func and skip_func(module)): + print('SKIP', module) continue + name = module.rsplit('.', 1)[-1] + if name == '__main__' and 'if __name__ ==' not in importer.get_source(module): + print('SKIP', module, '''without "if __name__ == '__main__'" check''') + continue + def print_backtrace_marked(e): tb_exc = traceback.format_exception(*e) for item in tb_exc: @@ -58,18 +58,18 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): print('FAIL:', l, file=sys.stderr) try: - print('TRY', module) + print('TRY', module) # XXX waiting for py3 to use print(..., flush=True) sys.stdout.flush() s = time.time() - if module == '__main__': - importer.load_module('__main__', '__main__py') + if module == '__main__': + importer.load_module('__main__', '__main__py') elif module.endswith('.__init__'): __import__(module[:-len('.__init__')]) - else: - __import__(module) - + else: + __import__(module) + delay = time.time() - s import_times[str(module)] = delay print('OK ', module, '{:.3f}s'.format(delay)) @@ -77,8 +77,8 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): except Exception as e: print('FAIL:', module, e, file=sys.stderr) print_backtrace_marked(sys.exc_info()) - failed.append('{}: {}'.format(module, e)) - + failed.append('{}: {}'.format(module, e)) + except: e = sys.exc_info() print('FAIL:', module, e, file=sys.stderr) @@ -91,25 +91,25 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): print(' ', '{:.3f}s'.format(t), m) if failed: - raise ImportError('modules not imported:\n' + '\n'.join(failed)) - + raise ImportError('modules not imported:\n' + '\n'.join(failed)) -test_imports = check_imports - -def main(): - skip_names = sys.argv[1:] - - os.environ['Y_PYTHON_IMPORT_TEST'] = '' +test_imports = check_imports + + +def main(): + skip_names = sys.argv[1:] + + os.environ['Y_PYTHON_IMPORT_TEST'] = '' # We should initialize Django before importing any applications if os.getenv('DJANGO_SETTINGS_MODULE'): - try: - import django - except ImportError: - pass - else: - django.setup() + try: + import django + except ImportError: + pass + else: + django.setup() py_main = __res.find('PY_MAIN') @@ -118,7 +118,7 @@ def main(): else: py_main_module = None - try: + try: check_imports(no_check=skip_names, py_main=py_main_module) - except: - sys.exit(1) + except: + sys.exit(1) diff --git a/library/python/testing/yatest_common/yatest/common/process.py b/library/python/testing/yatest_common/yatest/common/process.py index a8bcc21f51..54a899c2ba 100644 --- a/library/python/testing/yatest_common/yatest/common/process.py +++ b/library/python/testing/yatest_common/yatest/common/process.py @@ -475,7 +475,7 @@ def execute( if isinstance(stream, six.string_types): # User filename is supplied: open file for writing - return open(stream, 'wb+'), stream.startswith('/dev/') + return open(stream, 'wb+'), stream.startswith('/dev/') # Open file or PIPE sentinel is supplied is_pipe = stream == subprocess.PIPE @@ -626,7 +626,7 @@ def wait_for(check_function, timeout, fail_message="", sleep_time=1.0, on_check_ raise TimeoutError(truncate(message, MAX_MESSAGE_LEN)) -def _kill_process_tree(process_pid, target_pid_signal=None): +def _kill_process_tree(process_pid, target_pid_signal=None): """ Kills child processes, req. Note that psutil should be installed @param process_pid: parent id to search for descendants @@ -653,7 +653,7 @@ def _get_binname(pid): return "error({})".format(e) -def _nix_kill_process_tree(pid, target_pid_signal=None): +def _nix_kill_process_tree(pid, target_pid_signal=None): """ Kills the process tree. """ @@ -680,7 +680,7 @@ def _nix_kill_process_tree(pid, target_pid_signal=None): yatest_logger.debug("Killing child pid {pid} failed: {error}".format(pid=child_pid, error=e)) continue - try_to_send_signal(pid, target_pid_signal or signal.SIGKILL) # Kill the root process. + try_to_send_signal(pid, target_pid_signal or signal.SIGKILL) # Kill the root process. # sometimes on freebsd sigkill cannot kill the process and either sigkill or sigcont should be sent # https://www.mail-archive.com/freebsd-hackers@freebsd.org/msg159646.html |