Example #1
0
  def testSamePageMergeNonstandardKeyFunc(self):
    page0 = self.pages[0]
    page1 = self.pages[1]

    all_values = [scalar.ScalarValue(
                      page0, 'x', 'units', 1,
                      improvement_direction=improvement_direction.UP),
                  scalar.ScalarValue(
                      page1, 'x', 'units', 4,
                      improvement_direction=improvement_direction.UP),
                  scalar.ScalarValue(
                      page0, 'y', 'units', 2,
                      improvement_direction=improvement_direction.UP),
                  scalar.ScalarValue(
                      page1, 'y', 'units', 5,
                      improvement_direction=improvement_direction.UP)]

    merged_values = merge_values.MergeLikeValuesFromSamePage(
      all_values, key_func=lambda v: v.page.name)
    # Sort the results so that their order is predictable for the subsequent
    # assertions.
    merged_values.sort(key=lambda x: x.page.url)

    self.assertEquals(2, len(merged_values))
    self.assertEquals([1, 2], merged_values[0].values)
    self.assertEquals([4, 5], merged_values[1].values)
Example #2
0
    def testSamePageMergeBasic(self):
        page0 = self.pages[0]
        page1 = self.pages[1]

        all_values = [
            scalar.ScalarValue(page0, 'x', 'units', 1),
            scalar.ScalarValue(page1, 'x', 'units', 4),
            scalar.ScalarValue(page0, 'x', 'units', 2),
            scalar.ScalarValue(page1, 'x', 'units', 5)
        ]

        merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
        # Sort the results so that their order is predictable for the subsequent
        # assertions.
        merged_values.sort(key=lambda x: x.page.url)

        self.assertEquals(2, len(merged_values))

        self.assertEquals((page0, 'x'),
                          (merged_values[0].page, merged_values[0].name))
        self.assertEquals([1, 2], merged_values[0].values)

        self.assertEquals((page1, 'x'),
                          (merged_values[1].page, merged_values[1].name))
        self.assertEquals([4, 5], merged_values[1].values)
Example #3
0
  def testSamePageMergeWithTwoInteractionRecords(self):
    page0 = self.pages[0]

    all_values = [scalar.ScalarValue(page0, 'x', 'units', 1, tir_label='foo'),
                  scalar.ScalarValue(page0, 'x', 'units', 4, tir_label='bar')]

    merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
    self.assertEquals(2, len(merged_values))
    self.assertEquals('foo', merged_values[0].tir_label)
    self.assertEquals('bar', merged_values[1].tir_label)
Example #4
0
  def testSamePageMergeOneValue(self):
    page0 = self.pages[0]

    all_values = [scalar.ScalarValue(page0, 'x', 'units', 1)]

    # Sort the results so that their order is predictable for the subsequent
    # assertions.
    merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
    self.assertEquals(1, len(merged_values))
    self.assertEquals(all_values[0].name, merged_values[0].name)
    self.assertEquals(all_values[0].units, merged_values[0].units)
 def Format(self, page_test_results):
     values = merge_values.MergeLikeValuesFromSamePage(
         page_test_results.all_page_specific_values)
     writer = csv.writer(self.output_stream)
     header_value_names = self._OutputHeader(values, writer)
     value_groups_by_page = merge_values.GroupStably(
         values, lambda value: value.page.url)
     for values_for_page in value_groups_by_page:
         self._OutputValuesForPage(header_value_names,
                                   values_for_page[0].page, values_for_page,
                                   writer)
Example #6
0
  def testSamePageMergeWithInteractionRecord(self):
    page0 = self.pages[0]

    all_values = [scalar.ScalarValue(
                      page0, 'foo-x', 'units', 1, tir_label='foo',
                      improvement_direction=improvement_direction.UP),
                  scalar.ScalarValue(
                      page0, 'foo-x', 'units', 4, tir_label='foo',
                      improvement_direction=improvement_direction.UP)]

    merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
    self.assertEquals(1, len(merged_values))
    self.assertEquals('foo', merged_values[0].tir_label)
