def testCreateReportLink(self): class StepMock(mock.Mock): def __init__(self, urltype, reportlink): mock.Mock.__init__(self) self._urltype = urltype self._reportlink = reportlink self._addURLCalled = 0 def addURL(self, urltype, link): self._addURLCalled += 1 if self._addURLCalled > 1: raise Exception('getLogs called more than once') if urltype != self._urltype: raise Exception('url_type should be \'%s\'' % self._urltype) if link != self._reportlink: raise Exception('link should have been \'%s\'' % self._reportlink) log_processor_class = chromium_utils.InitializePartiallyWithArguments( process_log.BenchpressLogProcessor, report_link=self._report_link, output_dir=self._output_dir) step = chromium_step.ProcessLogShellStep(log_processor_class) build_mock = mock.Mock() source_mock = mock.Mock() change_mock = mock.Mock() change_mock.revision = self._revision source_mock.changes = [change_mock] build_mock.source = source_mock step_status = StepMock('results', log_processor_class().ReportLink()) step.build = build_mock step.step_status = step_status step._CreateReportLinkIfNeccessary() build_mock.verify()
def _ConstructStep(self, log_processor_class, logfile, factory_properties=None, perf_expectations_path=None): """ Common approach to construct chromium_step.ProcessLogTestStep type instance with LogFile instance set. Args: log_processor_class: type/class of type chromium_step.ProcessLogTestStep that is going to be constructed. E.g. PagecyclerTestStep logfile: filename with setup process log output. """ factory_properties = factory_properties or {} self._log_processor_class = chromium_utils.InitializePartiallyWithArguments( log_processor_class, factory_properties=factory_properties, report_link=self._report_link, output_dir=self._output_dir, perf_name='test-system', test_name='test-name', perf_filename=perf_expectations_path) step = chromium_step.ProcessLogShellStep(self._log_processor_class) log_file = self._LogFile( 'stdio', open(os.path.join(test_env.DATA_PATH, logfile)).read()) self._SetupBuild(step, self._revision, self._webkit_revision, log_file) return step
def CreatePerformanceStepClass(log_processor_class, report_link=None, output_dir=None, factory_properties=None, perf_name=None, test_name=None, command_class=None): """Returns ProcessLogShellStep class. Args: log_processor_class: class that will be used to process logs. Normally should be a subclass of process_log.PerformanceLogProcessor. report_link: URL that will be used as a link to results. If None, result won't be written into file. output_dir: directory where the log processor will write the results. command_class: command type to run for this step. Normally this will be chromium_step.ProcessLogShellStep. """ factory_properties = factory_properties or {} command_class = command_class or chromium_step.ProcessLogShellStep # We create a log-processor class using # chromium_utils.InitializePartiallyWithArguments, which uses function # currying to create classes that have preset constructor arguments. # This serves two purposes: # 1. Allows the step to instantiate its log processor without any # additional parameters; # 2. Creates a unique log processor class for each individual step, so # they can keep state that won't be shared between builds log_processor_class = chromium_utils.InitializePartiallyWithArguments( log_processor_class, report_link=report_link, output_dir=output_dir, factory_properties=factory_properties, perf_name=perf_name, test_name=test_name) # Similarly, we need to allow buildbot to create the step itself without # using additional parameters, so we create a step class that already # knows which log_processor to use. return chromium_utils.InitializePartiallyWithArguments( command_class, log_processor_class=log_processor_class)
def testConstructorCurring(self): class PartiallyConstructable(object): def __init__(self, arg1, named_arg1=None, named_arg2=None): self.arg1 = arg1 self.named_arg1 = named_arg1 self.named_arg2 = named_arg2 partial_class = chromium_utils.InitializePartiallyWithArguments( PartiallyConstructable, 'argument 1 value', named_arg1='named argument 1 value') complete_class = partial_class(named_arg2='named argument 2 value') self.assertEqual('argument 1 value', complete_class.arg1) self.assertEqual('named argument 2 value', complete_class.named_arg2)