Ticket #57: testflags.patch
| File testflags.patch, 3.8 KB (added by dustin, 5 years ago) |
|---|
-
buildbot/test/runutils.py
Patch to add 'flags' that can be set in BuildSteps and tested for in the test harness. These are useful in determining which steps have and have not run.
old new 413 413 def filterArgs(self, args): 414 414 # this can be overridden 415 415 return args 416 417 # ---------------------------------------- 418 419 _flags = {} 420 421 def setTestFlag(flagname, value): 422 _flags[flagname] = value 423 424 class SetTestFlagStep(BuildStep): 425 """ 426 A special BuildStep to set a named flag; this can be used with the 427 TestFlagMixin to monitor what has and has not run in a particular 428 configuration. 429 """ 430 def __init__(self, flagname='flag', value=1, **kwargs): 431 BuildStep.__init__(self, **kwargs) 432 self.flagname = flagname 433 self.value = value 434 435 def start(self): 436 _flags[self.flagname] = self.value 437 self.finished(builder.SUCCESS) 438 439 class TestFlagMixin: 440 def clearFlags(self): 441 """ 442 Set up for a test by clearing all flags; call this from your test 443 function. 444 """ 445 _flags.clear() 446 447 def failIfFlagSet(self, flagname, msg=None): 448 if not msg: msg = "flag '%s' is set" % flagname 449 self.failIf(_flags.has_key(flagname), msg=msg) 450 451 def failIfFlagNotSet(self, flagname, msg=None): 452 if not msg: msg = "flag '%s' is not set" % flagname 453 self.failUnless(_flags.has_key(flagname), msg=msg) 454 455 def getFlag(self, flagname): 456 self.failIfFlagNotSet(flagname, "flag '%s' not set" % flagname) 457 return _flags.get(flagname) -
buildbot/test/test_run.py
old new 10 10 from buildbot.status import builder 11 11 from buildbot.process.base import BuildRequest 12 12 13 from buildbot.test.runutils import RunMixin, rmtree13 from buildbot.test.runutils import RunMixin, TestFlagMixin, rmtree 14 14 15 15 config_base = """ 16 16 from buildbot.process import factory … … 506 506 d = self.master.loadConfig(config_4_newbuilder) 507 507 return d 508 508 509 config_test_flag = config_base + """ 510 from buildbot.scheduler import Scheduler 511 c['schedulers'] = [Scheduler('quick', None, 0.1, ['dummy'])] 512 513 from buildbot.test.runutils import SetTestFlagStep 514 f3 = factory.BuildFactory([ 515 s(SetTestFlagStep, flagname='foo', value='bar'), 516 ]) 517 518 c['builders'] = [{'name': 'dummy', 'slavename': 'bot1', 519 'builddir': 'dummy', 'factory': f3}] 520 """ 521 522 class TestFlag(RunMixin, TestFlagMixin, unittest.TestCase): 523 """Test for the TestFlag functionality in runutils""" 524 def testTestFlag(self): 525 m = self.master 526 m.loadConfig(config_test_flag) 527 m.readConfig = True 528 m.startService() 529 530 c = changes.Change("bob", ["Makefile", "foo/bar.c"], "changed stuff") 531 m.change_svc.addChange(c) 532 533 d = self.connectSlave() 534 d.addCallback(self._testTestFlag_1) 535 return d 536 537 def _testTestFlag_1(self, res): 538 d = defer.Deferred() 539 reactor.callLater(0.5, d.callback, None) 540 d.addCallback(self._testTestFlag_2) 541 return d 542 543 def _testTestFlag_2(self, res): 544 self.failUnlessEqual(self.getFlag('foo'), 'bar') 545 509 546 # TODO: test everything, from Change submission to Scheduler to Build to 510 547 # Status. Use all the status types. Specifically I want to catch recurrences 511 548 # of the bug where I forgot to make Waterfall inherit from StatusReceiver
![[Buildbot Logo]](/chrome/site/header-text-transparent.png)