~ubuntuone-hackers/ols-tests/trunk

« back to all changes in this revision

Viewing changes to ucitests/filters.py

  • Committer: Vincent Ladeuil
  • Date: 2016-01-28 15:47:10 UTC
  • mfrom: (207.1.2 force-list-order)
  • Revision ID: vila+qa@canonical.com-20160128154710-wcj89rikld1fsy0e
Merge --load forcing order

Show diffs side-by-side

added added

removed removed

Lines of Context:
197
197
    return test_list
198
198
 
199
199
 
200
 
class TestIdList(object):
201
 
    """Test id list to filter a test suite.
202
 
 
203
 
    Relying on the assumption that test ids are built as:
204
 
    <module>[.<class>.<method>][(<param>+)], <module> being in python dotted
205
 
    notation, this class offers methods to :
206
 
    - keep only the listed tests from a given suite.
207
 
    """
208
 
 
209
 
    def __init__(self, test_id_list):
210
 
        # When a test suite needs to be filtered against us we compare test ids
211
 
        # for strict equality, so a simple dict offers a quick and simple
212
 
        # solution.
213
 
        self.tests = dict().fromkeys(test_id_list, True)
214
 
 
215
 
    def includes(self, test_id):
216
 
        return test_id in self.tests
217
 
 
218
 
 
219
200
def include_id_list(id_list, suite):
220
201
    """Returns the tests whose id are part of the list.
221
202
 
222
 
    :param id_list: A TestIdList describing the tests that should be kept.
 
203
    The order in the list is enforced in the returned suite. This provides a
 
204
    way to strictly control the order of execution, making isolation issues
 
205
    easier to diagnose.
 
206
 
 
207
    Note that this doesn't filter out duplicates in the list, instead, such
 
208
    duplicates are provided twice.
 
209
 
 
210
    :param id_list: A list of test ids that should be kept.
223
211
 
224
212
    :param suite: The test suite to filter.
 
213
 
225
214
    """
226
215
    if not id_list:
227
 
        # No id list, no filtering
228
 
        return suite
229
 
 
230
 
    return filter_suite(lambda t: id_list.includes(t.id()), suite)
 
216
        # No ids, no tests
 
217
        return suite.__class__()
 
218
 
 
219
    filtered = suite.__class__()
 
220
    for the_id in id_list:
 
221
 
 
222
        def is_the_id(test):
 
223
            return test.id() == the_id
 
224
        just_the_id = filter_suite(is_the_id, suite)
 
225
        # We don't want to wrap the filtered tests into two layers of
 
226
        # suite.__class__ so we extract the single test.
 
227
        if just_the_id.countTestCases():
 
228
            # Keep only non-empty suites
 
229
            filtered.addTest(list(just_the_id)[0])
 
230
    return filtered