3184 def testModifier(self):
3186 p = Process(
"test",m1)
3187 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3190 m1.toModify(p.a,_mod_fred)
3191 self.assertEqual(p.a.fred.value(),2)
3192 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3193 m1.toModify(p.b, wilma = 2)
3194 self.assertEqual(p.b.wilma.value(),2)
3195 self.assertTrue(p.isUsingModifier(m1))
3199 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3200 m1.toModify(p.a,_mod_fred)
3201 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3202 m1.toModify(p.b, wilma = 2)
3203 self.assertEqual(p.a.fred.value(),1)
3204 self.assertEqual(p.b.wilma.value(),1)
3205 self.assertEqual(p.isUsingModifier(m1),
False)
3208 p = Process(
"test",m1)
3209 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3210 m1.toModify(p.a, fred = int32(2))
3211 p.b = p.a.clone(wilma = int32(3))
3212 self.assertEqual(p.a.fred.value(),2)
3213 self.assertEqual(p.a.wilma.value(),1)
3214 self.assertEqual(p.b.fred.value(),2)
3215 self.assertEqual(p.b.wilma.value(),3)
3218 p = Process(
"test",m1)
3219 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
3220 m1.toModify(p.a, fred =
None, fintstones = dict(fred =
None))
3221 self.assertEqual(hasattr(p.a,
"fred"),
False)
3222 self.assertEqual(hasattr(p.a.fintstones,
"fred"),
False)
3223 self.assertEqual(p.a.wilma.value(),1)
3226 p = Process(
"test",m1)
3227 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3228 m1.toModify(p.a, wilma = int32(2))
3229 self.assertEqual(p.a.fred.value(), 1)
3230 self.assertEqual(p.a.wilma.value(),2)
3233 p = Process(
"test",m1)
3234 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
3235 m1.toModify(p.a, flintstones = dict(fred = int32(2)))
3236 self.assertEqual(p.a.flintstones.fred.value(),2)
3237 self.assertEqual(p.a.flintstones.wilma.value(),1)
3240 p = Process(
"test",m1)
3241 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
3242 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
3243 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, foo = 1))
3246 p = Process(
"test",m1)
3247 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3248 m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
3249 self.assertEqual(p.a.flintstones[0].fred.value(),1)
3250 self.assertEqual(p.a.flintstones[1].wilma.value(),2)
3253 p = Process(
"test",m1)
3254 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3255 m1.toModify(p.a, fred = {1:7})
3256 self.assertEqual(p.a.fred[0],1)
3257 self.assertEqual(p.a.fred[1],7)
3258 self.assertEqual(p.a.fred[2],3)
3261 p = Process(
"test",m1)
3262 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3264 try: m1.toModify(p.a, fred = {5:7})
3265 except IndexError
as e: raised =
True
3266 self.assertEqual(raised,
True)
3269 p = Process(
"test",m1)
3270 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3272 try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
3273 except TypeError
as e: raised =
True
3274 self.assertEqual(raised,
True)
3278 class ProcModifierMod(
object):
3279 def __init__(self,modifier,func):
3280 self.proc_mod_ = modifier.makeProcessModifier(func)
3283 self.a = EDAnalyzer(
"Dummy")
3284 testMod = DummyMod()
3286 self.assertTrue(hasattr(p,
"a"))
3288 p = Process(
"test",m1)
3289 testProcMod = ProcModifierMod(m1,_rem_a)
3291 p.extend(testProcMod)
3292 self.assertTrue(
not hasattr(p,
"a"))
3295 mc = ModifierChain(m1)
3296 p = Process(
"test",mc)
3297 self.assertTrue(p.isUsingModifier(m1))
3298 self.assertTrue(p.isUsingModifier(mc))
3299 testMod = DummyMod()
3300 p.b = EDAnalyzer(
"Dummy2", fred = int32(1))
3301 m1.toModify(p.b, fred = int32(3))
3303 testProcMod = ProcModifierMod(m1,_rem_a)
3304 p.extend(testProcMod)
3305 self.assertTrue(
not hasattr(p,
"a"))
3306 self.assertEqual(p.b.fred.value(),3)
3310 mc = ModifierChain(m1,m2)
3311 mclone = mc.copyAndExclude([m2])
3312 self.assertTrue(
not mclone._isOrContains(m2))
3313 self.assertTrue(mclone._isOrContains(m1))
3315 mc2 = ModifierChain(mc,m3)
3316 mclone = mc2.copyAndExclude([m2])
3317 self.assertTrue(
not mclone._isOrContains(m2))
3318 self.assertTrue(mclone._isOrContains(m1))
3319 self.assertTrue(mclone._isOrContains(m3))
3323 p = Process(
"test",m1)
3324 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3325 (m1 & m2).toModify(p.a, fred = int32(2))
3326 self.assertRaises(TypeError,
lambda: (m1 & m2).toModify(p.a, 1, wilma=2))
3327 self.assertEqual(p.a.fred, 1)
3330 p = Process(
"test",m1,m2)
3331 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3332 (m1 & m2).toModify(p.a, fred = int32(2))
3333 self.assertEqual(p.a.fred, 2)
3337 p = Process(
"test",m1,m2,m3)
3338 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3339 (m1 & m2 & m3).toModify(p.a, fred = int32(2))
3340 self.assertEqual(p.a.fred, 2)
3341 (m1 & (m2 & m3)).toModify(p.a, fred = int32(3))
3342 self.assertEqual(p.a.fred, 3)
3343 ((m1 & m2) & m3).toModify(p.a, fred = int32(4))
3344 self.assertEqual(p.a.fred, 4)
3348 p = Process(
"test", m1)
3349 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3350 (~m1).toModify(p.a, fred=2)
3351 self.assertEqual(p.a.fred, 1)
3352 (~m2).toModify(p.a, wilma=2)
3353 self.assertEqual(p.a.wilma, 2)
3354 self.assertRaises(TypeError,
lambda: (~m1).toModify(p.a, 1, wilma=2))
3355 self.assertRaises(TypeError,
lambda: (~m2).toModify(p.a, 1, wilma=2))
3360 p = Process(
"test", m1)
3361 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3362 (m1 | m2).toModify(p.a, fred=2)
3363 self.assertEqual(p.a.fred, 2)
3364 (m1 | m2 | m3).toModify(p.a, fred=3)
3365 self.assertEqual(p.a.fred, 3)
3366 (m3 | m2 | m1).toModify(p.a, fred=4)
3367 self.assertEqual(p.a.fred, 4)
3368 ((m1 | m2) | m3).toModify(p.a, fred=5)
3369 self.assertEqual(p.a.fred, 5)
3370 (m1 | (m2 | m3)).toModify(p.a, fred=6)
3371 self.assertEqual(p.a.fred, 6)
3372 (m2 | m3).toModify(p.a, fred=7)
3373 self.assertEqual(p.a.fred, 6)
3374 self.assertRaises(TypeError,
lambda: (m1 | m2).toModify(p.a, 1, wilma=2))
3375 self.assertRaises(TypeError,
lambda: (m2 | m3).toModify(p.a, 1, wilma=2))
3381 p = Process(
"test", m1, m2)
3382 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3383 (m1 & ~m2).toModify(p.a, fred=2)
3384 self.assertEqual(p.a.fred, 1)
3385 (m1 & ~m3).toModify(p.a, fred=2)
3386 self.assertEqual(p.a.fred, 2)
3387 (m1 | ~m2).toModify(p.a, fred=3)
3388 self.assertEqual(p.a.fred, 3)
3389 (~m1 | ~m2).toModify(p.a, fred=4)
3390 self.assertEqual(p.a.fred, 3)
3391 (~m3 & ~m4).toModify(p.a, fred=4)
3392 self.assertEqual(p.a.fred, 4)
3393 ((m1 & m3) | ~m4).toModify(p.a, fred=5)
3394 self.assertEqual(p.a.fred, 5)
3397 p = Process(
"test",m1)
3398 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3399 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3400 self.assertRaises(TypeError,
lambda: m1.toReplaceWith(p.a, EDProducer(
"YourProducer")))
3401 p.b =EDAnalyzer(
"BAn")
3402 p.c =EDProducer(
"c")
3403 p.d =EDProducer(
"d")
3407 m1.toReplaceWith(p.s,
Sequence(p.a+p.b, p.td))
3408 self.assertEqual(p.a.wilma.value(),3)
3409 self.assertEqual(p.a.type_(),
"YourAnalyzer")
3410 self.assertEqual(hasattr(p,
"fred"),
False)
3411 self.assertTrue(p.s.dumpPython() ==
"cms.Sequence(process.a+process.b, process.td)\n")
3412 p.e =EDProducer(
"e")
3413 m1.toReplaceWith(p.td, Task(p.e))
3414 self.assertTrue(p.td._collection ==
OrderedSet([p.e]))
3418 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3419 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3420 self.assertEqual(p.a.type_(),
"MyAnalyzer")
3426 p = Process(
"test", m1, m2)
3427 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3428 self.assertRaises(TypeError,
lambda: (m1 & m2).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3429 self.assertRaises(TypeError,
lambda: (m3 & m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3430 self.assertRaises(TypeError,
lambda: (~m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3431 self.assertRaises(TypeError,
lambda: (~m1).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3432 self.assertRaises(TypeError,
lambda: (m1 | m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3433 self.assertRaises(TypeError,
lambda: (m3 | m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3434 (m1 & m2).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer1"))
3435 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3436 (m1 & m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3437 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3438 (~m1).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3439 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3440 (~m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3441 self.assertEqual(p.a.type_(),
"YourAnalyzer2")
3442 (m1 | m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer3"))
3443 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3444 (m3 | m4).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer4"))
3445 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3448 a = EDAlias(foo2 =
VPSet(PSet(type =
string(
"Foo2"))))
3452 m.toModify(a, foo2 = {0: dict(type =
"Foo3")})
3453 self.assertEqual(a.foo2[0].type,
"Foo3")
3455 m.toModify(a, foo4 =
VPSet(PSet(type =
string(
"Foo4"))))
3456 self.assertEqual(a.foo2[0].type,
"Foo3")
3457 self.assertEqual(a.foo4[0].type,
"Foo4")
3459 m.toModify(a, foo2 =
None)
3460 self.assertFalse(hasattr(a,
"foo2"))
3461 self.assertEqual(a.foo4[0].type,
"Foo4")
3463 m.toReplaceWith(a, EDAlias(bar =
VPSet(PSet(type =
string(
"Bar")))))
3464 self.assertFalse(hasattr(a,
"foo2"))
3465 self.assertFalse(hasattr(a,
"foo4"))
3466 self.assertTrue(hasattr(a,
"bar"))
3467 self.assertEqual(a.bar[0].type,
"Bar")
3470 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
3472 b = PSet(c = int32(2))),
3473 test2 = EDProducer(
"Bar",
3475 bb = PSet(cc = int32(12))))
3480 test1 = dict(a = 4, b = dict(c =
None)),
3481 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
3482 self.assertEqual(sp.test1.a.value(), 4)
3483 self.assertEqual(sp.test1.b.hasParameter(
"c"),
False)
3484 self.assertEqual(sp.test2.aa.value(), 15)
3485 self.assertEqual(sp.test2.bb.cc.value(), 45)
3486 self.assertEqual(sp.test2.bb.dd.value(),
"foo")
3488 m.toReplaceWith(sp.test1, EDProducer(
"Fred", x = int32(42)))
3489 self.assertEqual(sp.test1.type_(),
"Fred")
3490 self.assertEqual(sp.test1.x.value(), 42)
3491 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test1, EDAnalyzer(
"Foo")))
3493 m.toModify(sp, test2 = EDProducer(
"Xyzzy", x = int32(24)))
3494 self.assertEqual(sp.test2.type_(),
"Xyzzy")
3495 self.assertEqual(sp.test2.x.value(), 24)
3496 self.assertRaises(TypeError,
lambda: m.toModify(sp, test2 = EDAnalyzer(
"Foo")))
3498 m.toModify(sp, test3 = EDProducer(
"Wilma", y = int32(24)))
3499 self.assertEqual(sp.test3.type_(),
"Wilma")
3500 self.assertEqual(sp.test3.y.value(), 24)
3501 self.assertRaises(TypeError,
lambda: m.toModify(sp, test4 = EDAnalyzer(
"Foo")))
3503 m.toModify(sp, test2 =
None)
3504 self.assertEqual(hasattr(sp,
"test2"),
False)
3506 m.toModify(sp, test2 = EDAlias(foo =
VPSet(PSet(type =
string(
"int")))))
3507 self.assertTrue(hasattr(sp.test2,
"foo"))
3509 m.toReplaceWith(sp.test2, EDAlias(bar =
VPSet(PSet(type =
string(
"int")))))
3510 self.assertTrue(hasattr(sp.test2,
"bar"))
3512 m.toModify(sp, test2 = EDAlias(xyzzy =
VPSet(PSet(type =
string(
"int")))))
3513 self.assertTrue(hasattr(sp.test2,
"xyzzy"))
3515 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test2, EDProducer(
"Foo")))
3516 m.toModify(sp, test2 = EDProducer(
"Foo"))