diff options
| author | sobols <[email protected]> | 2022-02-10 16:47:08 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:47:08 +0300 | 
| commit | 03335cb18337a0ef51966452a66a69b01abea218 (patch) | |
| tree | b83306b6e37edeea782e9eed673d89286c4fef35 /library/python | |
| parent | 09961b69c61f471ddd594e0fd877df62a8021562 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/python')
| -rw-r--r-- | library/python/pytest/plugins/collection.py | 4 | ||||
| -rw-r--r-- | library/python/pytest/yatest_tools.py | 4 | ||||
| -rw-r--r-- | library/python/testing/recipe/__init__.py | 6 | ||||
| -rw-r--r-- | library/python/testing/recipe/ya.make | 2 | ||||
| -rw-r--r-- | library/python/testing/yatest_lib/tools.py | 82 | 
5 files changed, 49 insertions, 49 deletions
| diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index f49c675d364..e36f47a78f3 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -85,8 +85,8 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f      if filenames_from_full_filters is not None and module.name not in filenames_from_full_filters:          return True -    test_file_filter = getattr(session.config.option, 'test_file_filter', None)  -    if test_file_filter is None:  +    test_file_filter = getattr(session.config.option, 'test_file_filter', None) +    if test_file_filter is None:          return False      if module.name != test_file_filter.replace('/', '.'):          return True diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py index 7b37688fd41..6b8b8963942 100644 --- a/library/python/pytest/yatest_tools.py +++ b/library/python/pytest/yatest_tools.py @@ -210,8 +210,8 @@ def get_unique_file_path(dir_path, filename, cache=collections.defaultdict(set))          max_path = 260          filename_len = len(dir_path) + len(extension) + tail_length + len(os.sep)          if filename_len < max_path: -            filename = yatest_lib.tools.trim_string(filename, max_path - filename_len)  -    filename = yatest_lib.tools.trim_string(filename, get_max_filename_length(dir_path) - tail_length - len(extension)) + extension  +            filename = yatest_lib.tools.trim_string(filename, max_path - filename_len) +    filename = yatest_lib.tools.trim_string(filename, get_max_filename_length(dir_path) - tail_length - len(extension)) + extension      candidate = os.path.join(dir_path, filename)      key = dir_path + filename diff --git a/library/python/testing/recipe/__init__.py b/library/python/testing/recipe/__init__.py index 91d31d370aa..5ef9c5c1895 100644 --- a/library/python/testing/recipe/__init__.py +++ b/library/python/testing/recipe/__init__.py @@ -1,5 +1,5 @@ -from __future__ import print_function  -  +from __future__ import print_function +  import os  import sys  import json @@ -86,7 +86,7 @@ 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()))  +        print("Recipe \"{} {}\" working dir is {}".format(sys.argv[0], " ".join(argv), os.getcwd()))      try:          if argv[0] == RECIPE_START_OPTION: diff --git a/library/python/testing/recipe/ya.make b/library/python/testing/recipe/ya.make index 0d98ecc3d66..dd323aa2457 100644 --- a/library/python/testing/recipe/ya.make +++ b/library/python/testing/recipe/ya.make @@ -3,7 +3,7 @@ OWNER(      g:yatest  ) -PY23_LIBRARY()  +PY23_LIBRARY()  PY_SRCS(      __init__.py diff --git a/library/python/testing/yatest_lib/tools.py b/library/python/testing/yatest_lib/tools.py index 0cf2ce87c8e..b72d79c1629 100644 --- a/library/python/testing/yatest_lib/tools.py +++ b/library/python/testing/yatest_lib/tools.py @@ -1,4 +1,4 @@ -import six  +import six  import sys @@ -16,46 +16,46 @@ def to_utf8(value):          return value.encode('utf-8', 'ignore')      else:          return str(value) -  -  -def trim_string(s, max_bytes):  -    """  -    Adjusts the length of the string s in order to fit it  -    into max_bytes bytes of storage after encoding as UTF-8.  -    Useful when cutting filesystem paths.  -    :param s: unicode string  -    :param max_bytes: number of bytes  -    :return the prefix of s  -    """  -    if isinstance(s, six.text_type):  -        return _trim_unicode_string(s, max_bytes)  -  -    if isinstance(s, six.binary_type):  -        if len(s) <= max_bytes:  -            return s  -        s = s.decode('utf-8', errors='ignore')  -        s = _trim_unicode_string(s, max_bytes)  -        s = s.encode('utf-8', errors='ignore')  -        return s  -  -    raise TypeError('a string is expected')  -  -  -def _trim_unicode_string(s, max_bytes):  -    if len(s) * 4 <= max_bytes:  -        # UTF-8 uses at most 4 bytes per character  -        return s  -  -    result = []  -    cur_byte_length = 0  -  -    for ch in s:  -        cur_byte_length += len(ch.encode('utf-8'))  -        if cur_byte_length > max_bytes:  -            break  -        result.append(ch)  -  -    return ''.join(result)  + + +def trim_string(s, max_bytes): +    """ +    Adjusts the length of the string s in order to fit it +    into max_bytes bytes of storage after encoding as UTF-8. +    Useful when cutting filesystem paths. +    :param s: unicode string +    :param max_bytes: number of bytes +    :return the prefix of s +    """ +    if isinstance(s, six.text_type): +        return _trim_unicode_string(s, max_bytes) + +    if isinstance(s, six.binary_type): +        if len(s) <= max_bytes: +            return s +        s = s.decode('utf-8', errors='ignore') +        s = _trim_unicode_string(s, max_bytes) +        s = s.encode('utf-8', errors='ignore') +        return s + +    raise TypeError('a string is expected') + + +def _trim_unicode_string(s, max_bytes): +    if len(s) * 4 <= max_bytes: +        # UTF-8 uses at most 4 bytes per character +        return s + +    result = [] +    cur_byte_length = 0 + +    for ch in s: +        cur_byte_length += len(ch.encode('utf-8')) +        if cur_byte_length > max_bytes: +            break +        result.append(ch) + +    return ''.join(result)  def to_str(s): | 
