How to use filter_by_ids method in stestr

Best Python code snippet using stestr_python

testsuite.py

Source:testsuite.py Github

copy

Full Screen

...203 # If it has a sort_tests method, call that.204 if safe_hasattr(suite_or_case, 'sort_tests'):205 suite_or_case.sort_tests()206 return [(suite_id, suite_or_case)]207def filter_by_ids(suite_or_case, test_ids):208 """Remove tests from suite_or_case where their id is not in test_ids.209 210 :param suite_or_case: A test suite or test case.211 :param test_ids: Something that supports the __contains__ protocol.212 :return: suite_or_case, unless suite_or_case was a case that itself213 fails the predicate when it will return a new unittest.TestSuite with214 no contents.215 This helper exists to provide backwards compatability with older versions216 of Python (currently all versions :)) that don't have a native217 filter_by_ids() method on Test(Case|Suite).218 For subclasses of TestSuite, filtering is done by:219 - attempting to call suite.filter_by_ids(test_ids)220 - if there is no method, iterating the suite and identifying tests to221 remove, then removing them from _tests, manually recursing into222 each entry.223 For objects with an id() method - TestCases, filtering is done by:224 - attempting to return case.filter_by_ids(test_ids)225 - if there is no such method, checking for case.id() in test_ids226 and returning case if it is, or TestSuite() if it is not.227 For anything else, it is not filtered - it is returned as-is.228 To provide compatability with this routine for a custom TestSuite, just229 define a filter_by_ids() method that will return a TestSuite equivalent to230 the original minus any tests not in test_ids.231 Similarly to provide compatability for a custom TestCase that does232 something unusual define filter_by_ids to return a new TestCase object233 that will only run test_ids that are in the provided container. If none234 would run, return an empty TestSuite().235 The contract for this function does not require mutation - each filtered236 object can choose to return a new object with the filtered tests. However237 because existing custom TestSuite classes in the wild do not have this238 method, we need a way to copy their state correctly which is tricky:239 thus the backwards-compatible code paths attempt to mutate in place rather240 than guessing how to reconstruct a new suite.241 """242 # Compatible objects243 if safe_hasattr(suite_or_case, 'filter_by_ids'):244 return suite_or_case.filter_by_ids(test_ids)245 # TestCase objects.246 if safe_hasattr(suite_or_case, 'id'):247 if suite_or_case.id() in test_ids:248 return suite_or_case249 else:250 return unittest.TestSuite()251 # Standard TestSuites or derived classes [assumed to be mutable].252 if isinstance(suite_or_case, unittest.TestSuite):253 filtered = []254 for item in suite_or_case:255 filtered.append(filter_by_ids(item, test_ids))256 suite_or_case._tests[:] = filtered257 # Everything else:258 return suite_or_case259def sorted_tests(suite_or_case, unpack_outer=False):260 """Sort suite_or_case while preserving non-vanilla TestSuites."""261 # Duplicate test id can induce TypeError in Python 3.3.262 # Detect the duplicate test id, raise exception when found.263 seen = set()264 for test_case in iterate_tests(suite_or_case):265 test_id = test_case.id()266 if test_id not in seen:267 seen.add(test_id)268 else:269 raise ValueError('Duplicate test id detected: %s' % (test_id,))...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

...88 data_filters,89 reserved_keys=items,90 full_embeddings=data_manager.get_embeddings(91 dataset_id))92 projected_embeddings = filter_by_ids(projected_embeddings,93 embeddings.keys())94 result = {}95 for word, coords in projected_embeddings.items():96 val = metadata.get(word, {})97 val["coords"] = coords98 result[word] = val99 return result100def filter(embeddings, metadata, metadata_type, rank_slice=None,101 metadata_filters=None, data_filters=None,102 reserved_keys=None, full_embeddings=None):103 filtered_embeddings = embeddings104 filtered_metadata = metadata105 # slice106 if rank_slice:107 filtered_ids = slice_embeddings(filtered_embeddings, rank_slice,108 reserved_keys)109 if len(filtered_ids) == 0:110 return {}, {}111 else:112 filtered_embeddings = filter_by_ids(filtered_embeddings,113 filtered_ids)114 filtered_metadata = filter_by_ids(filtered_metadata, filtered_ids)115 # metadata filtering116 if metadata_filters and len(metadata_filters) > 0:117 filtered_ids = filter_embeddings_metadata(filtered_metadata,118 metadata_type,119 metadata_filters)120 if len(filtered_ids) == 0:121 return {}, {}122 else:123 filtered_embeddings = filter_by_ids(filtered_embeddings,124 filtered_ids)125 filtered_metadata = filter_by_ids(filtered_metadata, filtered_ids)126 # data filtering127 if data_filters and len(data_filters) > 0:128 filtered_ids = filter_embeddings(filtered_embeddings,129 data_filters,130 full_embeddings=full_embeddings if full_embeddings is not None else embeddings)131 if len(filtered_ids) == 0:132 return {}, {}133 else:134 filtered_embeddings = filter_by_ids(filtered_embeddings,135 filtered_ids)136 filtered_metadata = filter_by_ids(filtered_metadata, filtered_ids)...

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 stestr 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