Example #7
0
  def PrintSummary(self):
    try:
      if self._output_after_every_page:
        return

      self._OutputHeader()
      values = merge_values.MergeLikeValuesFromSamePage(
          self.all_page_specific_values)
      value_groups_by_page = merge_values.GroupStably(
          values, lambda value: value.page.url)
      for values_for_page in value_groups_by_page:
        self._OutputValuesForPage(values_for_page[0].page, values_for_page)
    finally:
      super(CsvPageMeasurementResults, self).PrintSummary()
    def testSamePageMergeWithSameGroupingKey(self):
        page0 = self.pages[0]
        all_values = [
            scalar.ScalarValue(page0,
                               'x',
                               'units',
                               1,
                               grouping_keys={'foo': 'bar'}),
            scalar.ScalarValue(page0,
                               'x',
                               'units',
                               4,
                               grouping_keys={'foo': 'bar'})
        ]

        merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
        self.assertEquals(1, len(merged_values))
        self.assertEquals({'foo': 'bar'}, merged_values[0].grouping_keys)
Example #9
0
    def testSamePageMergeWithGroupingLabel(self):
        page0 = self.pages[0]
        page0.grouping_keys['label'] = 'foo'

        all_values = [
            scalar.ScalarValue(page0,
                               'foo-x',
                               'units',
                               1,
                               improvement_direction=improvement_direction.UP),
            scalar.ScalarValue(page0,
                               'foo-x',
                               'units',
                               4,
                               improvement_direction=improvement_direction.UP)
        ]

        merged_values = merge_values.MergeLikeValuesFromSamePage(all_values)
        self.assertEquals(1, len(merged_values))
        self.assertEquals('foo', merged_values[0].grouping_label)
Example #10
0
    def _ComputePerPageValues(self, all_page_specific_values):
        all_successful_page_values = all_page_specific_values

        # We will later need to determine how many values were originally created
        # for each value name, to apply a workaround meant to clean up the printf
        # output.
        num_successful_pages_for_value_name = defaultdict(int)
        for v in all_successful_page_values:
            num_successful_pages_for_value_name[v.name] += 1

        # By here, due to page repeat options, all_values_from_successful_pages
        # contains values of the same name not only from mulitple pages, but also
        # from the same name. So even if, for instance, only one page ran, it may
        # have run twice, producing two 'x' values.
        #
        # So, get rid of the repeated pages by merging.
        merged_page_values = merge_values.MergeLikeValuesFromSamePage(
            all_successful_page_values)

        # Now we have a bunch of values, but there is only one value_name per page.
        # Suppose page1 and page2 ran, producing values x and y. We want to print
        #    x_by_url for page1
        #    x_by_url for page2
        #    x for page1, page2 combined
        #
        #    y_by_url for page1
        #    y_by_url for page2
        #    y for page1, page2 combined
        #
        # We already have the x_by_url values in the values array. But, we will need
        # them indexable by the value name.
        #
        # The following dict maps value_name -> list of pages that have values of
        # that name.
        per_page_values_by_value_name = defaultdict(list)
        for value in merged_page_values:
            per_page_values_by_value_name[value.name].append(value)

        # We already have the x_by_url values in the values array. But, we also need
        # the values merged across the pages. And, we will need them indexed by
        # value name so that we can find them when printing out value names in
        # alphabetical order.
        merged_pages_value_by_value_name = {}
        if not self.had_errors_or_failures:
            for value in merge_values.MergeLikeValuesFromDifferentPages(
                    all_successful_page_values):
                assert value.name not in merged_pages_value_by_value_name
                merged_pages_value_by_value_name[value.name] = value

        # sorted_value names will govern the order we start printing values.
        value_names = set([v.name for v in merged_page_values])
        sorted_value_names = sorted(value_names)

        # Time to walk through the values by name, printing first the by_url values
        # and then the merged_site value.
        for value_name in sorted_value_names:
            per_page_values = per_page_values_by_value_name.get(value_name, [])

            # Sort the values by their url
            sorted_per_page_values = list(per_page_values)
            sorted_per_page_values.sort(
                key=lambda per_page_values: per_page_values.page.display_name)

            # Output the _by_url results.
            num_successful_pages_for_this_value_name = (
                num_successful_pages_for_value_name[value_name])
            for per_page_value in sorted_per_page_values:
                self._ComputePerPageValue(
                    per_page_value, num_successful_pages_for_this_value_name)

            # Output the combined values.
            merged_pages_value = merged_pages_value_by_value_name.get(
                value_name, None)
            if merged_pages_value:
                self._computed_summary_values.append(merged_pages_value)
                self._interleaved_computed_per_page_values_and_summaries.append(
                    merged_pages_value)
