Ejemplo n.º 1
0
    def test_shouldTakeCustomOptionsForSyncingAndForSyncingAndRestoring(
            self, fixture):
        assert "AdditionalSyncOpts" in fixture.optionNames
        assert "AdditionalOptsBothWays" in fixture.optionNames

        options = dict(AdditionalSyncOpts="$(echo --update)",
                       AdditionalOptsBothWays="--exclude '*.o'")

        codeFile, binFile = writeFileTree(
            fixture.loc1, [".", ["src", "main.c [1]", "main.o [2]"]])
        fixture.changeMTime(codeFile, 20)
        codeFileBackup = fixture.loc2 / "src" / "main.c"
        binFileInBackup = fixture.loc2 / "src" / "main.o"

        fixture.sync(options)
        codeFileBackup.ensure(file=True)
        assert not os.path.isfile(str(binFileInBackup))
        codeFileBackup.write("//foo")
        fixture.changeMTime(codeFileBackup, 40)
        fixture.sync(options)
        binFileInBackup.write("ELF")

        codeFile.write("//bar")
        fixture.changeMTime(codeFileBackup, 60)
        fixture.restorePort1File(".", anyUTCDateTime(), None, options)
        assert codeFile.read() == "//foo"
        assert binFile.read() == ""
Ejemplo n.º 2
0
def test_shouldEncodeLocationsAsMultipleOptions(fixture):
    fixture.functions.expectCalls(
        mock.callMatching(
            "callVoid", lambda _, args, options: dictIncludes(
                options, {
                    "SomePlaceProtocol": "ftp",
                    "SomePlaceLogin": "******",
                    "SomePlaceHost": "mansion",
                    "SomePlacePort": "10",
                    "SomePlacePath": "/blah/quux",
                    "LocalProtocol": "file",
                    "LocalPath": "/foo",
                    "RestoreLogin": "",
                    "RestoreHost": "blah",
                    "RestorePath": "/foo"
                })))

    options = {
        "SomePlace":
        remoteLocation(protocol="ftp",
                       login="******",
                       host="mansion",
                       port="10",
                       path="/blah/quux"),
        "Local":
        localLocation("/foo")
    }

    fixture.syncer.restore(options, "file", 2, anyUTCDateTime(),
                           remoteLocation("http", host="blah", path="/foo"))

    fixture.functions.checkExpectedCalls()
Ejemplo n.º 3
0
def test_shouldConvertArgumentsAndOptionsToStringsDependingOnTheirType(
        fixture):
    enum = types.Enum("A", "B")
    options = {
        "SomePlace": location("/home//foo/"),
        "Loc1": location("/tmp"),
        "Yes": True,
        "No": False,
        "Number": 934,
        "Interval": timedelta(minutes=2, seconds=3.5),
        "Choice": enum.A
    }

    fixture.functions.expectCalls(
        mock.callMatching(
            "callVoid", lambda _, args, receivedOptions: args[
                3] == "/media/foo" and receivedOptions[
                    "SomePlace"] == "/home/foo" and receivedOptions["Loc1"] ==
            "/tmp" and receivedOptions["Yes"] == "1" and receivedOptions["No"]
            == "0" and receivedOptions["Number"] == "934" and receivedOptions[
                "Interval"] == "123" and receivedOptions["Choice"] == "A"))

    fixture.syncer.restore(options, "foo", 1, anyUTCDateTime(),
                           location("/media/foo/"))

    fixture.functions.checkExpectedCalls()
Ejemplo n.º 4
0
 def test_shouldThrowExceptionForNonTrivialNotImplementedFunctions(
         self, fixture):
     syncer = self.loadSynchronizerWithCode("", fixture)
     with pytest.raises(SynchronizerFuncNotImplementedException):
         syncer.listFiles(mkSyncerOpts(), lambda *_: None, "/tmp/file", 1,
                          anyUTCDateTime(), False)
     with pytest.raises(SynchronizerFuncNotImplementedException):
         syncer.sync(mkSyncerOpts())
Ejemplo n.º 5
0
def test_shouldCycleThroughAListOfPresetTimes():
    firstTime = datetime.now(timezone.utc)
    secondTime = anyUTCDateTime()

    clock = PresetCyclingClock(firstTime)
    clock.dateTimes = clock.dateTimes + [secondTime]

    assert [clock.now(), clock.now(), clock.now(), clock.now(), clock.now()] == \
        [firstTime, secondTime, firstTime, secondTime, firstTime]
Ejemplo n.º 6
0
def test_shouldThrowExceptionIfInUnstablePhaseWhileGettingVersions(fixture):
    syncer = mockSyncer()
    syncer.versionsOf = lambda *_: [anyUTCDateTime()]
    rule = fixture.ruleWith(mockedSynchronizer=syncer,
                            syncerOptions=mkSyncerOpts(Loc1=location("/loc1")))

    rule.versionsOf(location("/not-in-a-port"),
                    PositiveUnstablePhaseDetector())

    with pytest.raises(UnstablePhaseException):
        rule.versionsOf(location("/loc1"), PositiveUnstablePhaseDetector())
Ejemplo n.º 7
0
def test_shouldRequireForceOptionToRestoreWithARuleWhoseExecutionIsTooClose(
        fixture):
    now = anyUTCDateTime()
    fixture.setClock(constantTimeClock(now))

    _, sched = fixture.conf.aSched().withNextExecutionTimeFunc(
        lambda *_: now).mock()
    syncer = fixture.conf.syncerHavingAnyVersions().write()
    rule = fixture.conf.aRule().withScheduler(sched).withSynchronizer(syncer).\
        withLoc1("/mnt").write()

    fixture.runSibtCheckingExecs("restore", "/mnt", ":")
    fixture.shouldHaveExitedWithStatus(1)
    fixture.stderr.shouldInclude("error", "execution", "less than").but.\
        shouldNotInclude("warning", "matching")

    syncer.expectingRestore().reMakeExpectations()
    fixture.runSibtCheckingExecs("restore", "--force", "/mnt", ":")
    fixture.shouldHaveExitedWithStatus(0)
    fixture.stderr.shouldBeEmpty()
Ejemplo n.º 8
0
  def test_shouldCorrectlyReadExecutionsThatAreStillInProgress(self, fixture):
    startTime = anyUTCDateTime()
    executionsInThisProcess = []
    executionsInOtherProcess = []

    def execute(logger):
      logger.write(b"output\n")
      executionsInThisProcess.extend(fixture.executionsOf("quux"))
      executionsInOtherProcess.extend(fixture.inNewProcess(r"""
        return fixture.executionsOf("quux")"""))
      return True

    fixture.log.logExecution("quux", constantTimeClock(startTime), execute)

    iterToTest(executionsInOtherProcess).shouldContainMatching(
        lambda execution: 
          execution.startTime == startTime and
          execution.output == "output\n" and
          execution.finished is False)
    iterToTest(executionsInThisProcess).shouldContainMatching(
        lambda execution: execution.finished is False)
Ejemplo n.º 9
0
def make(minimum=timedelta(hours=1), currentTime=anyUTCDateTime()):
    return ExecutionClosenessDetector(constantTimeClock(currentTime), minimum)