3183 def testModifier(self):
3185 p = Process(
"test",m1)
3186 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3189 m1.toModify(p.a,_mod_fred)
3190 self.assertEqual(p.a.fred.value(),2)
3191 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3192 m1.toModify(p.b, wilma = 2)
3193 self.assertEqual(p.b.wilma.value(),2)
3194 self.assertTrue(p.isUsingModifier(m1))
3198 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3199 m1.toModify(p.a,_mod_fred)
3200 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3201 m1.toModify(p.b, wilma = 2)
3202 self.assertEqual(p.a.fred.value(),1)
3203 self.assertEqual(p.b.wilma.value(),1)
3204 self.assertEqual(p.isUsingModifier(m1),
False)
3207 p = Process(
"test",m1)
3208 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3209 m1.toModify(p.a, fred = int32(2))
3210 p.b = p.a.clone(wilma = int32(3))
3211 self.assertEqual(p.a.fred.value(),2)
3212 self.assertEqual(p.a.wilma.value(),1)
3213 self.assertEqual(p.b.fred.value(),2)
3214 self.assertEqual(p.b.wilma.value(),3)
3217 p = Process(
"test",m1)
3218 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
3219 m1.toModify(p.a, fred =
None, fintstones = dict(fred =
None))
3220 self.assertEqual(hasattr(p.a,
"fred"),
False)
3221 self.assertEqual(hasattr(p.a.fintstones,
"fred"),
False)
3222 self.assertEqual(p.a.wilma.value(),1)
3225 p = Process(
"test",m1)
3226 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3227 m1.toModify(p.a, wilma = int32(2))
3228 self.assertEqual(p.a.fred.value(), 1)
3229 self.assertEqual(p.a.wilma.value(),2)
3232 p = Process(
"test",m1)
3233 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
3234 m1.toModify(p.a, flintstones = dict(fred = int32(2)))
3235 self.assertEqual(p.a.flintstones.fred.value(),2)
3236 self.assertEqual(p.a.flintstones.wilma.value(),1)
3239 p = Process(
"test",m1)
3240 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
3241 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
3242 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, foo = 1))
3245 p = Process(
"test",m1)
3246 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3247 m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
3248 self.assertEqual(p.a.flintstones[0].fred.value(),1)
3249 self.assertEqual(p.a.flintstones[1].wilma.value(),2)
3252 p = Process(
"test",m1)
3253 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3254 m1.toModify(p.a, fred = {1:7})
3255 self.assertEqual(p.a.fred[0],1)
3256 self.assertEqual(p.a.fred[1],7)
3257 self.assertEqual(p.a.fred[2],3)
3260 p = Process(
"test",m1)
3261 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3263 try: m1.toModify(p.a, fred = {5:7})
3264 except IndexError
as e: raised =
True
3265 self.assertEqual(raised,
True)
3268 p = Process(
"test",m1)
3269 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3271 try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
3272 except TypeError
as e: raised =
True
3273 self.assertEqual(raised,
True)
3277 class ProcModifierMod(
object):
3278 def __init__(self,modifier,func):
3279 self.proc_mod_ = modifier.makeProcessModifier(func)
3282 self.a = EDAnalyzer(
"Dummy")
3283 testMod = DummyMod()
3285 self.assertTrue(hasattr(p,
"a"))
3287 p = Process(
"test",m1)
3288 testProcMod = ProcModifierMod(m1,_rem_a)
3290 p.extend(testProcMod)
3291 self.assertTrue(
not hasattr(p,
"a"))
3294 mc = ModifierChain(m1)
3295 p = Process(
"test",mc)
3296 self.assertTrue(p.isUsingModifier(m1))
3297 self.assertTrue(p.isUsingModifier(mc))
3298 testMod = DummyMod()
3299 p.b = EDAnalyzer(
"Dummy2", fred = int32(1))
3300 m1.toModify(p.b, fred = int32(3))
3302 testProcMod = ProcModifierMod(m1,_rem_a)
3303 p.extend(testProcMod)
3304 self.assertTrue(
not hasattr(p,
"a"))
3305 self.assertEqual(p.b.fred.value(),3)
3309 mc = ModifierChain(m1,m2)
3310 mclone = mc.copyAndExclude([m2])
3311 self.assertTrue(
not mclone._isOrContains(m2))
3312 self.assertTrue(mclone._isOrContains(m1))
3314 mc2 = ModifierChain(mc,m3)
3315 mclone = mc2.copyAndExclude([m2])
3316 self.assertTrue(
not mclone._isOrContains(m2))
3317 self.assertTrue(mclone._isOrContains(m1))
3318 self.assertTrue(mclone._isOrContains(m3))
3322 p = Process(
"test",m1)
3323 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3324 (m1 & m2).toModify(p.a, fred = int32(2))
3325 self.assertRaises(TypeError,
lambda: (m1 & m2).toModify(p.a, 1, wilma=2))
3326 self.assertEqual(p.a.fred, 1)
3329 p = Process(
"test",m1,m2)
3330 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3331 (m1 & m2).toModify(p.a, fred = int32(2))
3332 self.assertEqual(p.a.fred, 2)
3336 p = Process(
"test",m1,m2,m3)
3337 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3338 (m1 & m2 & m3).toModify(p.a, fred = int32(2))
3339 self.assertEqual(p.a.fred, 2)
3340 (m1 & (m2 & m3)).toModify(p.a, fred = int32(3))
3341 self.assertEqual(p.a.fred, 3)
3342 ((m1 & m2) & m3).toModify(p.a, fred = int32(4))
3343 self.assertEqual(p.a.fred, 4)
3347 p = Process(
"test", m1)
3348 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3349 (~m1).toModify(p.a, fred=2)
3350 self.assertEqual(p.a.fred, 1)
3351 (~m2).toModify(p.a, wilma=2)
3352 self.assertEqual(p.a.wilma, 2)
3353 self.assertRaises(TypeError,
lambda: (~m1).toModify(p.a, 1, wilma=2))
3354 self.assertRaises(TypeError,
lambda: (~m2).toModify(p.a, 1, wilma=2))
3359 p = Process(
"test", m1)
3360 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3361 (m1 | m2).toModify(p.a, fred=2)
3362 self.assertEqual(p.a.fred, 2)
3363 (m1 | m2 | m3).toModify(p.a, fred=3)
3364 self.assertEqual(p.a.fred, 3)
3365 (m3 | m2 | m1).toModify(p.a, fred=4)
3366 self.assertEqual(p.a.fred, 4)
3367 ((m1 | m2) | m3).toModify(p.a, fred=5)
3368 self.assertEqual(p.a.fred, 5)
3369 (m1 | (m2 | m3)).toModify(p.a, fred=6)
3370 self.assertEqual(p.a.fred, 6)
3371 (m2 | m3).toModify(p.a, fred=7)
3372 self.assertEqual(p.a.fred, 6)
3373 self.assertRaises(TypeError,
lambda: (m1 | m2).toModify(p.a, 1, wilma=2))
3374 self.assertRaises(TypeError,
lambda: (m2 | m3).toModify(p.a, 1, wilma=2))
3380 p = Process(
"test", m1, m2)
3381 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3382 (m1 & ~m2).toModify(p.a, fred=2)
3383 self.assertEqual(p.a.fred, 1)
3384 (m1 & ~m3).toModify(p.a, fred=2)
3385 self.assertEqual(p.a.fred, 2)
3386 (m1 | ~m2).toModify(p.a, fred=3)
3387 self.assertEqual(p.a.fred, 3)
3388 (~m1 | ~m2).toModify(p.a, fred=4)
3389 self.assertEqual(p.a.fred, 3)
3390 (~m3 & ~m4).toModify(p.a, fred=4)
3391 self.assertEqual(p.a.fred, 4)
3392 ((m1 & m3) | ~m4).toModify(p.a, fred=5)
3393 self.assertEqual(p.a.fred, 5)
3396 p = Process(
"test",m1)
3397 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3398 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3399 self.assertRaises(TypeError,
lambda: m1.toReplaceWith(p.a, EDProducer(
"YourProducer")))
3400 p.b =EDAnalyzer(
"BAn")
3401 p.c =EDProducer(
"c")
3402 p.d =EDProducer(
"d")
3406 m1.toReplaceWith(p.s,
Sequence(p.a+p.b, p.td))
3407 self.assertEqual(p.a.wilma.value(),3)
3408 self.assertEqual(p.a.type_(),
"YourAnalyzer")
3409 self.assertEqual(hasattr(p,
"fred"),
False)
3410 self.assertTrue(p.s.dumpPython() ==
"cms.Sequence(process.a+process.b, process.td)\n")
3411 p.e =EDProducer(
"e")
3412 m1.toReplaceWith(p.td, Task(p.e))
3413 self.assertTrue(p.td._collection ==
OrderedSet([p.e]))
3417 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3418 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3419 self.assertEqual(p.a.type_(),
"MyAnalyzer")
3425 p = Process(
"test", m1, m2)
3426 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3427 self.assertRaises(TypeError,
lambda: (m1 & m2).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3428 self.assertRaises(TypeError,
lambda: (m3 & m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3429 self.assertRaises(TypeError,
lambda: (~m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3430 self.assertRaises(TypeError,
lambda: (~m1).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3431 self.assertRaises(TypeError,
lambda: (m1 | m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3432 self.assertRaises(TypeError,
lambda: (m3 | m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3433 (m1 & m2).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer1"))
3434 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3435 (m1 & m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3436 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3437 (~m1).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3438 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3439 (~m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3440 self.assertEqual(p.a.type_(),
"YourAnalyzer2")
3441 (m1 | m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer3"))
3442 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3443 (m3 | m4).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer4"))
3444 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3447 a = EDAlias(foo2 =
VPSet(PSet(type =
string(
"Foo2"))))
3451 m.toModify(a, foo2 = {0: dict(type =
"Foo3")})
3452 self.assertEqual(a.foo2[0].type,
"Foo3")
3454 m.toModify(a, foo4 =
VPSet(PSet(type =
string(
"Foo4"))))
3455 self.assertEqual(a.foo2[0].type,
"Foo3")
3456 self.assertEqual(a.foo4[0].type,
"Foo4")
3458 m.toModify(a, foo2 =
None)
3459 self.assertFalse(hasattr(a,
"foo2"))
3460 self.assertEqual(a.foo4[0].type,
"Foo4")
3462 m.toReplaceWith(a, EDAlias(bar =
VPSet(PSet(type =
string(
"Bar")))))
3463 self.assertFalse(hasattr(a,
"foo2"))
3464 self.assertFalse(hasattr(a,
"foo4"))
3465 self.assertTrue(hasattr(a,
"bar"))
3466 self.assertEqual(a.bar[0].type,
"Bar")
3469 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
3471 b = PSet(c = int32(2))),
3472 test2 = EDProducer(
"Bar",
3474 bb = PSet(cc = int32(12))))
3479 test1 = dict(a = 4, b = dict(c =
None)),
3480 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
3481 self.assertEqual(sp.test1.a.value(), 4)
3482 self.assertEqual(sp.test1.b.hasParameter(
"c"),
False)
3483 self.assertEqual(sp.test2.aa.value(), 15)
3484 self.assertEqual(sp.test2.bb.cc.value(), 45)
3485 self.assertEqual(sp.test2.bb.dd.value(),
"foo")
3487 m.toReplaceWith(sp.test1, EDProducer(
"Fred", x = int32(42)))
3488 self.assertEqual(sp.test1.type_(),
"Fred")
3489 self.assertEqual(sp.test1.x.value(), 42)
3490 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test1, EDAnalyzer(
"Foo")))
3492 m.toModify(sp, test2 = EDProducer(
"Xyzzy", x = int32(24)))
3493 self.assertEqual(sp.test2.type_(),
"Xyzzy")
3494 self.assertEqual(sp.test2.x.value(), 24)
3495 self.assertRaises(TypeError,
lambda: m.toModify(sp, test2 = EDAnalyzer(
"Foo")))
3497 m.toModify(sp, test3 = EDProducer(
"Wilma", y = int32(24)))
3498 self.assertEqual(sp.test3.type_(),
"Wilma")
3499 self.assertEqual(sp.test3.y.value(), 24)
3500 self.assertRaises(TypeError,
lambda: m.toModify(sp, test4 = EDAnalyzer(
"Foo")))
3502 m.toModify(sp, test2 =
None)
3503 self.assertEqual(hasattr(sp,
"test2"),
False)
3505 m.toModify(sp, test2 = EDAlias(foo =
VPSet(PSet(type =
string(
"int")))))
3506 self.assertTrue(hasattr(sp.test2,
"foo"))
3508 m.toReplaceWith(sp.test2, EDAlias(bar =
VPSet(PSet(type =
string(
"int")))))
3509 self.assertTrue(hasattr(sp.test2,
"bar"))
3511 m.toModify(sp, test2 = EDAlias(xyzzy =
VPSet(PSet(type =
string(
"int")))))
3512 self.assertTrue(hasattr(sp.test2,
"xyzzy"))
3514 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test2, EDProducer(
"Foo")))
3515 m.toModify(sp, test2 = EDProducer(
"Foo"))