Example #11
0
    def _ComputePerPageValues(self, all_page_specific_values):
        all_successful_page_values = [
            v for v in all_page_specific_values
            if not (isinstance(v, skip.SkipValue))
        ]

        # We will later need to determine how many values were originally created
        # for each value name, to apply a workaround meant to clean up the printf
        # output.
        num_successful_pages_for_key = defaultdict(int)
        for v in all_successful_page_values:
            num_successful_pages_for_key[self._key_func(v)] += 1

        # By here, due to page repeat options, all_values_from_successful_pages
        # contains values of the same name not only from mulitple pages, but also
        # from the same name. So even if, for instance, only one page ran, it may
        # have run twice, producing two 'x' values.
        #
        # So, get rid of the repeated pages by merging.
        merged_page_values = merge_values.MergeLikeValuesFromSamePage(
            all_successful_page_values, self._key_func)

        # Now we have a bunch of values, but there is only one value_name per page.
        # Suppose page1 and page2 ran, producing values x and y. We want to print
        #    x for page1
        #    x for page2
        #    x for page1, page2 combined
        #
        #    y for page1
        #    y for page2
        #    y for page1, page2 combined
        #
        # We already have the x values in the values array. But, we will need
        # them indexable by summary key.
        #
        # The following dict maps summary_key -> list of pages that have values of
        # that name.
        per_page_values_by_key = defaultdict(list)
        for value in merged_page_values:
            per_page_values_by_key[self._key_func(value)].append(value)

        # We already have the x values in the values array. But, we also need
        # the values merged across the pages. And, we will need them indexed by
        # summary key so that we can find them when printing out value names in
        # alphabetical order.
        merged_pages_value_by_key = {}
        if not self._had_failures:
            for value in merge_values.MergeLikeValuesFromDifferentPages(
                    merged_page_values, self._key_func):
                value_key = self._key_func(value)
                assert value_key not in merged_pages_value_by_key
                merged_pages_value_by_key[value_key] = value

        keys = sorted(set([self._key_func(v) for v in merged_page_values]))

        # Time to walk through the values by key, printing first the page-specific
        # values and then the merged_site value.
        for key in keys:
            per_page_values = per_page_values_by_key.get(key, [])

            # Sort the values by their URL.
            sorted_per_page_values = list(per_page_values)
            sorted_per_page_values.sort(
                key=lambda per_page_values: per_page_values.page.name)

            # Output the page-specific results.
            num_successful_pages_for_this_key = (
                num_successful_pages_for_key[key])
            for per_page_value in sorted_per_page_values:
                self._ComputePerPageValue(per_page_value,
                                          num_successful_pages_for_this_key)

            # Output the combined values.
            merged_pages_value = merged_pages_value_by_key.get(key, None)
            if merged_pages_value:
                self._computed_summary_values.append(merged_pages_value)
                self._interleaved_computed_per_page_values_and_summaries.append(
                    merged_pages_value)