3178 def testModifier(self):
3180 p = Process(
"test",m1)
3181 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3184 m1.toModify(p.a,_mod_fred)
3185 self.assertEqual(p.a.fred.value(),2)
3186 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3187 m1.toModify(p.b, wilma = 2)
3188 self.assertEqual(p.b.wilma.value(),2)
3189 self.assertTrue(p.isUsingModifier(m1))
3193 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3194 m1.toModify(p.a,_mod_fred)
3195 p.b = EDAnalyzer(
"YourAnalyzer", wilma = int32(1))
3196 m1.toModify(p.b, wilma = 2)
3197 self.assertEqual(p.a.fred.value(),1)
3198 self.assertEqual(p.b.wilma.value(),1)
3199 self.assertEqual(p.isUsingModifier(m1),
False)
3202 p = Process(
"test",m1)
3203 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3204 m1.toModify(p.a, fred = int32(2))
3205 p.b = p.a.clone(wilma = int32(3))
3206 self.assertEqual(p.a.fred.value(),2)
3207 self.assertEqual(p.a.wilma.value(),1)
3208 self.assertEqual(p.b.fred.value(),2)
3209 self.assertEqual(p.b.wilma.value(),3)
3212 p = Process(
"test",m1)
3213 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
3214 m1.toModify(p.a, fred =
None, fintstones = dict(fred =
None))
3215 self.assertEqual(hasattr(p.a,
"fred"),
False)
3216 self.assertEqual(hasattr(p.a.fintstones,
"fred"),
False)
3217 self.assertEqual(p.a.wilma.value(),1)
3220 p = Process(
"test",m1)
3221 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3222 m1.toModify(p.a, wilma = int32(2))
3223 self.assertEqual(p.a.fred.value(), 1)
3224 self.assertEqual(p.a.wilma.value(),2)
3227 p = Process(
"test",m1)
3228 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
3229 m1.toModify(p.a, flintstones = dict(fred = int32(2)))
3230 self.assertEqual(p.a.flintstones.fred.value(),2)
3231 self.assertEqual(p.a.flintstones.wilma.value(),1)
3234 p = Process(
"test",m1)
3235 p.a = EDAnalyzer(
"MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
3236 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
3237 self.assertRaises(KeyError,
lambda: m1.toModify(p.a, foo = 1))
3240 p = Process(
"test",m1)
3241 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3242 m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
3243 self.assertEqual(p.a.flintstones[0].fred.value(),1)
3244 self.assertEqual(p.a.flintstones[1].wilma.value(),2)
3247 p = Process(
"test",m1)
3248 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3249 m1.toModify(p.a, fred = {1:7})
3250 self.assertEqual(p.a.fred[0],1)
3251 self.assertEqual(p.a.fred[1],7)
3252 self.assertEqual(p.a.fred[2],3)
3255 p = Process(
"test",m1)
3256 p.a = EDAnalyzer(
"MyAnalyzer", fred = vuint32(1,2,3))
3258 try: m1.toModify(p.a, fred = {5:7})
3259 except IndexError
as e: raised =
True
3260 self.assertEqual(raised,
True)
3263 p = Process(
"test",m1)
3264 p.a = EDAnalyzer(
"MyAnalyzer", flintstones =
VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3266 try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
3267 except TypeError
as e: raised =
True
3268 self.assertEqual(raised,
True)
3272 class ProcModifierMod(
object):
3273 def __init__(self,modifier,func):
3274 self.proc_mod_ = modifier.makeProcessModifier(func)
3277 self.a = EDAnalyzer(
"Dummy")
3278 testMod = DummyMod()
3280 self.assertTrue(hasattr(p,
"a"))
3282 p = Process(
"test",m1)
3283 testProcMod = ProcModifierMod(m1,_rem_a)
3285 p.extend(testProcMod)
3286 self.assertTrue(
not hasattr(p,
"a"))
3289 mc = ModifierChain(m1)
3290 p = Process(
"test",mc)
3291 self.assertTrue(p.isUsingModifier(m1))
3292 self.assertTrue(p.isUsingModifier(mc))
3293 testMod = DummyMod()
3294 p.b = EDAnalyzer(
"Dummy2", fred = int32(1))
3295 m1.toModify(p.b, fred = int32(3))
3297 testProcMod = ProcModifierMod(m1,_rem_a)
3298 p.extend(testProcMod)
3299 self.assertTrue(
not hasattr(p,
"a"))
3300 self.assertEqual(p.b.fred.value(),3)
3304 mc = ModifierChain(m1,m2)
3305 mclone = mc.copyAndExclude([m2])
3306 self.assertTrue(
not mclone._isOrContains(m2))
3307 self.assertTrue(mclone._isOrContains(m1))
3309 mc2 = ModifierChain(mc,m3)
3310 mclone = mc2.copyAndExclude([m2])
3311 self.assertTrue(
not mclone._isOrContains(m2))
3312 self.assertTrue(mclone._isOrContains(m1))
3313 self.assertTrue(mclone._isOrContains(m3))
3317 p = Process(
"test",m1)
3318 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3319 (m1 & m2).toModify(p.a, fred = int32(2))
3320 self.assertRaises(TypeError,
lambda: (m1 & m2).toModify(p.a, 1, wilma=2))
3321 self.assertEqual(p.a.fred, 1)
3324 p = Process(
"test",m1,m2)
3325 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3326 (m1 & m2).toModify(p.a, fred = int32(2))
3327 self.assertEqual(p.a.fred, 2)
3331 p = Process(
"test",m1,m2,m3)
3332 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3333 (m1 & m2 & m3).toModify(p.a, fred = int32(2))
3334 self.assertEqual(p.a.fred, 2)
3335 (m1 & (m2 & m3)).toModify(p.a, fred = int32(3))
3336 self.assertEqual(p.a.fred, 3)
3337 ((m1 & m2) & m3).toModify(p.a, fred = int32(4))
3338 self.assertEqual(p.a.fred, 4)
3342 p = Process(
"test", m1)
3343 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3344 (~m1).toModify(p.a, fred=2)
3345 self.assertEqual(p.a.fred, 1)
3346 (~m2).toModify(p.a, wilma=2)
3347 self.assertEqual(p.a.wilma, 2)
3348 self.assertRaises(TypeError,
lambda: (~m1).toModify(p.a, 1, wilma=2))
3349 self.assertRaises(TypeError,
lambda: (~m2).toModify(p.a, 1, wilma=2))
3354 p = Process(
"test", m1)
3355 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3356 (m1 | m2).toModify(p.a, fred=2)
3357 self.assertEqual(p.a.fred, 2)
3358 (m1 | m2 | m3).toModify(p.a, fred=3)
3359 self.assertEqual(p.a.fred, 3)
3360 (m3 | m2 | m1).toModify(p.a, fred=4)
3361 self.assertEqual(p.a.fred, 4)
3362 ((m1 | m2) | m3).toModify(p.a, fred=5)
3363 self.assertEqual(p.a.fred, 5)
3364 (m1 | (m2 | m3)).toModify(p.a, fred=6)
3365 self.assertEqual(p.a.fred, 6)
3366 (m2 | m3).toModify(p.a, fred=7)
3367 self.assertEqual(p.a.fred, 6)
3368 self.assertRaises(TypeError,
lambda: (m1 | m2).toModify(p.a, 1, wilma=2))
3369 self.assertRaises(TypeError,
lambda: (m2 | m3).toModify(p.a, 1, wilma=2))
3375 p = Process(
"test", m1, m2)
3376 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3377 (m1 & ~m2).toModify(p.a, fred=2)
3378 self.assertEqual(p.a.fred, 1)
3379 (m1 & ~m3).toModify(p.a, fred=2)
3380 self.assertEqual(p.a.fred, 2)
3381 (m1 | ~m2).toModify(p.a, fred=3)
3382 self.assertEqual(p.a.fred, 3)
3383 (~m1 | ~m2).toModify(p.a, fred=4)
3384 self.assertEqual(p.a.fred, 3)
3385 (~m3 & ~m4).toModify(p.a, fred=4)
3386 self.assertEqual(p.a.fred, 4)
3387 ((m1 & m3) | ~m4).toModify(p.a, fred=5)
3388 self.assertEqual(p.a.fred, 5)
3391 p = Process(
"test",m1)
3392 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3393 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3394 self.assertRaises(TypeError,
lambda: m1.toReplaceWith(p.a, EDProducer(
"YourProducer")))
3395 p.b =EDAnalyzer(
"BAn")
3396 p.c =EDProducer(
"c")
3397 p.d =EDProducer(
"d")
3401 m1.toReplaceWith(p.s,
Sequence(p.a+p.b, p.td))
3402 self.assertEqual(p.a.wilma.value(),3)
3403 self.assertEqual(p.a.type_(),
"YourAnalyzer")
3404 self.assertEqual(hasattr(p,
"fred"),
False)
3405 self.assertTrue(p.s.dumpPython() ==
"cms.Sequence(process.a+process.b, process.td)\n")
3406 p.e =EDProducer(
"e")
3407 m1.toReplaceWith(p.td, Task(p.e))
3408 self.assertTrue(p.td._collection ==
OrderedSet([p.e]))
3412 p.a =EDAnalyzer(
"MyAnalyzer", fred = int32(1))
3413 m1.toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer", wilma = int32(3)))
3414 self.assertEqual(p.a.type_(),
"MyAnalyzer")
3420 p = Process(
"test", m1, m2)
3421 p.a = EDAnalyzer(
"MyAnalyzer", fred = int32(1), wilma = int32(1))
3422 self.assertRaises(TypeError,
lambda: (m1 & m2).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3423 self.assertRaises(TypeError,
lambda: (m3 & m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3424 self.assertRaises(TypeError,
lambda: (~m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3425 self.assertRaises(TypeError,
lambda: (~m1).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3426 self.assertRaises(TypeError,
lambda: (m1 | m3).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3427 self.assertRaises(TypeError,
lambda: (m3 | m4).toReplaceWith(p.a, EDProducer(
"YourProducer")))
3428 (m1 & m2).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer1"))
3429 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3430 (m1 & m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3431 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3432 (~m1).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3433 self.assertEqual(p.a.type_(),
"YourAnalyzer1")
3434 (~m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer2"))
3435 self.assertEqual(p.a.type_(),
"YourAnalyzer2")
3436 (m1 | m3).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer3"))
3437 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3438 (m3 | m4).toReplaceWith(p.a, EDAnalyzer(
"YourAnalyzer4"))
3439 self.assertEqual(p.a.type_(),
"YourAnalyzer3")
3442 a = EDAlias(foo2 =
VPSet(PSet(type =
string(
"Foo2"))))
3446 m.toModify(a, foo2 = {0: dict(type =
"Foo3")})
3447 self.assertEqual(a.foo2[0].type,
"Foo3")
3449 m.toModify(a, foo4 =
VPSet(PSet(type =
string(
"Foo4"))))
3450 self.assertEqual(a.foo2[0].type,
"Foo3")
3451 self.assertEqual(a.foo4[0].type,
"Foo4")
3453 m.toModify(a, foo2 =
None)
3454 self.assertFalse(hasattr(a,
"foo2"))
3455 self.assertEqual(a.foo4[0].type,
"Foo4")
3457 m.toReplaceWith(a, EDAlias(bar =
VPSet(PSet(type =
string(
"Bar")))))
3458 self.assertFalse(hasattr(a,
"foo2"))
3459 self.assertFalse(hasattr(a,
"foo4"))
3460 self.assertTrue(hasattr(a,
"bar"))
3461 self.assertEqual(a.bar[0].type,
"Bar")
3464 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
3466 b = PSet(c = int32(2))),
3467 test2 = EDProducer(
"Bar",
3469 bb = PSet(cc = int32(12))))
3474 test1 = dict(a = 4, b = dict(c =
None)),
3475 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
3476 self.assertEqual(sp.test1.a.value(), 4)
3477 self.assertEqual(sp.test1.b.hasParameter(
"c"),
False)
3478 self.assertEqual(sp.test2.aa.value(), 15)
3479 self.assertEqual(sp.test2.bb.cc.value(), 45)
3480 self.assertEqual(sp.test2.bb.dd.value(),
"foo")
3482 m.toReplaceWith(sp.test1, EDProducer(
"Fred", x = int32(42)))
3483 self.assertEqual(sp.test1.type_(),
"Fred")
3484 self.assertEqual(sp.test1.x.value(), 42)
3485 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test1, EDAnalyzer(
"Foo")))
3487 m.toModify(sp, test2 = EDProducer(
"Xyzzy", x = int32(24)))
3488 self.assertEqual(sp.test2.type_(),
"Xyzzy")
3489 self.assertEqual(sp.test2.x.value(), 24)
3490 self.assertRaises(TypeError,
lambda: m.toModify(sp, test2 = EDAnalyzer(
"Foo")))
3492 m.toModify(sp, test3 = EDProducer(
"Wilma", y = int32(24)))
3493 self.assertEqual(sp.test3.type_(),
"Wilma")
3494 self.assertEqual(sp.test3.y.value(), 24)
3495 self.assertRaises(TypeError,
lambda: m.toModify(sp, test4 = EDAnalyzer(
"Foo")))
3497 m.toModify(sp, test2 =
None)
3498 self.assertEqual(hasattr(sp,
"test2"),
False)
3500 m.toModify(sp, test2 = EDAlias(foo =
VPSet(PSet(type =
string(
"int")))))
3501 self.assertTrue(hasattr(sp.test2,
"foo"))
3503 m.toReplaceWith(sp.test2, EDAlias(bar =
VPSet(PSet(type =
string(
"int")))))
3504 self.assertTrue(hasattr(sp.test2,
"bar"))
3506 m.toModify(sp, test2 = EDAlias(xyzzy =
VPSet(PSet(type =
string(
"int")))))
3507 self.assertTrue(hasattr(sp.test2,
"xyzzy"))
3509 self.assertRaises(TypeError,
lambda: m.toReplaceWith(sp.test2, EDProducer(
"Foo")))
3510 m.toModify(sp, test2 = EDProducer(
"Foo"))