def _GetAllPossiblePageTestInstances():
  page_test_instances = []
  measurements_dir = os.path.dirname(__file__)
  top_level_dir = os.path.dirname(measurements_dir)
  benchmarks_dir = os.path.join(top_level_dir, 'benchmarks')

  # Get all page test instances from measurement classes that are directly
  # constructable
  all_measurement_classes = discover.DiscoverClasses(
      measurements_dir, top_level_dir, page_test.PageTest).values()
  for measurement_class in all_measurement_classes:
    if classes.IsDirectlyConstructable(measurement_class):
      page_test_instances.append(measurement_class())

  all_benchmarks_classes = discover.DiscoverClasses(
      benchmarks_dir, top_level_dir, benchmark_module.Benchmark).values()

  # Get all page test instances from defined benchmarks.
  # Note: since this depends on the command line options, there is no guaranteed
  # that this will generate all possible page test instances but it's worth
  # enough for smoke test purpose.
  for benchmark_class in all_benchmarks_classes:
    options = options_for_unittests.GetCopy()
    parser = options.CreateParser()
    benchmark_class.AddCommandLineArgs(parser)
    benchmark_module.AddCommandLineArgs(parser)
    benchmark_class.SetArgumentDefaults(parser)
    options.MergeDefaultValues(parser.get_default_values())
    pt = benchmark_class().CreatePageTest(options)
    if not isinstance(pt, timeline_based_measurement.TimelineBasedMeasurement):
      page_test_instances.append(pt)

  return page_test_instances
Beispiel #2
0
    def RunSmokeTest(self, page_sets_dir, top_level_dir):
        """Run smoke test on all page sets in page_sets_dir.

    Subclass of PageSetSmokeTest is supposed to call this in some test
    method to run smoke test.
    """
        page_sets = discover.DiscoverClasses(page_sets_dir, top_level_dir,
                                             page_set_module.PageSet).values()
        for page_set_class in page_sets:
            if not classes.IsDirectlyConstructable(page_set_class):
                # We can't test page sets that aren't directly constructable since we
                # don't know what arguments to put for the constructor.
                continue
            page_set = page_set_class()
            logging.info('Testing %s', page_set.file_path)
            self.CheckArchive(page_set)
            self.CheckCredentials(page_set)
            self.CheckAttributes(page_set)
            self.CheckSharedStates(page_set)
 def testIsDirectlyConstructableReturnsFalse(self):
   self.assertFalse(
       classes.IsDirectlyConstructable(
           ClassWhoseInitWithDefaultArgumentsAndNonDefaultArguments))
 def testIsDirectlyConstructableReturnsTrue(self):
   self.assertTrue(classes.IsDirectlyConstructable(ClassWithoutInitDefOne))
   self.assertTrue(classes.IsDirectlyConstructable(ClassWithoutInitDefTwo))
   self.assertTrue(classes.IsDirectlyConstructable(ClassWhoseInitOnlyHasSelf))
   self.assertTrue(
       classes.IsDirectlyConstructable(ClassWhoseInitWithDefaultArguments))