CMS 3D CMS Logo

List of all members | Public Member Functions
Modules.TestModules Class Reference
Inheritance diagram for Modules.TestModules:

Public Member Functions

def testEDAnalyzer (self)
 
def testESPrefer (self)
 
def testIsTaskComponent (self)
 
def testSequences (self)
 
def testService (self)
 
def testSwitchProducer (self)
 
def testSwithProducerWithAlias (self)
 

Detailed Description

Definition at line 455 of file Modules.py.

Member Function Documentation

◆ testEDAnalyzer()

def Modules.TestModules.testEDAnalyzer (   self)

Definition at line 456 of file Modules.py.

References Types.untracked.

456  def testEDAnalyzer(self):
457  empty = EDAnalyzer("Empty")
458  withParam = EDAnalyzer("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
459  self.assertEqual(withParam.foo.value(), 1)
460  self.assertEqual(withParam.bar.value(), "it")
461  aCopy = withParam.copy()
462  self.assertEqual(aCopy.foo.value(), 1)
463  self.assertEqual(aCopy.bar.value(), "it")
464  withType = EDAnalyzer("Test",type = int32(1))
465  self.assertEqual(withType.type.value(),1)
466  block = PSet(i = int32(9))
467  m = EDProducer("DumbProducer", block, j = int32(10))
468  self.assertEqual(9, m.i.value())
469  self.assertEqual(10, m.j.value())
untracked
Definition: Types.py:34

◆ testESPrefer()

def Modules.TestModules.testESPrefer (   self)

Definition at line 470 of file Modules.py.

470  def testESPrefer(self):
471  juicer = ESPrefer("JuiceProducer")
472  options = PrintOptions()
473  options.isCfg = True
474  self.assertEqual(juicer.dumpPythonAs("juicer", options), "process.prefer(\"JuiceProducer\")\n")
475  options.isCfg = False
476  self.assertEqual(juicer.dumpPythonAs("juicer", options), "es_prefer_JuiceProducer = cms.ESPrefer(\"JuiceProducer\")\n")
477 
478  juicer = ESPrefer("JuiceProducer","juicer")
479  options = PrintOptions()
480  options.isCfg = True
481  self.assertEqual(juicer.dumpPythonAs("juicer", options), 'process.prefer("juicer")\n')
482  options.isCfg = False
483  self.assertEqual(juicer.dumpPythonAs("juicer", options), 'es_prefer_juicer = cms.ESPrefer("JuiceProducer","juicer")\n')
484  juicer = ESPrefer("JuiceProducer",fooRcd=vstring())
485  self.assertEqual(juicer.dumpConfig(options),
486 """JuiceProducer {
487  vstring fooRcd = {
488  }
489 
490 }
491 """)
492  options = PrintOptions()
493  options.isCfg = True
494  self.assertEqual(juicer.dumpPythonAs("juicer"),
495 """process.prefer("JuiceProducer",
496  fooRcd = cms.vstring()
497 )
498 """)
499  options.isCfg = False
500  self.assertEqual(juicer.dumpPythonAs("juicer", options),
501 """es_prefer_JuiceProducer = cms.ESPrefer("JuiceProducer",
502  fooRcd = cms.vstring()
503 )
504 """)
505 

◆ testIsTaskComponent()

def Modules.TestModules.testIsTaskComponent (   self)

Definition at line 521 of file Modules.py.

521  def testIsTaskComponent(self):
522  m = EDProducer("x")
523  self.assertTrue(m._isTaskComponent())
524  self.assertTrue(m.isLeaf())
525  m = SwitchProducerTest(test1=EDProducer("x"))
526  self.assertTrue(m._isTaskComponent())
527  self.assertTrue(m.isLeaf())
528  m = EDFilter("x")
529  self.assertTrue(m._isTaskComponent())
530  self.assertTrue(m.isLeaf())
531  m = OutputModule("x")
532  self.assertFalse(m._isTaskComponent())
533  self.assertTrue(m.isLeaf())
534  m = EDAnalyzer("x")
535  self.assertFalse(m._isTaskComponent())
536  self.assertTrue(m.isLeaf())
537  m = Service("x")
538  self.assertTrue(m._isTaskComponent())
539  self.assertTrue(m.isLeaf())
540  m = ESProducer("x")
541  self.assertTrue(m._isTaskComponent())
542  self.assertTrue(m.isLeaf())
543  m = ESSource("x")
544  self.assertTrue(m._isTaskComponent())
545  self.assertTrue(m.isLeaf())
546  m = Sequence()
547  self.assertFalse(m._isTaskComponent())
548  self.assertFalse(m.isLeaf())
549  m = Path()
550  self.assertFalse(m._isTaskComponent())
551  m = EndPath()
552  self.assertFalse(m._isTaskComponent())
553  m = Task()
554  self.assertTrue(m._isTaskComponent())
555  self.assertFalse(m.isLeaf())
556 

◆ testSequences()

def Modules.TestModules.testSequences (   self)

Definition at line 513 of file Modules.py.

513  def testSequences(self):
514  m = EDProducer("MProducer")
515  n = EDProducer("NProducer")
516  m.setLabel("m")
517  n.setLabel("n")
518  s1 = Sequence(m*n)
519  options = PrintOptions()
520 

◆ testService()

def Modules.TestModules.testService (   self)

Definition at line 506 of file Modules.py.

References Types.untracked.

506  def testService(self):
507  empty = Service("Empty")
508  withParam = Service("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
509  self.assertEqual(withParam.foo.value(), 1)
510  self.assertEqual(withParam.bar.value(), "it")
511  self.assertEqual(empty.dumpPython(), "cms.Service(\"Empty\")\n")
512  self.assertEqual(withParam.dumpPython(), "cms.Service(\"Parameterized\",\n bar = cms.untracked.string(\'it\'),\n foo = cms.untracked.int32(1)\n)\n")
untracked
Definition: Types.py:34

◆ testSwitchProducer()

def Modules.TestModules.testSwitchProducer (   self)

Definition at line 557 of file Modules.py.

557  def testSwitchProducer(self):
558  # Constructor
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"))))
573 
574  # Label
575  sp.setLabel("sp")
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")
583  del sp.test1
584  sp.test1 = EDProducer("Wilma")
585  self.assertEqual(sp.test1.label_(), "sp@test1")
586  sp.setLabel(None)
587  sp.setLabel("other")
588  self.assertEqual(sp.label_(), "other")
589  self.assertEqual(sp.test1.label_(), "other@test1")
590  self.assertEqual(sp.test2.label_(), "other@test2")
591 
592  # Case decision
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"])
601 
602  # Mofications
603  from .Types import int32, string, PSet
604  sp = SwitchProducerTest(test1 = EDProducer("Foo",
605  a = int32(1),
606  b = PSet(c = int32(2))),
607  test2 = EDProducer("Bar",
608  aa = int32(11),
609  bb = PSet(cc = int32(12))))
610  # Simple clone
611  cl = sp.clone()
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")
619  # Modify clone
620  cl.test1.a = 3
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)
630  # Modify values with a dict
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")
638  # Replace/add/remove EDProducers
639  cl = sp.clone(test1 = EDProducer("Fred", x = int32(42)),
640  test3 = EDProducer("Wilma", y = int32(24)),
641  test2 = None)
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")))))
649 
650  # Dump
651  sp = SwitchProducerTest(test2 = EDProducer("Foo",
652  a = int32(1),
653  b = PSet(c = int32(2))),
654  test1 = EDProducer("Bar",
655  aa = int32(11),
656  bb = PSet(cc = int32(12))))
657  self.assertEqual(sp.dumpPython(),
658 """SwitchProducerTest(
659  test1 = cms.EDProducer("Bar",
660  aa = cms.int32(11),
661  bb = cms.PSet(
662  cc = cms.int32(12)
663  )
664  ),
665  test2 = cms.EDProducer("Foo",
666  a = cms.int32(1),
667  b = cms.PSet(
668  c = cms.int32(2)
669  )
670  )
671 )
672 """)
673  # Pickle
674  import pickle
675  sp = SwitchProducerPickleable(cpu = EDProducer("Foo"))
676  pkl = pickle.dumps(sp)
677  unpkl = pickle.loads(pkl)
678  self.assertEqual(unpkl.cpu.type_(), "Foo")
679 

◆ testSwithProducerWithAlias()

def Modules.TestModules.testSwithProducerWithAlias (   self)

Definition at line 680 of file Modules.py.

680  def testSwithProducerWithAlias(self):
681  # Constructor
682  sp = SwitchProducerTest(test1 = EDProducer("Foo"), test2 = EDAlias())
683  self.assertEqual(sp.test1.type_(), "Foo")
684  self.assertTrue(isinstance(sp.test2, EDAlias))
685 
686  # Modifications
687  from .Types import int32, string, PSet, VPSet
688  sp = SwitchProducerTest(test1 = EDProducer("Foo"),
689  test2 = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
690 
691  # Simple clone
692  cl = sp.clone()
693  self.assertTrue(hasattr(cl.test2, "foo"))
694  # Modify clone
695  cl.test2.foo[0].type = "Foo3"
696  self.assertEqual(cl.test2.foo[0].type, "Foo3")
697  # Modify values with a dict
698  cl = sp.clone(test2 = dict(foo = {0: dict(type = "Foo4")}))
699  self.assertEqual(cl.test2.foo[0].type, "Foo4")
700  # Replace or add EDAlias
701  cl = sp.clone(test1 = EDAlias(foo = VPSet(PSet(type = string("Foo5")))),
702  test3 = EDAlias(foo = VPSet(PSet(type = string("Foo6")))))
703  self.assertEqual(cl.test1.foo[0].type, "Foo5")
704  self.assertEqual(cl.test3.foo[0].type, "Foo6")
705  # Modify clone
706  cl.test1 = EDProducer("Xyzzy")
707  self.assertEqual(cl.test1.type_(), "Xyzzy")
708  cl.test1 = EDAlias(foo = VPSet(PSet(type = string("Foo7"))))
709  self.assertEqual(cl.test1.foo[0].type, "Foo7")
710 
711 
712  # Dump
713  from .Types import int32, string, PSet, VPSet
714  sp = SwitchProducerTest(test1 = EDProducer("Foo"),
715  test2 = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
716 
717  self.assertEqual(sp.dumpPython(),
718 """SwitchProducerTest(
719  test1 = cms.EDProducer("Foo"),
720  test2 = cms.EDAlias(
721  foo = cms.VPSet(cms.PSet(
722  type = cms.string('Foo2')
723  ))
724  )
725 )
726 """)
727 
728  # Pickle
729  import pickle
730  sp = SwitchProducerPickleable(cpu = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
731  pkl = pickle.dumps(sp)
732  unpkl = pickle.loads(pkl)
733  self.assertEqual(sp.cpu.foo[0].type, "Foo2")
734  unittest.main()