Best Python code snippet using avocado_python
tags.py
Source:tags.py
...35 else:36 must.add(tag)37 result.append((must, must_not))38 return result39def _must_split_flat_key_val(must):40 """41 Splits the flat and key:val tags apart42 :returns: the flat set tags and the key:val tags43 :rtype: tuple(set, dict)44 """45 key_val = {}46 flat = set()47 for i in must:48 if ':' in i:49 k, v = i.split(':', 1)50 key_val[k] = v51 else:52 flat.add(i)53 return flat, key_val54def _must_key_val_matches(must_key_vals, test_tags, include_empty_key):55 """56 Checks if the required key:vals are fulfilled by the test_tags57 :rtype: bool58 """59 key_val_test_tags = {}60 for k, v in test_tags.items():61 if v is None:62 continue63 key_val_test_tags[k] = v64 for k, v in must_key_vals.items():65 if k not in test_tags:66 if include_empty_key:67 continue68 else:69 return False70 if v not in key_val_test_tags.get(k, set()):71 return False72 return True73def filter_test_tags(test_suite, filter_by_tags, include_empty=False,74 include_empty_key=False):75 """76 Filter the existing (unfiltered) test suite based on tags77 The filtering mechanism is agnostic to test type. It means that78 if users request filtering by tag and the specific test type does79 not populate the test tags, it will be considered to have empty80 tags.81 :param test_suite: the unfiltered test suite82 :type test_suite: dict83 :param filter_by_tags: the list of tag sets to use as filters84 :type filter_by_tags: list of comma separated tags (['foo,bar', 'fast'])85 :param include_empty: if true tests without tags will not be filtered out86 :type include_empty: bool87 :param include_empty_key: if true tests "keys" on key:val tags will be88 included in the filtered results89 :type include_empty_key: bool90 """91 filtered = []92 must_must_nots = _parse_filter_by_tags(filter_by_tags)93 for klass, info in test_suite:94 test_tags = info.get('tags', {})95 if not test_tags:96 if include_empty:97 filtered.append((klass, info))98 continue99 for must, must_not in must_must_nots:100 if must_not.intersection(test_tags):101 continue102 must_flat, must_key_val = _must_split_flat_key_val(must)103 if must_key_val:104 if not _must_key_val_matches(must_key_val,105 test_tags,106 include_empty_key):107 continue108 if must_flat:109 if not must_flat.issubset(test_tags):110 continue111 filtered.append((klass, info))112 break113 return filtered114def filter_test_tags_runnable(runnable, filter_by_tags, include_empty=False,115 include_empty_key=False):116 """117 Filter the existing (unfiltered) test suite based on tags118 The filtering mechanism is agnostic to test type. It means that119 if users request filtering by tag and the specific test type does120 not populate the test tags, it will be considered to have empty121 tags.122 :param test_suite: the unfiltered test suite123 :type test_suite: dict124 :param filter_by_tags: the list of tag sets to use as filters125 :type filter_by_tags: list of comma separated tags (['foo,bar', 'fast'])126 :param include_empty: if true tests without tags will not be filtered out127 :type include_empty: bool128 :param include_empty_key: if true tests "keys" on key:val tags will be129 included in the filtered results130 :type include_empty_key: bool131 """132 must_must_nots = _parse_filter_by_tags(filter_by_tags)133 runnable_tags = runnable.tags or {}134 if not runnable_tags:135 if include_empty:136 return True137 for must, must_not in must_must_nots:138 if must_not.intersection(runnable_tags):139 continue140 must_flat, must_key_val = _must_split_flat_key_val(must)141 if must_key_val:142 if not _must_key_val_matches(must_key_val,143 runnable_tags,144 include_empty_key):145 continue146 if must_flat:147 if not must_flat.issubset(runnable_tags):148 continue149 return True...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!