diff options
author | iaz1607 <iaz1607@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
commit | e5437feb4ac2d2dc044e1090b9312dde5ef197e0 (patch) | |
tree | f5a238c69dd20a1fa2092127a31b8aff25020f7d /library/python/testing/yatest_lib | |
parent | f4945d0a44b8770f0801de3056aa41639b0b7bd2 (diff) | |
download | ydb-e5437feb4ac2d2dc044e1090b9312dde5ef197e0.tar.gz |
Restoring authorship annotation for <iaz1607@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/testing/yatest_lib')
-rw-r--r-- | library/python/testing/yatest_lib/test_splitter.py | 104 | ||||
-rw-r--r-- | library/python/testing/yatest_lib/tests/test_testsplitter.py | 206 | ||||
-rw-r--r-- | library/python/testing/yatest_lib/tests/ya.make | 22 | ||||
-rw-r--r-- | library/python/testing/yatest_lib/ya.make | 6 |
4 files changed, 169 insertions, 169 deletions
diff --git a/library/python/testing/yatest_lib/test_splitter.py b/library/python/testing/yatest_lib/test_splitter.py index acbcd4300e..2f2ec39a6e 100644 --- a/library/python/testing/yatest_lib/test_splitter.py +++ b/library/python/testing/yatest_lib/test_splitter.py @@ -18,66 +18,66 @@ def flatten_tests(test_classes): return tests -def get_sequential_chunk(tests, modulo, modulo_index, is_sorted=False): +def get_sequential_chunk(tests, modulo, modulo_index, is_sorted=False): """ - >>> get_sequential_chunk(range(10), 4, 0) + >>> get_sequential_chunk(range(10), 4, 0) [0, 1, 2] - >>> get_sequential_chunk(range(10), 4, 1) + >>> get_sequential_chunk(range(10), 4, 1) [3, 4, 5] - >>> get_sequential_chunk(range(10), 4, 2) - [6, 7] - >>> get_sequential_chunk(range(10), 4, 3) - [8, 9] - >>> get_sequential_chunk(range(10), 4, 4) + >>> get_sequential_chunk(range(10), 4, 2) + [6, 7] + >>> get_sequential_chunk(range(10), 4, 3) + [8, 9] + >>> get_sequential_chunk(range(10), 4, 4) [] - >>> get_sequential_chunk(range(10), 4, 5) + >>> get_sequential_chunk(range(10), 4, 5) [] """ - if not is_sorted: - tests = sorted(tests) - chunk_size = len(tests) // modulo - not_used = len(tests) % modulo - shift = chunk_size + (modulo_index < not_used) - start = chunk_size * modulo_index + min(modulo_index, not_used) + if not is_sorted: + tests = sorted(tests) + chunk_size = len(tests) // modulo + not_used = len(tests) % modulo + shift = chunk_size + (modulo_index < not_used) + start = chunk_size * modulo_index + min(modulo_index, not_used) end = start + shift - return [] if end > len(tests) else tests[start:end] + return [] if end > len(tests) else tests[start:end] -def get_shuffled_chunk(tests, modulo, modulo_index, is_sorted=False): - """ - >>> get_shuffled_chunk(range(10), 4, 0) - [0, 4, 8] - >>> get_shuffled_chunk(range(10), 4, 1) - [1, 5, 9] - >>> get_shuffled_chunk(range(10), 4, 2) - [2, 6] - >>> get_shuffled_chunk(range(10), 4, 3) - [3, 7] - >>> get_shuffled_chunk(range(10), 4, 4) - [] - >>> get_shuffled_chunk(range(10), 4, 5) - [] - """ - if not is_sorted: - tests = sorted(tests) - result_tests = [] - for i, test in enumerate(tests): - if i % modulo == modulo_index: - result_tests.append(test) - return result_tests - - -def get_splitted_tests(test_entities, modulo, modulo_index, partition_mode, is_sorted=False): - if partition_mode == 'SEQUENTIAL': - return get_sequential_chunk(test_entities, modulo, modulo_index, is_sorted) - elif partition_mode == 'MODULO': - return get_shuffled_chunk(test_entities, modulo, modulo_index, is_sorted) - else: - raise ValueError("detected unknown partition mode: {}".format(partition_mode)) - - -def filter_tests_by_modulo(test_classes, modulo, modulo_index, split_by_tests, partition_mode="SEQUENTIAL"): +def get_shuffled_chunk(tests, modulo, modulo_index, is_sorted=False): """ + >>> get_shuffled_chunk(range(10), 4, 0) + [0, 4, 8] + >>> get_shuffled_chunk(range(10), 4, 1) + [1, 5, 9] + >>> get_shuffled_chunk(range(10), 4, 2) + [2, 6] + >>> get_shuffled_chunk(range(10), 4, 3) + [3, 7] + >>> get_shuffled_chunk(range(10), 4, 4) + [] + >>> get_shuffled_chunk(range(10), 4, 5) + [] + """ + if not is_sorted: + tests = sorted(tests) + result_tests = [] + for i, test in enumerate(tests): + if i % modulo == modulo_index: + result_tests.append(test) + return result_tests + + +def get_splitted_tests(test_entities, modulo, modulo_index, partition_mode, is_sorted=False): + if partition_mode == 'SEQUENTIAL': + return get_sequential_chunk(test_entities, modulo, modulo_index, is_sorted) + elif partition_mode == 'MODULO': + return get_shuffled_chunk(test_entities, modulo, modulo_index, is_sorted) + else: + raise ValueError("detected unknown partition mode: {}".format(partition_mode)) + + +def filter_tests_by_modulo(test_classes, modulo, modulo_index, split_by_tests, partition_mode="SEQUENTIAL"): + """ >>> test_classes = {x: [x] for x in range(20)} >>> filter_tests_by_modulo(test_classes, 4, 0, False) {0: [0], 1: [1], 2: [2], 3: [3], 4: [4]} @@ -92,11 +92,11 @@ def filter_tests_by_modulo(test_classes, modulo, modulo_index, split_by_tests, p {8: [8], 9: [9], 5: [5], 6: [6], 7: [7]} """ if split_by_tests: - tests = get_splitted_tests(flatten_tests(test_classes), modulo, modulo_index, partition_mode) + tests = get_splitted_tests(flatten_tests(test_classes), modulo, modulo_index, partition_mode) test_classes = collections.defaultdict(list) for class_name, test_name in tests: test_classes[class_name].append(test_name) return test_classes else: - target_classes = get_splitted_tests(test_classes, modulo, modulo_index, partition_mode) + target_classes = get_splitted_tests(test_classes, modulo, modulo_index, partition_mode) return {class_name: test_classes[class_name] for class_name in target_classes} diff --git a/library/python/testing/yatest_lib/tests/test_testsplitter.py b/library/python/testing/yatest_lib/tests/test_testsplitter.py index 394bfe5a74..87842e0ceb 100644 --- a/library/python/testing/yatest_lib/tests/test_testsplitter.py +++ b/library/python/testing/yatest_lib/tests/test_testsplitter.py @@ -1,103 +1,103 @@ -# coding: utf-8 -from yatest_lib import test_splitter - - -def get_chunks(tests, modulo, mode): - chunks = [] - if mode == "MODULO": - for modulo_index in range(modulo): - chunks.append(test_splitter.get_shuffled_chunk(tests, modulo, modulo_index)) - elif mode == "SEQUENTIAL": - for modulo_index in range(modulo): - chunks.append(test_splitter.get_sequential_chunk(tests, modulo, modulo_index)) - else: - raise ValueError("no such mode") - return chunks - - -def check_not_intersect(chunk_list): - test_set = set() - total_size = 0 - for tests in chunk_list: - total_size += len(tests) - test_set.update(tests) - return total_size == len(test_set) - - -def check_max_diff(chunk_list): - return max(map(len, chunk_list)) - min(map(len, chunk_list)) - - -def test_lot_of_chunks(): - for chunk_count in range(10, 20): - for tests_count in range(chunk_count): - chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert chunks.count([]) == chunk_count - tests_count - assert len(chunks) == chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "MODULO") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert chunks.count([]) == chunk_count - tests_count - assert len(chunks) == chunk_count - - -def test_lot_of_tests(): - for tests_count in range(10, 20): - for chunk_count in range(2, tests_count): - chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "MODULO") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count - - -def prime_chunk_count(): - for chunk_count in [7, 11, 13, 17, 23, 29]: - for tests_count in range(chunk_count): - chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "MODULO") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count - - -def get_divisors(number): - divisors = [] - for d in range(1, number + 1): - if number % d == 0: - divisors.append(d) - return divisors - - -def equal_chunks(): - for chunk_count in range(12, 31): - for tests_count in get_divisors(chunk_count): - chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) == 0 - assert len(chunks) == chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "MODULO") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) == 0 - assert len(chunks) == chunk_count - - -def chunk_count_equal_tests_count(): - for chunk_count in range(10, 20): - tests_count = chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count - chunks = get_chunks(range(tests_count), chunk_count, "MODULO") - assert check_not_intersect(chunks) - assert check_max_diff(chunks) <= 1 - assert len(chunks) == chunk_count +# coding: utf-8 +from yatest_lib import test_splitter + + +def get_chunks(tests, modulo, mode): + chunks = [] + if mode == "MODULO": + for modulo_index in range(modulo): + chunks.append(test_splitter.get_shuffled_chunk(tests, modulo, modulo_index)) + elif mode == "SEQUENTIAL": + for modulo_index in range(modulo): + chunks.append(test_splitter.get_sequential_chunk(tests, modulo, modulo_index)) + else: + raise ValueError("no such mode") + return chunks + + +def check_not_intersect(chunk_list): + test_set = set() + total_size = 0 + for tests in chunk_list: + total_size += len(tests) + test_set.update(tests) + return total_size == len(test_set) + + +def check_max_diff(chunk_list): + return max(map(len, chunk_list)) - min(map(len, chunk_list)) + + +def test_lot_of_chunks(): + for chunk_count in range(10, 20): + for tests_count in range(chunk_count): + chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert chunks.count([]) == chunk_count - tests_count + assert len(chunks) == chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "MODULO") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert chunks.count([]) == chunk_count - tests_count + assert len(chunks) == chunk_count + + +def test_lot_of_tests(): + for tests_count in range(10, 20): + for chunk_count in range(2, tests_count): + chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "MODULO") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count + + +def prime_chunk_count(): + for chunk_count in [7, 11, 13, 17, 23, 29]: + for tests_count in range(chunk_count): + chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "MODULO") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count + + +def get_divisors(number): + divisors = [] + for d in range(1, number + 1): + if number % d == 0: + divisors.append(d) + return divisors + + +def equal_chunks(): + for chunk_count in range(12, 31): + for tests_count in get_divisors(chunk_count): + chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) == 0 + assert len(chunks) == chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "MODULO") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) == 0 + assert len(chunks) == chunk_count + + +def chunk_count_equal_tests_count(): + for chunk_count in range(10, 20): + tests_count = chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "SEQUENTIAL") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count + chunks = get_chunks(range(tests_count), chunk_count, "MODULO") + assert check_not_intersect(chunks) + assert check_max_diff(chunks) <= 1 + assert len(chunks) == chunk_count diff --git a/library/python/testing/yatest_lib/tests/ya.make b/library/python/testing/yatest_lib/tests/ya.make index 8586c6ef7d..6670106533 100644 --- a/library/python/testing/yatest_lib/tests/ya.make +++ b/library/python/testing/yatest_lib/tests/ya.make @@ -1,14 +1,14 @@ OWNER(g:yatest) - + PY23_TEST() - -PEERDIR( - library/python/testing/yatest_lib -) - -TEST_SRCS( + +PEERDIR( + library/python/testing/yatest_lib +) + +TEST_SRCS( test_external.py - test_testsplitter.py -) - -END() + test_testsplitter.py +) + +END() diff --git a/library/python/testing/yatest_lib/ya.make b/library/python/testing/yatest_lib/ya.make index 342bae82ba..9b1d5224ea 100644 --- a/library/python/testing/yatest_lib/ya.make +++ b/library/python/testing/yatest_lib/ya.make @@ -6,7 +6,7 @@ PY_SRCS( NAMESPACE yatest_lib external.py - test_splitter.py + test_splitter.py tools.py ya.py ) @@ -22,5 +22,5 @@ IF(PYTHON2) ENDIF() END() - -RECURSE_FOR_TESTS(tests) + +RECURSE_FOR_TESTS(tests) |