Example #1
0
  def __init__(self, *phases, **metadata):
    # Some sanity checks on special metadata keys we automatically fill in.
    if 'config' in metadata:
      raise KeyError(
          'Invalid metadata key "config", it will be automatically populated.')

    self.created_time_millis = util.time_millis()
    self.last_run_time_millis = None
    code_info = test_record.CodeInfo.for_module_from_stack(levels_up=2)
    self._test_desc = TestDescriptor(self.uid, phases, code_info, metadata)
    self._test_options = TestOptions()
    self._lock = threading.Lock()
    self._executor = None

    # Make sure configure() gets called at least once before Execute().  The
    # user might call configure() again to override options, but we don't want
    # to force them to if they want to use defaults.  For default values, see
    # the class definition of TestOptions.
    if 'test_name' in metadata:
      # Allow legacy metadata key for specifying test name.
      self.configure(name=metadata['test_name'])
    else:
      self.configure()

    self.TEST_INSTANCES[self.uid] = self
    # This is a noop if the server is already running, otherwise start it now
    # that we have at least one Test instance.
    station_api.start_server()
Example #2
0
    def __init__(self, *phases, **metadata):
        # Some sanity checks on special metadata keys we automatically fill in.
        if 'config' in metadata:
            raise KeyError(
                'Invalid metadata key "config", it will be automatically populated.'
            )

        self.created_time_millis = util.time_millis()
        self.last_run_time_millis = None
        self._test_options = TestOptions()
        self._lock = threading.Lock()
        self._executor = None
        self._test_desc = TestDescriptor(phases,
                                         test_record.CodeInfo.uncaptured(),
                                         metadata)

        if conf.capture_source:
            # First, we copy the phases with the real CodeInfo for them.
            phases = [
                mutablerecords.CopyRecord(
                    phase,
                    code_info=test_record.CodeInfo.for_function(phase.func))
                for phase in self._test_desc.phases
            ]

            # Then we replace the TestDescriptor with one that stores the test
            # module's CodeInfo as well as our newly copied phases.
            code_info = test_record.CodeInfo.for_module_from_stack(levels_up=2)
            self._test_desc = self._test_desc._replace(code_info=code_info,
                                                       phases=phases)

        # Make sure configure() gets called at least once before Execute().  The
        # user might call configure() again to override options, but we don't want
        # to force them to if they want to use defaults.  For default values, see
        # the class definition of TestOptions.
        if 'test_name' in metadata:
            # Allow legacy metadata key for specifying test name.
            self.configure(name=metadata['test_name'])
        else:
            self.configure()

        # This is a noop if the server is already running, otherwise start it now
        # that we have at least one Test instance.
        station_api.start_server()
Example #3
0
  def __init__(self, *phases, **metadata):
    # Some sanity checks on special metadata keys we automatically fill in.
    if 'config' in metadata:
      raise KeyError(
          'Invalid metadata key "config", it will be automatically populated.')

    self.created_time_millis = util.time_millis()
    self.last_run_time_millis = None
    self._test_options = TestOptions()
    self._lock = threading.Lock()
    self._executor = None
    self._test_desc = TestDescriptor(
        self.uid, phases, test_record.CodeInfo.uncaptured(), metadata)

    if conf.capture_source:
      # First, we copy the phases with the real CodeInfo for them.
      phases = [
        mutablerecords.CopyRecord(
            phase, code_info=test_record.CodeInfo.for_function(phase.func))
        for phase in self._test_desc.phases]

      # Then we replace the TestDescriptor with one that stores the test
      # module's CodeInfo as well as our newly copied phases.
      code_info = test_record.CodeInfo.for_module_from_stack(levels_up=2)
      self._test_desc = self._test_desc._replace(
          code_info=code_info, phases=phases)

    # Make sure configure() gets called at least once before Execute().  The
    # user might call configure() again to override options, but we don't want
    # to force them to if they want to use defaults.  For default values, see
    # the class definition of TestOptions.
    if 'test_name' in metadata:
      # Allow legacy metadata key for specifying test name.
      self.configure(name=metadata['test_name'])
    else:
      self.configure()

    self.TEST_INSTANCES[self.uid] = self
    # This is a noop if the server is already running, otherwise start it now
    # that we have at least one Test instance.
    station_api.start_server()