summaryrefslogtreecommitdiffstats
path: root/library/python/testing/filter
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/testing/filter
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/testing/filter')
-rw-r--r--library/python/testing/filter/filter.py57
-rw-r--r--library/python/testing/filter/ya.make5
2 files changed, 62 insertions, 0 deletions
diff --git a/library/python/testing/filter/filter.py b/library/python/testing/filter/filter.py
new file mode 100644
index 00000000000..a1642bd052f
--- /dev/null
+++ b/library/python/testing/filter/filter.py
@@ -0,0 +1,57 @@
+# coding: utf-8
+# TODO move devtools/ya/test/filter.py to library/python/testing/filter/filter.py
+import re
+import fnmatch
+import logging
+
+logger = logging.getLogger(__name__)
+TEST_SUBTEST_SEPARATOR = '::'
+
+PARSE_TAG_RE = re.compile("([+-]?[\w:]*)")
+
+
+class FilterException(Exception):
+ mute = True
+
+
+def fix_filter(flt):
+ if TEST_SUBTEST_SEPARATOR not in flt and "*" not in flt:
+ # user wants to filter by test module name
+ flt = flt + TEST_SUBTEST_SEPARATOR + "*"
+ return flt
+
+
+def escape_for_fnmatch(s):
+ return s.replace("[", "&#91;").replace("]", "&#93;")
+
+
+def make_py_file_filter(filter_names):
+ if filter_names is not None:
+ with_star = []
+ wo_star = set()
+ for flt in filter_names:
+ flt = flt.split(':')[0]
+ if '*' in flt:
+ with_star.append(flt.split('*')[0] + '*')
+ else:
+ wo_star.add(flt)
+
+ def predicate(filename):
+ if filter_names is None:
+ return True
+ return filename in wo_star or any([fnmatch.fnmatch(escape_for_fnmatch(filename), escape_for_fnmatch(filter_name)) for filter_name in with_star])
+
+ return predicate
+
+
+def make_name_filter(filter_names):
+ filter_names = map(fix_filter, filter_names)
+ filter_full_names = set()
+ for name in filter_names:
+ if '*' not in name:
+ filter_full_names.add(name)
+
+ def predicate(testname):
+ return testname in filter_full_names or any([fnmatch.fnmatch(escape_for_fnmatch(testname), escape_for_fnmatch(filter_name)) for filter_name in filter_names])
+
+ return predicate
diff --git a/library/python/testing/filter/ya.make b/library/python/testing/filter/ya.make
new file mode 100644
index 00000000000..22c485d2580
--- /dev/null
+++ b/library/python/testing/filter/ya.make
@@ -0,0 +1,5 @@
+PY23_LIBRARY()
+OWNER(g:yatest)
+PY_SRCS(filter.py)
+
+END()