Пример #1
0
def test_shouldParseOptionValuesAndRemoveNameBeforePassingThemOn(fixture):
    schedOptInfo, syncerOptInfo = object(), object()
    sched = fakeConfigurable("sched", availableOptions=[schedOptInfo])
    syncer = fakeConfigurable("syncer", availableOptions=[syncerOptInfo])
    oldRuleOpts = {"Opt": "abc"}
    oldSchedOpts, oldSyncerOpts = {"Name": "sched", "N": "2"}, \
        {"Name": "syncer", "A": "yes"}
    newSchedOpts, newSyncerOpts = {"N": 2}, {"A": True}

    fixture.parser.expectCallsInAnyOrder(
        mock.callMatching("parseOptions",
                          lambda infos, opts: opts == dict(N="2") and infos[0]
                          is schedOptInfo,
                          ret=newSchedOpts),
        mock.callMatching("parseOptions",
                          lambda infos, opts: opts == dict(A="yes") and infos[
                              0] is syncerOptInfo,
                          ret=newSyncerOpts),
        mock.callMatching("parseOptions",
                          lambda infos, opts: opts == oldRuleOpts and infos is
                          syncrule.AvailableOptions,
                          ret=oldRuleOpts))

    fixture.ruleFactory.expectCalls(
        mock.callMatchingTuple(
            "build", lambda args: args[3] == oldRuleOpts and args[4] ==
            newSchedOpts and args[5] == mkSyncerOpts(**newSyncerOpts)))

    fixture.makeReader([sched],
                       [syncer]).readRule("name", oldRuleOpts, oldSchedOpts,
                                          oldSyncerOpts, True)
Пример #2
0
def test_shouldTreatLocsCorrespondingToPortsAsMinimumOptions(fixture):
    def locOptInfo(number):
        return optInfo("Loc" + str(number), types.Location)

    sched = fakeConfigurable("scheduler")
    syncer = fakeConfigurable("synchronizer",
                              ports=[port(), port(),
                                     port(), port()],
                              availableOptions=[
                                  locOptInfo(1),
                                  locOptInfo(2),
                                  locOptInfo(3),
                                  locOptInfo(4)
                              ])

    loc1Through3 = {
        "Loc1": loc("/some-place"),
        "Loc2": loc("/place"),
        "Loc3": loc("/bar")
    }

    with pytest.raises(ConfigConsistencyException) as ex:
        fixture.factory.build("rulename", sched, syncer, {}, {},
                              mkSyncerOpts(**loc1Through3), True)
    strToTest(str(ex.value)).shouldIncludeInOrder("not", "minimum opt").andAlso.\
        shouldInclude("Loc4")

    with noException():
        fixture.factory.build(
            "rule", sched, syncer, {}, {},
            mkSyncerOpts(Loc4=loc("/fourth"), **loc1Through3), True)
Пример #3
0
def test_shouldFindSyncersAndSchedsByTheirNameOptions(fixture):
    sched = fakeConfigurable("sched-b")
    syncer = fakeConfigurable("syncer")

    fixture.parser.parseOptions = lambda _, opts: opts

    fixture.ruleFactory.expectCalls(
        mock.callMatching(
            "build", lambda name, receivedSched, receivedSyncer, *_: name ==
            "sys" and receivedSched is sched and receivedSyncer is syncer))

    reader = fixture.makeReader([fakeConfigurable("sched-a"), sched], [syncer])
    reader.readRule("sys", {}, {"Name": "sched-b"}, {"Name": "syncer"}, False)
Пример #4
0
def test_shouldAddLocOptInfosToAvailableOptionsBasedOnPorts():
  wrapped = fakeConfigurable("syncer", 
      ports=[port(), port(), port()], availableOptions=[])
  syncer = DefaultValueSynchronizer(wrapped)

  iterToTest(syncer.availableOptions).shouldContainMatching(
      lambda opt: opt.name == "Loc1" and opt.optionType == types.Location,
      lambda opt: opt.name == "Loc2", lambda opt: opt.name == "Loc3")
