def writingToLoc2(self): return self.allowing(execmock.call(lambda args: args[0] == "info-of-port" and args[1] == "1", ret=["0", "file", "ssh"])).\ allowing(execmock.call(lambda args: args[0] == "info-of-port" and args[1] == "2", ret=["1", "file", "ssh"])).\ allowing(execmock.call(lambda args: args[0] == "info-of-port" and args[1] in ["3", "specials"], ret=[]))
def test_shouldRemoveEmptyLinesAndSurroundingWhitespaceFromFuzzyOutput(fixture): fixture.execs.expect(fixture.executablePath, execmock.call( ("all-fuzzy",), ret=["A ", "B", " ", " C D"])) assert fixture.functions.callFuzzy("all-fuzzy", [], {}) == ["A", "B", "C D"] fixture.execs.check()
def test_shouldSplitLinesOfExactOutputAtNullBytes(fixture): uniterableOutput = object() fixture.execs.expect(fixture.executablePath, execmock.call(("list-files",), ret=uniterableOutput, delimiter="\0")) assert fixture.functions.callExact("list-files", [], {}) is uniterableOutput fixture.execs.check()
def test_shouldCallExecutableWithOptionsInKeyValueFormat(fixture): options = {"First": "foo", "Second": "/tmp/quux"} fixture.execs.expect(fixture.executablePath, execmock.call( lambda args: args[0] == "sync" and args[1] == "arg" and set(args[2:4]) == set(["First=foo", "Second=/tmp/quux"]) and len(args) == 4)) fixture.functions.callVoid("sync", ["arg"], options) fixture.execs.check()
def _allowingOptionsCalls(self): return self.allowing( execmock.call(lambda args: args[0] == "available-options", returningNotImplementedStatus=True))
def _allowingPortCalls(self): return self.allowing( execmock.call(lambda args: args[0] == "info-of-port", returningNotImplementedStatus=True))
def _allowingCheckCall(self): return self.allowing( execmock.call(lambda args: args[0] == "check", delimiter="\0", returningNotImplementedStatus=True))
def allowing(indexString, protocols): return ret.allowing( execmock.call(lambda args: args == ("info-of-port", indexString), ret=retValue))
def allowingPortSpecialsCalls(self, output=[]): return self.allowing( execmock.call(lambda args: args[0] == "info-of-port" and args[1] == "specials", returningNotImplementedStatus=output == [], ret=output))
def withOptions(self, *options): return self.allowing( execmock.call(lambda args: args[0] == "available-options", ret=list(options)))
def expectingSync(self, matcher=lambda _: True): return self.expecting( execmock.call(lambda args: args[0] == "sync" and matcher(args)))
def expectingRestore(self, matcher=lambda _: True): return self.expecting( execmock.call(lambda args: args[0] == "restore" and matcher(args)))
def expectingListFiles(self, matcher=lambda _: True): return self.expecting( execmock.call( lambda args: args[0] == "list-files" and matcher(args), delimiter="\0"))
def syncerHavingAnyVersions(self): return self.aSyncer().allowingSetupCalls().allowing( execmock.call(lambda args: args[0] == "versions-of", ret=["0"]))
def checkExceptionTypeWithExitStatus(exceptionType, exitStatus): fixture.execs.expect(fixture.executablePath, execmock.call(partial(failWithExitStatus, exitStatus))) with pytest.raises(exceptionType): fixture.functions.callVoid("foo", [], {})
def checkOption(self, optionName, schedulings, matcher): self.execs.expect( "anacron", execmock.call( lambda args: matcher(args[1 + args.index(optionName)]))) self.schedule(schedulings)