def test_shouldReturnEachSyncerCheckErrorWithAnAppropriatePrefix( self, fix): rule1 = mockRule("first", syncerName="syncer1", syncerCheckErrors=["Wrong option syntax"]) rule2 = mockRule( "second", syncerName="syncer2", syncerCheckErrors=["Contradictory values", "Unreadable File"]) iterToTest(self.construct().validate(ruleSet(rule1, rule2))).\ shouldContainMatchingInAnyOrder( stringThat.shouldInclude("syntax", "first", "syncer1"), stringThat.shouldInclude("Contradictory", "second", "syncer2"), stringThat.shouldInclude("Unreadable", "second", "syncer2"))
def test_shouldReturnTheErrorsOfTheFirstSchedulerThatHasSome(self, fix): sched = mockSched(sharedOptions=[optInfo("UseVarDir")]) rule1, rule2 = mockRule(scheduler=sched, schedOpts=dict(UseVarDir=True)), \ mockRule(scheduler=sched, schedOpts=dict(UseVarDir=False)) def visitSchedulers(visitFunc): assert visitFunc(sched, [rule1]) == None ret = visitFunc(sched, [rule1, rule2]) assert len(ret) == 1 return ret ruleSet = lambda x: x ruleSet.visitSchedulers = visitSchedulers validator = self.construct() validator.validate(ruleSet)
def test_shouldTurnEachCheckErrorFromTheUsedSchedulersIntoAString( self, fix): sched1, sched2 = mockSched("first"), mockSched("second") rule1, rule2 = mockRule(scheduler=sched1), mockRule(scheduler=sched2) validator = self.construct() sched1.expectCalls( schedCallWithRules("check", rule1, ret=["foo", "bar"])) sched2.expectCalls(schedCallWithRules("check", rule2, ret=["quux"])) iterToTest(validator.validate(ruleSet(rule1, rule2))).\ shouldContainMatchingInAnyOrder( stringThat.shouldInclude("first", "reported error", "foo"), stringThat.shouldInclude("first", "bar"), stringThat.shouldInclude("second", "quux"))
def mockRule(self, loc1, loc2, name=None, **kwargs): sched = mockSched() sched.check = lambda *args: [] self.nameCounter += 1 return mockRule(loc1=loc1, loc2=loc2, name=name or "rule-" + str(self.nameCounter), scheduler=sched, **kwargs)
def test_shouldDetectClosenessAlsoIfTheNextExecutionIsInThePast(): minimum = timedelta(minutes=45) nextTime = datetime(2004, 1, 1, 0, 0, 0, 0, timezone.utc) tooClose = datetime(2004, 1, 1, 0, 44, 59, 0, timezone.utc) nextIsLongAgoNow = datetime(2004, 1, 1, 0, 46, 0, 0, timezone.utc) rule = mockRule(nextExecution=execution(startTime=nextTime)) assert make(minimum=minimum, currentTime=tooClose).isInUnstablePhase(rule) is True assert make(minimum=minimum, currentTime=nextIsLongAgoNow).isInUnstablePhase(rule) is False
def test_shouldPrintTheActualMountPointIfTheAssertionTurnsOutFalse( self, fix): mountPoint = fix.tmpdir.mkdir("mount") with nonEmptyFSMountedAt(mountPoint): loc1 = mountPoint.mkdir("sub").mkdir("loc1") rule = mockRule(loc1=str(loc1), options=dict(MustBeMountPoint="1")) errors = self.construct().validate(ruleSet(rule)) iterToTest(errors).shouldContainMatching( stringThat.shouldInclude("actual", str(mountPoint) + "’"))
def rule(**schedOpts): return mockRule(scheduler=sched, schedOpts=schedOpts)
def ruleWithSched(self, scheduler, **kwargs): self.counter += 1 return mockRule(name="rule-" + str(self.counter), scheduler=scheduler, **kwargs)
def test_shouldConsiderItUnstableIfTheRuleIsExecuting(): detector = make() rule = mockRule(nextExecution=None, executing=True) assert detector.isInUnstablePhase(rule) is True
def test_shouldConsiderItStableIfThereIsNoNextExecution(): detector = make() rule = mockRule(nextExecution=None) assert detector.isInUnstablePhase(rule) is False
def ruleWith(**kwargs): ret = mockRule(**kwargs) ret.scheduler, ret.synchronizer = fakeConfigurable(), fakeConfigurable() return ret