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