Commit bdfd7802 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Clarify job ID-related type checks, add unittests



Instead of a rather complicated expression only “JobId” is output. Job
ID lists (like generated by “SubmitManyJobs”) are limited to two-item
lists. Unittests are added.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent f7686867
......@@ -307,8 +307,9 @@ TPositiveFloat = \
TAnd(TFloat, WithDesc("EqualGreaterZero")(lambda v: v >= 0.0))
#: Job ID
TJobId = TOr(TPositiveInt,
TRegex(re.compile("^%s$" % constants.JOB_ID_TEMPLATE)))
TJobId = WithDesc("JobId")(TOr(TPositiveInt,
TRegex(re.compile("^%s$" %
constants.JOB_ID_TEMPLATE))))
#: Number
TNumber = TOr(TInt, TFloat)
......
......@@ -429,7 +429,9 @@ def _BuildJobDepCheck(relative):
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
#: List of submission status and job ID as returned by C{SubmitManyJobs}
TJobIdList = ht.TListOf(ht.TItems([ht.TBool, ht.TOr(ht.TString, ht.TJobId)]))
TJobIdList = \
ht.TListOf(ht.TAnd(ht.TIsLength(2),
ht.TItems([ht.TBool, ht.TOr(ht.TString, ht.TJobId)])))
#: Result containing only list of submitted jobs
TJobIdListOnly = ht.TStrictDict(True, True, {
......
......@@ -306,5 +306,37 @@ class TestOpcodeDepends(unittest.TestCase):
self.assertFalse(check_norelative(i))
class TestResultChecks(unittest.TestCase):
def testJobIdList(self):
for i in [[], [(False, "error")], [(False, "")],
[(True, 123), (True, "999")]]:
self.assertTrue(opcodes.TJobIdList(i))
for i in ["", [("x", 1)], [[], []], [[False, "", None], [True, 123]]]:
self.assertFalse(opcodes.TJobIdList(i))
def testJobIdListOnly(self):
self.assertTrue(opcodes.TJobIdListOnly({
constants.JOB_IDS_KEY: [],
}))
self.assertTrue(opcodes.TJobIdListOnly({
constants.JOB_IDS_KEY: [(True, "9282")],
}))
self.assertFalse(opcodes.TJobIdListOnly({
"x": None,
}))
self.assertFalse(opcodes.TJobIdListOnly({
constants.JOB_IDS_KEY: [],
"x": None,
}))
self.assertFalse(opcodes.TJobIdListOnly({
constants.JOB_IDS_KEY: [("foo", "bar")],
}))
self.assertFalse(opcodes.TJobIdListOnly({
constants.JOB_IDS_KEY: [("one", "two", "three")],
}))
if __name__ == "__main__":
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment