aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/testing/yatest_lib
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-11-12 13:34:46 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-11-12 13:46:33 +0300
commit39b2d17a032a25ea4334f40208471552f1e3561b (patch)
tree9187bcf735fa2a2fa17c18156a1165627aabce3a /library/python/testing/yatest_lib
parent4d22358c7791f4b3e7a76167ee52368d34bb37fd (diff)
downloadydb-39b2d17a032a25ea4334f40208471552f1e3561b.tar.gz
Intermediate changes
commit_hash:63f0ba341b35ad9ea632bfc2971f028cebbec800
Diffstat (limited to 'library/python/testing/yatest_lib')
-rw-r--r--library/python/testing/yatest_lib/external.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/library/python/testing/yatest_lib/external.py b/library/python/testing/yatest_lib/external.py
index 249a37c5f0..2863579ee8 100644
--- a/library/python/testing/yatest_lib/external.py
+++ b/library/python/testing/yatest_lib/external.py
@@ -15,6 +15,31 @@ logger = logging.getLogger(__name__)
MDS_URI_PREFIX = 'https://storage.yandex-team.ru/get-devtools/'
+def _do_apply(func, value, apply_to_keys, value_path):
+ if value_path is None:
+ value_path = []
+
+ if isinstance(value, list) or isinstance(value, tuple):
+ res = []
+ for ind, item in enumerate(value):
+ path = copy.copy(value_path)
+ path.append(ind)
+ res.append(_do_apply(func, item, apply_to_keys, path))
+ elif isinstance(value, dict):
+ if is_external(value):
+ # this is a special serialized object pointing to some external place
+ res = func(value, value_path)
+ else:
+ res = {}
+ for key, val in sorted(value.items(), key=lambda dict_item: dict_item[0]):
+ path = copy.copy(value_path)
+ path.append(key)
+ res[_do_apply(func, key, apply_to_keys, path) if apply_to_keys else key] = _do_apply(func, val, apply_to_keys, path)
+ else:
+ res = func(value, value_path)
+ return res
+
+
def apply(func, value, apply_to_keys=False):
"""
Applies func to every possible member of value
@@ -22,30 +47,7 @@ def apply(func, value, apply_to_keys=False):
:param func: func to be applied
:return:
"""
- def _apply(func, value, value_path):
- if value_path is None:
- value_path = []
-
- if isinstance(value, list) or isinstance(value, tuple):
- res = []
- for ind, item in enumerate(value):
- path = copy.copy(value_path)
- path.append(ind)
- res.append(_apply(func, item, path))
- elif isinstance(value, dict):
- if is_external(value):
- # this is a special serialized object pointing to some external place
- res = func(value, value_path)
- else:
- res = {}
- for key, val in sorted(value.items(), key=lambda dict_item: dict_item[0]):
- path = copy.copy(value_path)
- path.append(key)
- res[_apply(func, key, path) if apply_to_keys else key] = _apply(func, val, path)
- else:
- res = func(value, value_path)
- return res
- return _apply(func, value, None)
+ return _do_apply(func, value, apply_to_keys, None)
def is_coroutine(val):