How to use flatten_tests method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_splitter.py

Source:test_splitter.py Github

copy

Full Screen

1# coding: utf-82import collections3def flatten_tests(test_classes):4 """5 >>> test_classes = {x: [x] for x in range(5)}6 >>> flatten_tests(test_classes)7 [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]8 >>> test_classes = {x: [x + 1, x + 2] for x in range(2)}9 >>> flatten_tests(test_classes)10 [(0, 1), (0, 2), (1, 2), (1, 3)]11 """12 tests = []13 for class_name, test_names in test_classes.items():14 tests += [(class_name, test_name) for test_name in test_names]15 return tests16def get_sequential_chunk(tests, modulo, modulo_index, is_sorted=False):17 """18 >>> get_sequential_chunk(range(10), 4, 0)19 [0, 1, 2]20 >>> get_sequential_chunk(range(10), 4, 1)21 [3, 4, 5]22 >>> get_sequential_chunk(range(10), 4, 2)23 [6, 7]24 >>> get_sequential_chunk(range(10), 4, 3)25 [8, 9]26 >>> get_sequential_chunk(range(10), 4, 4)27 []28 >>> get_sequential_chunk(range(10), 4, 5)29 []30 """31 if not is_sorted:32 tests = sorted(tests)33 chunk_size = len(tests) // modulo34 not_used = len(tests) % modulo35 shift = chunk_size + (modulo_index < not_used)36 start = chunk_size * modulo_index + min(modulo_index, not_used)37 end = start + shift38 return [] if end > len(tests) else tests[start:end]39def get_shuffled_chunk(tests, modulo, modulo_index, is_sorted=False):40 """41 >>> get_shuffled_chunk(range(10), 4, 0)42 [0, 4, 8]43 >>> get_shuffled_chunk(range(10), 4, 1)44 [1, 5, 9]45 >>> get_shuffled_chunk(range(10), 4, 2)46 [2, 6]47 >>> get_shuffled_chunk(range(10), 4, 3)48 [3, 7]49 >>> get_shuffled_chunk(range(10), 4, 4)50 []51 >>> get_shuffled_chunk(range(10), 4, 5)52 []53 """54 if not is_sorted:55 tests = sorted(tests)56 result_tests = []57 for i, test in enumerate(tests):58 if i % modulo == modulo_index:59 result_tests.append(test)60 return result_tests61def get_splitted_tests(test_entities, modulo, modulo_index, partition_mode, is_sorted=False):62 if partition_mode == 'SEQUENTIAL':63 return get_sequential_chunk(test_entities, modulo, modulo_index, is_sorted)64 elif partition_mode == 'MODULO':65 return get_shuffled_chunk(test_entities, modulo, modulo_index, is_sorted)66 else:67 raise ValueError("detected unknown partition mode: {}".format(partition_mode))68def filter_tests_by_modulo(test_classes, modulo, modulo_index, split_by_tests, partition_mode="SEQUENTIAL"):69 """70 >>> test_classes = {x: [x] for x in range(20)}71 >>> filter_tests_by_modulo(test_classes, 4, 0, False)72 {0: [0], 1: [1], 2: [2], 3: [3], 4: [4]}73 >>> filter_tests_by_modulo(test_classes, 4, 1, False)74 {8: [8], 9: [9], 5: [5], 6: [6], 7: [7]}75 >>> filter_tests_by_modulo(test_classes, 4, 2, False)76 {10: [10], 11: [11], 12: [12], 13: [13], 14: [14]}77 >>> dict(filter_tests_by_modulo(test_classes, 4, 0, True))78 {0: [0], 1: [1], 2: [2], 3: [3], 4: [4]}79 >>> dict(filter_tests_by_modulo(test_classes, 4, 1, True))80 {8: [8], 9: [9], 5: [5], 6: [6], 7: [7]}81 """82 if split_by_tests:83 tests = get_splitted_tests(flatten_tests(test_classes), modulo, modulo_index, partition_mode)84 test_classes = collections.defaultdict(list)85 for class_name, test_name in tests:86 test_classes[class_name].append(test_name)87 return test_classes88 else:89 target_classes = get_splitted_tests(test_classes, modulo, modulo_index, partition_mode)...

Full Screen

Full Screen

test_models.py

Source:test_models.py Github

copy

Full Screen

...11 "ga4gh_identify": ga4gh_identify,12}13validation_fn = os.path.join(os.path.dirname(__file__), "data", "models.yaml")14validation_tests = yaml.load(open(validation_fn), Loader=yaml.SafeLoader)15def flatten_tests(vts):16 """flatten tests to (class, data, function name, exp out) tuples17 Each tuple is a test in which an object of the specified class is18 created with data, evaluated with the named function, and compared19 with the expected output.20 """21 for cls, tests in validation_tests.items():22 for t in tests:23 for fn, exp in t["out"].items():24 test_name = t.get("name", cls)25 test_name += f"-{fn}"26 yield pytest.param(cls, t["in"], fn, exp, id=test_name)27#tests, ids = zip(*list(flatten_tests(validation_tests)))28#import IPython; IPython.embed() ### TODO: Remove IPython.embed()29@pytest.mark.parametrize("cls,data,fn,exp", flatten_tests(validation_tests))30def test_validation(cls, data, fn, exp):31 o = models[cls](**data)32 fx = fxs[fn]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful