Beispiel #1
0
def LoadTestCasesToBeRun(test_class, finder_options, test_filter_str,
                         filter_tests_after_sharding, total_shards,
                         shard_index, test_times, debug_shard_distributions,
                         typ_options):
    test_cases = []
    match_everything = lambda *args: True
    if test_filter_str:
        test_filter_matcher_func = _DoesTestMatchFilter
    else:
        test_filter_matcher_func = match_everything
    if filter_tests_after_sharding:
        test_filter_matcher = match_everything
        post_test_filter_matcher = test_filter_matcher_func
    else:
        test_filter_matcher = test_filter_matcher_func
        post_test_filter_matcher = match_everything

    for t in serially_executed_browser_test_case.GenerateTestCases(
            test_class, finder_options):
        assert t.id().startswith(typ_options.test_name_prefix), (
            'The test prefix passed at the command line does not match the prefix '
            'of the tests generated')
        if test_filter_matcher(test_filter_str,
                               t.id()[len(typ_options.test_name_prefix):]):
            test_cases.append(t)
    if test_times:
        # Assign tests to shards.
        shards = _SplitShardsByTime(test_cases, total_shards, test_times,
                                    debug_shard_distributions)
        return [
            t for t in shards[shard_index] if post_test_filter_matcher(
                test_filter_str,
                t.id()[len(typ_options.test_name_prefix):])
        ]
    else:
        test_cases.sort(key=lambda t: t.shortName())
        test_range = _TestRangeForShard(total_shards, shard_index,
                                        len(test_cases))
        if debug_shard_distributions:
            tmp_shards = []
            for i in xrange(total_shards):
                tmp_range = _TestRangeForShard(total_shards, i,
                                               len(test_cases))
                tmp_shards.append(test_cases[tmp_range[0]:tmp_range[1]])
            # Can edit the code to get 'test_times' passed in here for
            # debugging and comparison purposes.
            _DebugShardDistributions(tmp_shards, None)
        return [
            t for t in test_cases[test_range[0]:test_range[1]]
            if post_test_filter_matcher(
                test_filter_str,
                t.id()[len(typ_options.test_name_prefix):])
        ]
Beispiel #2
0
def _LoadTests(test_class, finder_options, filter_regex_str,
               filter_tests_after_sharding, total_shards, shard_index,
               test_times, debug_shard_distributions):
    test_cases = []
    real_regex = re.compile(filter_regex_str)
    noop_regex = re.compile('')
    if filter_tests_after_sharding:
        filter_regex = noop_regex
        post_filter_regex = real_regex
    else:
        filter_regex = real_regex
        post_filter_regex = noop_regex

    for t in serially_executed_browser_test_case.GenerateTestCases(
            test_class, finder_options):
        if filter_regex.search(t.shortName()):
            test_cases.append(t)

    if test_times:
        # Assign tests to shards.
        shards = _SplitShardsByTime(test_cases, total_shards, test_times,
                                    debug_shard_distributions)
        return [
            t for t in shards[shard_index]
            if post_filter_regex.search(t.shortName())
        ]
    else:
        test_cases.sort(key=lambda t: t.shortName())
        test_range = _TestRangeForShard(total_shards, shard_index,
                                        len(test_cases))
        if debug_shard_distributions:
            tmp_shards = []
            for i in xrange(total_shards):
                tmp_range = _TestRangeForShard(total_shards, i,
                                               len(test_cases))
                tmp_shards.append(test_cases[tmp_range[0]:tmp_range[1]])
            # Can edit the code to get 'test_times' passed in here for
            # debugging and comparison purposes.
            _DebugShardDistributions(tmp_shards, None)
        return [
            t for t in test_cases[test_range[0]:test_range[1]]
            if post_filter_regex.search(t.shortName())
        ]
def LoadTestCasesToBeRun(
    test_class, finder_options, filter_tests_after_sharding,
    total_shards, shard_index, test_times, debug_shard_distributions,
    typ_runner):
  test_cases = []
  match_everything = lambda _: True
  test_filter_matcher_func = typ_runner.matches_filter
  if filter_tests_after_sharding:
    test_filter_matcher = match_everything
    post_test_filter_matcher = test_filter_matcher_func
  else:
    test_filter_matcher = test_filter_matcher_func
    post_test_filter_matcher = match_everything

  for t in serially_executed_browser_test_case.GenerateTestCases(
      test_class, finder_options):
    if test_filter_matcher(t):
      test_cases.append(t)
  if test_times:
    # Assign tests to shards.
    shards = _SplitShardsByTime(test_cases, total_shards, test_times,
                                debug_shard_distributions)
    return [t for t in shards[shard_index]
            if post_test_filter_matcher(t)]
  else:
    test_cases.sort(key=lambda t: t.shortName())
    test_cases = [t for t in test_cases if post_test_filter_matcher(t)]
    test_indices = _TestIndicesForShard(
        total_shards, shard_index, len(test_cases))
    if debug_shard_distributions:
      tmp_shards = []
      for i in xrange(total_shards):
        tmp_indices = _TestIndicesForShard(
            total_shards, i, len(test_cases))
        tmp_tests = [test_cases[index] for index in tmp_indices]
        tmp_shards.append(tmp_tests)
      # Can edit the code to get 'test_times' passed in here for
      # debugging and comparison purposes.
      _DebugShardDistributions(tmp_shards, None)
    return [test_cases[index] for index in test_indices]