557 def testSwitchProducer(self):
559 sp = SwitchProducerTest(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
560 self.assertEqual(sp.test1.type_(),
"Foo")
561 self.assertEqual(sp.test2.type_(),
"Bar")
562 self.assertRaises(ValueError,
lambda: SwitchProducerTest(nonexistent = EDProducer(
"Foo")))
563 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = EDAnalyzer(
"Foo")))
564 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = EDFilter(
"Foo")))
565 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
Source(
"Foo")))
566 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = OutputModule(
"Foo")))
567 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = Looper(
"Foo")))
568 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
Service(
"Foo")))
569 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = ESSource(
"Foo")))
570 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 =
ESProducer(
"Foo")))
571 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = ESPrefer(
"Foo")))
572 self.assertRaises(TypeError,
lambda: SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo"))))
576 self.assertEqual(sp.label_(),
"sp")
577 self.assertEqual(sp.test1.label_(),
"sp@test1")
578 self.assertEqual(sp.test2.label_(),
"sp@test2")
579 sp.test3 = EDProducer(
"Xyzzy")
580 self.assertEqual(sp.test3.label_(),
"sp@test3")
581 sp.test1 = EDProducer(
"Fred")
582 self.assertEqual(sp.test1.label_(),
"sp@test1")
584 sp.test1 = EDProducer(
"Wilma")
585 self.assertEqual(sp.test1.label_(),
"sp@test1")
588 self.assertEqual(sp.label_(),
"other")
589 self.assertEqual(sp.test1.label_(),
"other@test1")
590 self.assertEqual(sp.test2.label_(),
"other@test2")
593 accelerators = [
"test1",
"test2",
"test3"]
594 sp = SwitchProducerTest(test1 = EDProducer(
"Foo"), test2 = EDProducer(
"Bar"))
595 self.assertEqual(sp._getProducer([
"test1",
"test2",
"test3"]).type_(),
"Bar")
596 self.assertEqual(sp._getProducer([
"test2",
"test3"]).type_(),
"Bar")
597 self.assertEqual(sp._getProducer([
"test1",
"test3"]).type_(),
"Foo")
598 sp = SwitchProducerTest(test1 = EDProducer(
"Bar"))
599 self.assertEqual(sp._getProducer([
"test1",
"test2",
"test3"]).type_(),
"Bar")
600 self.assertRaises(RuntimeError, sp._getProducer, [
"test2",
"test3"])
603 from .Types
import int32, string, PSet
604 sp = SwitchProducerTest(test1 = EDProducer(
"Foo",
606 b =
PSet(c = int32(2))),
607 test2 = EDProducer(
"Bar",
609 bb =
PSet(cc = int32(12))))
612 self.assertEqual(cl.test1.type_(),
"Foo")
613 self.assertEqual(cl.test1.a.value(), 1)
614 self.assertEqual(cl.test1.b.c.value(), 2)
615 self.assertEqual(cl.test2.type_(),
"Bar")
616 self.assertEqual(cl.test2.aa.value(), 11)
617 self.assertEqual(cl.test2.bb.cc.value(), 12)
618 self.assertEqual(sp._getProducer(accelerators).type_(),
"Bar")
621 self.assertEqual(cl.test1.a.value(), 3)
622 cl.test1 = EDProducer(
"Fred")
623 self.assertEqual(cl.test1.type_(),
"Fred")
624 def _assignEDAnalyzer():
625 cl.test1 = EDAnalyzer(
"Foo")
626 self.assertRaises(TypeError, _assignEDAnalyzer)
627 def _assignSwitchProducer():
628 cl.test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo")))
629 self.assertRaises(TypeError, _assignSwitchProducer)
631 cl = sp.clone(test1 = dict(a = 4, b = dict(c =
None)),
632 test2 = dict(aa = 15, bb = dict(cc = 45, dd =
string(
"foo"))))
633 self.assertEqual(cl.test1.a.value(), 4)
634 self.assertEqual(cl.test1.b.hasParameter(
"c"),
False)
635 self.assertEqual(cl.test2.aa.value(), 15)
636 self.assertEqual(cl.test2.bb.cc.value(), 45)
637 self.assertEqual(cl.test2.bb.dd.value(),
"foo")
639 cl = sp.clone(test1 = EDProducer(
"Fred", x = int32(42)),
640 test3 = EDProducer(
"Wilma", y = int32(24)),
642 self.assertEqual(cl.test1.type_(),
"Fred")
643 self.assertEqual(cl.test1.x.value(), 42)
644 self.assertEqual(cl.test3.type_(),
"Wilma")
645 self.assertEqual(cl.test3.y.value(), 24)
646 self.assertEqual(hasattr(cl,
"test2"),
False)
647 self.assertRaises(TypeError,
lambda: sp.clone(test1 = EDAnalyzer(
"Foo")))
648 self.assertRaises(TypeError,
lambda: sp.clone(test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer(
"Foo")))))
651 sp = SwitchProducerTest(test2 = EDProducer(
"Foo",
653 b =
PSet(c = int32(2))),
654 test1 = EDProducer(
"Bar",
656 bb =
PSet(cc = int32(12))))
657 self.assertEqual(sp.dumpPython(),
658 """SwitchProducerTest( 659 test1 = cms.EDProducer("Bar", 665 test2 = cms.EDProducer("Foo", 675 sp = SwitchProducerPickleable(cpu = EDProducer(
"Foo"))
676 pkl = pickle.dumps(sp)
677 unpkl = pickle.loads(pkl)
678 self.assertEqual(unpkl.cpu.type_(),
"Foo")