def setupBuildSteps(self, step_factories): steps = [] for factory in step_factories: step = buildstep.create_step_from_step_or_factory(factory) step.setBuild(self) step.setWorker(self.workerforbuilder.worker) steps.append(step) if self.useProgress: step.setupProgress() return steps
def setup_step(self, step, worker_version=None, worker_env=None, build_files=None, want_default_work_dir=True): self.step = buildstep.create_step_from_step_or_factory(step) # set defaults if want_default_work_dir: self.step.workdir = self.step._workdir or 'wkdir' self.build = self._setup_fake_build(worker_version, worker_env, build_files) self.step.setBuild(self.build) # watch for properties being set self.properties = self.build.getProperties() # step.progress self.step.progress = mock.Mock(name="progress") # step.worker self.worker = self.step.worker = worker.FakeWorker(self.master) self.worker.attached(None) # step overrides def addLog(name, type='s', logEncoding=None): _log = logfile.FakeLogFile(name) self.step.logs[name] = _log self.step._connectPendingLogObservers() return defer.succeed(_log) self.step.addLog = addLog def addHTMLLog(name, html): _log = logfile.FakeLogFile(name) html = bytes2unicode(html) _log.addStdout(html) return defer.succeed(None) self.step.addHTMLLog = addHTMLLog def addCompleteLog(name, text): _log = logfile.FakeLogFile(name) if name in self.step.logs: raise Exception(f'Attempt to add log {name} twice to the logs') self.step.logs[name] = _log _log.addStdout(text) return defer.succeed(None) self.step.addCompleteLog = addCompleteLog self._got_test_result_sets = [] self._next_test_result_set_id = 1000 def add_test_result_set(description, category, value_unit): self._got_test_result_sets.append( (description, category, value_unit)) setid = self._next_test_result_set_id self._next_test_result_set_id += 1 return defer.succeed(setid) self.step.addTestResultSet = add_test_result_set self._got_test_results = [] def add_test_result(setid, value, test_name=None, test_code_path=None, line=None, duration_ns=None): self._got_test_results.append( (setid, value, test_name, test_code_path, line, duration_ns)) self.step.addTestResult = add_test_result self._got_build_data = {} def set_build_data(name, value, source): self._got_build_data[name] = (value, source) return defer.succeed(None) self.step.setBuildData = set_build_data # expectations self.exp_result = None self.exp_state_string = None self.exp_properties = {} self.exp_missing_properties = [] self.exp_logfiles = {} self._exp_logfiles_stderr = {} self.exp_hidden = False self.exp_exception = None self._exp_test_result_sets = [] self._exp_test_results = [] self._exp_build_data = {} # check that the step's name is not None self.assertNotEqual(self.step.name, None) return self.step
def setupStep(self, step, worker_version=None, worker_env=None, buildFiles=None, wantDefaultWorkdir=True): """ Set up C{step} for testing. This begins by using C{step} as a factory to create a I{new} step instance, thereby testing that the factory arguments are handled correctly. It then creates a comfortable environment for the worker to run in, replete with a fake build and a fake worker. As a convenience, it can set the step's workdir with C{'wkdir'}. @param worker_version: worker version to present, as a dictionary mapping command name to version. A command name of '*' will apply for all commands. @param worker_env: environment from the worker at worker startup """ if worker_version is None: worker_version = {'*': '99.99'} if worker_env is None: worker_env = dict() if buildFiles is None: buildFiles = list() step = self.step = buildstep.create_step_from_step_or_factory(step) # set defaults if wantDefaultWorkdir: step.workdir = step._workdir or 'wkdir' # step.build b = self.build = fakebuild.FakeBuild(master=self.master) b.allFiles = lambda: buildFiles b.master = self.master def getWorkerVersion(cmd, oldversion): if cmd in worker_version: return worker_version[cmd] if '*' in worker_version: return worker_version['*'] return oldversion b.getWorkerCommandVersion = getWorkerVersion b.workerEnvironment = worker_env.copy() step.setBuild(b) self.build.builder.config.env = worker_env.copy() # watch for properties being set self.properties = b.getProperties() # step.progress step.progress = mock.Mock(name="progress") # step.worker self.worker = step.worker = worker.FakeWorker(self.master) self.worker.attached(None) # step overrides def addLog(name, type='s', logEncoding=None): _log = logfile.FakeLogFile(name) self.step.logs[name] = _log self.step._connectPendingLogObservers() return defer.succeed(_log) step.addLog = addLog def addHTMLLog(name, html): _log = logfile.FakeLogFile(name) html = bytes2unicode(html) _log.addStdout(html) return defer.succeed(None) step.addHTMLLog = addHTMLLog def addCompleteLog(name, text): _log = logfile.FakeLogFile(name) if name in self.step.logs: raise Exception( 'Attempt to add log {} twice to the logs'.format(name)) self.step.logs[name] = _log _log.addStdout(text) return defer.succeed(None) step.addCompleteLog = addCompleteLog self._got_test_result_sets = [] self._next_test_result_set_id = 1000 def add_test_result_set(description, category, value_unit): self._got_test_result_sets.append( (description, category, value_unit)) setid = self._next_test_result_set_id self._next_test_result_set_id += 1 return defer.succeed(setid) step.addTestResultSet = add_test_result_set self._got_test_results = [] def add_test_result(setid, value, test_name=None, test_code_path=None, line=None, duration_ns=None): self._got_test_results.append( (setid, value, test_name, test_code_path, line, duration_ns)) step.addTestResult = add_test_result self._got_build_data = {} def set_build_data(name, value, source): self._got_build_data[name] = (value, source) return defer.succeed(None) step.setBuildData = set_build_data # expectations self.exp_result = None self.exp_state_string = None self.exp_properties = {} self.exp_missing_properties = [] self.exp_logfiles = {} self._exp_logfiles_stderr = {} self.exp_hidden = False self.exp_exception = None self._exp_test_result_sets = [] self._exp_test_results = [] self._exp_build_data = {} # check that the step's name is not None self.assertNotEqual(step.name, None) return step
def setup_step(self, step, worker_version=None, worker_env=None, build_files=None, want_default_work_dir=True): if worker_version is None: worker_version = { '*': '99.99' } if worker_env is None: worker_env = dict() if build_files is None: build_files = list() step = self.step = buildstep.create_step_from_step_or_factory(step) # set defaults if want_default_work_dir: step.workdir = step._workdir or 'wkdir' # step.build b = self.build = fakebuild.FakeBuild(master=self.master) b.allFiles = lambda: build_files b.master = self.master def getWorkerVersion(cmd, oldversion): if cmd in worker_version: return worker_version[cmd] if '*' in worker_version: return worker_version['*'] return oldversion b.getWorkerCommandVersion = getWorkerVersion b.workerEnvironment = worker_env.copy() step.setBuild(b) self.build.builder.config.env = worker_env.copy() # watch for properties being set self.properties = b.getProperties() # step.progress step.progress = mock.Mock(name="progress") # step.worker self.worker = step.worker = worker.FakeWorker(self.master) self.worker.attached(None) # step overrides def addLog(name, type='s', logEncoding=None): _log = logfile.FakeLogFile(name) self.step.logs[name] = _log self.step._connectPendingLogObservers() return defer.succeed(_log) step.addLog = addLog def addHTMLLog(name, html): _log = logfile.FakeLogFile(name) html = bytes2unicode(html) _log.addStdout(html) return defer.succeed(None) step.addHTMLLog = addHTMLLog def addCompleteLog(name, text): _log = logfile.FakeLogFile(name) if name in self.step.logs: raise Exception('Attempt to add log {} twice to the logs'.format(name)) self.step.logs[name] = _log _log.addStdout(text) return defer.succeed(None) step.addCompleteLog = addCompleteLog self._got_test_result_sets = [] self._next_test_result_set_id = 1000 def add_test_result_set(description, category, value_unit): self._got_test_result_sets.append((description, category, value_unit)) setid = self._next_test_result_set_id self._next_test_result_set_id += 1 return defer.succeed(setid) step.addTestResultSet = add_test_result_set self._got_test_results = [] def add_test_result(setid, value, test_name=None, test_code_path=None, line=None, duration_ns=None): self._got_test_results.append((setid, value, test_name, test_code_path, line, duration_ns)) step.addTestResult = add_test_result self._got_build_data = {} def set_build_data(name, value, source): self._got_build_data[name] = (value, source) return defer.succeed(None) step.setBuildData = set_build_data # expectations self.exp_result = None self.exp_state_string = None self.exp_properties = {} self.exp_missing_properties = [] self.exp_logfiles = {} self._exp_logfiles_stderr = {} self.exp_hidden = False self.exp_exception = None self._exp_test_result_sets = [] self._exp_test_results = [] self._exp_build_data = {} # check that the step's name is not None self.assertNotEqual(step.name, None) return step