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_shouldFindSyntaxErrorsInItsOptions(self, fixture): assert fixture.check( dict(AdditionalSyncOpts="--exclude '**/.*'")) == [] iterToTest( fixture.check( dict(AdditionalSyncOpts="--exclude '", RemoteShellCommand="("))).shouldContainMatchingInAnyOrder( stringThat.shouldInclude("AdditionalSyncOpts", "unexpected"), stringThat.shouldInclude("RemoteShellCommand", "unexpected"))
def test_shouldFindSyntaxErrorsInTheExcludedDirsOption(self, fixture): assert fixture.check(dict(ExcludedDirs="'/foo bar'")) == [] iterToTest(fixture.check(dict(ExcludedDirs="/foo'b"))).\ shouldContainMatching(stringThat.shouldInclude( "unexpected", "ExcludedDirs")) iterToTest(fixture.check(dict(ExcludedDirs="relative/foo/bar"))).\ shouldContainMatching(stringThat.shouldInclude("ExcludedDirs", "relative/foo/bar", "absolute")) iterToTest(fixture.check(dict(ExcludedDirs="'/foo' ''"))).\ shouldContainMatching(stringThat.shouldInclude( "absolute", "ExcludedDirs"))
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_shouldBeAbleToDryTestTheRsyncCommandThatWouldBeUsedToSync( self, fixture): assert "DryRun" in fixture.optionNames iterToTest(fixture.check(dict(DryRun=True, AdditionalSyncOpts="--bar"))).\ shouldContainMatching(stringThat.shouldInclude("unknown option", "bar")) (fixture.loc1 / "file").write("") assert fixture.check({}) == [] assert not os.path.isfile(str(fixture.loc2 / "file")) fixture.loc1.chmod(0o300) iterToTest(fixture.check(dict(DryRun=True))).shouldContainMatching( stringThat.shouldInclude("Permission denied")) assert fixture.check(dict(DryRun=False)) == []
def test_shouldFindSyntaxErrorsInItsOptions(self, fixture): assert fixture.check( dict(AdditionalSyncOpts="--one-file-system", ExcludedDirs="/foo")) == [] iterToTest( fixture.check( dict(AdditionalSyncOpts="'", AdditionalOptsBothWays="'", RemoteShellCommand="("))).shouldContainMatchingInAnyOrder( stringThat.shouldInclude("unexpected", "AdditionalOptsBothWays"), stringThat.shouldInclude("unexpected", "AdditionalSyncOpts"), stringThat.shouldInclude("unexpected", "RemoteShellCommand"))
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) + "’"))