def test_shouldCheckIfAllSharedOptionValuesOfAllRulesOfASchedulerAreEqual( self, fix): schedName = "sched-with-shared-opts" sched = mockSched(schedName, sharedOptions=[ optInfo("ConfDir"), optInfo("DestFile"), optInfo("Version") ]) def rule(**schedOpts): return mockRule(scheduler=sched, schedOpts=schedOpts) rules = [ rule(Version="1", ConfDir="/home", DestFile="/etc/foo"), rule(Version="1", ConfDir="/etc", DestFile="/etc/foo"), rule(Version="1", ConfDir="/usr/share") ] validator = self.construct() iterToTest(validator.validate(ruleSet(*rules))).\ shouldContainMatchingInAnyOrder( stringThat.shouldInclude("ConfDir", "/home", "/etc", "/usr/share"), stringThat.shouldInclude("DestFile", "‘/etc/foo’", "‘’"))
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 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 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_validatorShouldReturnNoErrorsIfTheRulesAreOk(self, fix): validator = self.construct() assert validator.validate(ruleSet(fix.validRule(), fix.validRule())) == []
def test_shouldReturnAnErrorIfLoc1EqualsLoc2(self, fix): validator = self.construct() locDir = fix.validLocDir() assert len(validator.validate(ruleSet( fix.mockRule(locDir, locDir)))) > 0