552 def testSwitchProducer(self):
554 sp = SwitchProducerTest(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
555 self.assertEqual(sp.test1.type_(),
"Foo")
556 self.assertEqual(sp.test2.type_(),
"Bar")
557 self.assertRaises(ValueError,
lambda: SwitchProducerTest(nonexistent = EDProducer(
"Foo")))
558 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = EDAnalyzer(
"Foo")))
559 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = EDFilter(
"Foo")))
560 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
Source(
"Foo")))
561 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = OutputModule(
"Foo")))
562 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = Looper(
"Foo")))
563 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
Service(
"Foo")))
564 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = ESSource(
"Foo")))
565 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
ESProducer(
"Foo")))
566 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = ESPrefer(
"Foo")))
567 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo"))))
570 sp = SwitchProducerTest(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
571 self.assertEqual(sp._getProducer().type_(),
"Bar")
572 sp = SwitchProducerTest1Dis(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
573 self.assertEqual(sp._getProducer().type_(),
"Bar")
574 sp = SwitchProducerTest2Dis(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
575 self.assertEqual(sp._getProducer().type_(),
"Foo")
576 sp = SwitchProducerTest(test1 = EDProducer(
"Bar"))
577 self.assertEqual(sp._getProducer().type_(),
"Bar")
578 sp = SwitchProducerTest1Dis(test1 = EDProducer(
"Bar"))
579 self.assertRaises(RuntimeError, sp._getProducer)
582 from .Types
import int32, string, PSet
583 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
585 b = PSet(c = int32(2))),
586 test2 = EDProducer(
"Bar",
588 bb = PSet(cc = int32(12))))
591 self.assertEqual(cl.test1.type_(),
"Foo")
592 self.assertEqual(cl.test1.a.value(), 1)
593 self.assertEqual(cl.test1.b.c.value(), 2)
594 self.assertEqual(cl.test2.type_(),
"Bar")
595 self.assertEqual(cl.test2.aa.value(), 11)
596 self.assertEqual(cl.test2.bb.cc.value(), 12)
597 self.assertEqual(sp._getProducer().type_(),
"Bar")
600 self.assertEqual(cl.test1.a.value(), 3)
601 cl.test1 = EDProducer(
"Fred")
602 self.assertEqual(cl.test1.type_(),
"Fred")
603 def _assignEDAnalyzer():
604 cl.test1 = EDAnalyzer(
"Foo")
605 self.assertRaises(TypeError, _assignEDAnalyzer)
606 def _assignSwitchProducer():
607 cl.test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo")))
608 self.assertRaises(TypeError, _assignSwitchProducer)
610 cl = sp.clone(test1 = dict(a = 4, b = dict(c =
None)),
611 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
612 self.assertEqual(cl.test1.a.value(), 4)
613 self.assertEqual(cl.test1.b.hasParameter(
"c"),
False)
614 self.assertEqual(cl.test2.aa.value(), 15)
615 self.assertEqual(cl.test2.bb.cc.value(), 45)
616 self.assertEqual(cl.test2.bb.dd.value(),
"foo")
618 cl = sp.clone(test1 = EDProducer(
"Fred", x = int32(42)),
619 test3 = EDProducer(
"Wilma", y = int32(24)),
621 self.assertEqual(cl.test1.type_(),
"Fred")
622 self.assertEqual(cl.test1.x.value(), 42)
623 self.assertEqual(cl.test3.type_(),
"Wilma")
624 self.assertEqual(cl.test3.y.value(), 24)
625 self.assertEqual(hasattr(cl,
"test2"),
False)
626 self.assertRaises(TypeError,
lambda: sp.clone(test1 = EDAnalyzer(
"Foo")))
627 self.assertRaises(TypeError,
lambda: sp.clone(test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo")))))
630 sp = SwitchProducerTest(test2 = EDProducer(
"Foo",
632 b = PSet(c = int32(2))),
633 test1 = EDProducer(
"Bar",
635 bb = PSet(cc = int32(12))))
636 self.assertEqual(sp.dumpPython(),
637 """SwitchProducerTest(
638 test1 = cms.EDProducer("Bar",
644 test2 = cms.EDProducer("Foo",
654 sp = SwitchProducerPickleable(cpu = EDProducer(
"Foo"))
655 pkl = pickle.dumps(sp)
656 unpkl = pickle.loads(pkl)
657 self.assertEqual(unpkl.cpu.type_(),
"Foo")