예제 #1
0
    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"))
예제 #2
0
    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)
예제 #3
0
    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"))
예제 #4
0
파일: validatortest.py 프로젝트: pid0/sibt
 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)
예제 #5
0
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
예제 #6
0
    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) + "’"))
예제 #7
0
 def rule(**schedOpts):
     return mockRule(scheduler=sched, schedOpts=schedOpts)
예제 #8
0
 def ruleWithSched(self, scheduler, **kwargs):
     self.counter += 1
     return mockRule(name="rule-" + str(self.counter),
                     scheduler=scheduler,
                     **kwargs)
예제 #9
0
def test_shouldConsiderItUnstableIfTheRuleIsExecuting():
    detector = make()
    rule = mockRule(nextExecution=None, executing=True)
    assert detector.isInUnstablePhase(rule) is True
예제 #10
0
def test_shouldConsiderItStableIfThereIsNoNextExecution():
    detector = make()
    rule = mockRule(nextExecution=None)
    assert detector.isInUnstablePhase(rule) is False
예제 #11
0
def ruleWith(**kwargs):
    ret = mockRule(**kwargs)
    ret.scheduler, ret.synchronizer = fakeConfigurable(), fakeConfigurable()
    return ret