Пример #5
0
def test_shouldFailIfSyncersOrSchedsWithNamesOrNameOptionsThemselvesAreNotThere(
        fixture):
    scheduler = fakeConfigurable("the-sched")
    synchronizer = fakeConfigurable("the-syncer")
    reader = fixture.makeReader([scheduler], [synchronizer])

    with pytest.raises(ConfigurableNotFoundException) as ex:
        reader.readRule("rule", {}, {}, {"Name": "synchronizer"}, True)
    assert strToTest(ex.value.message).shouldIncludeInOrder("option", "not")

    with pytest.raises(ConfigurableNotFoundException):
        reader.readRule("name", {}, {"Name": "no"}, {"Name": "the-syncer"},
                        False)
    with pytest.raises(ConfigurableNotFoundException) as ex:
        reader.readRule("name", {}, {"Name": "the-sched"}, {"Name": "no"},
                        False)
    assert ex.value.unitName == "no"
    assert ex.value.unitType == "synchronizer"
Пример #6
0
def test_shouldThrowExceptionIfAnOptionIsNotSupported(fixture):
    scheduler = fakeConfigurable("sched",
                                 availableOptions=[optInfo("sched-supported")])
    synchronizer = fakeConfigurable(
        "syncer", ports=[], availableOptions=[optInfo("syncer-supported")])

    def callBuild(ruleOptions, schedulerOptions, synchronizerOptions):
        fixture.factory.build("rule", scheduler, synchronizer, ruleOptions,
                              schedulerOptions,
                              mkSyncerOpts(**synchronizerOptions), True)

    with pytest.raises(ConfigConsistencyException):
        callBuild({}, {"sched-supported": 1}, {"not": 1})
    with pytest.raises(ConfigConsistencyException):
        callBuild({}, {"not": 1}, {"syncer-supported": 1})

    with noException():
        callBuild({}, {"sched-supported": 1}, {"syncer-supported": 1})

    with pytest.raises(ConfigConsistencyException):
        callBuild({"Blah": 2}, {"sched-supported": 1}, {"syncer-supported": 1})
Пример #7
0
def test_shouldWrapAllParseExceptionsItGetsInAConsistencyEx(fixture):
    def fail(_, opts):
        if "A" not in opts or opts["A"] == "3":
            raise OptionParseException(
                ["rule-foo" if "A" not in opts else "sched-bar"])
        return True

    sched, syncer = fakeConfigurable("sched"), fakeConfigurable("syncer")

    fixture.parser.expectCalls(
        mock.callMatching("parseOptions", fail, anyNumber=True, ret={}))

    with pytest.raises(ConfigConsistencyException) as ex:
        fixture.makeReader([sched], [syncer]).readRule("rule", {}, {
            "Name": "sched",
            "A": "3"
        }, {
            "Name": "syncer",
            "A": "0"
        }, False)
    strToTest(ex.value.message).shouldIncludeInOrder("[Scheduler]", "sched-bar").\
        andAlso.shouldIncludeInOrder("[Rule]", "rule-foo").andAlso.\
        shouldNotInclude("[Synchronizer]")
Пример #8
0
def test_shouldThrowExceptionIfRuleNameContainsInvalidCharacters(fixture):
    with pytest.raises(RuleNameInvalidException) as ex:
        fixture.factory.build("foo@with space", fakeConfigurable("sched"),
                              fakeConfigurable("syncer", ports=[]), {}, {},
                              mkSyncerOpts(), False)
    assert ex.value.invalidCharacter == " "
Пример #9
0
 def buildRuleWithNoOpts(self):
     return self.factory.build("name", fakeConfigurable(),
                               fakeConfigurable(ports=[]), {}, {},
                               mkSyncerOpts(), False)
Пример #10
0
def ruleWith(**kwargs):
    ret = mockRule(**kwargs)
    ret.scheduler, ret.synchronizer = fakeConfigurable(), fakeConfigurable()
    return ret