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 449 of file Modules.py.

Member Function Documentation

◆ testEDAnalyzer()

def Modules.TestModules.testEDAnalyzer (   self)

Definition at line 450 of file Modules.py.

450  def testEDAnalyzer(self):
451  empty = EDAnalyzer("Empty")
452  withParam = EDAnalyzer("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
453  self.assertEqual(withParam.foo.value(), 1)
454  self.assertEqual(withParam.bar.value(), "it")
455  aCopy = withParam.copy()
456  self.assertEqual(aCopy.foo.value(), 1)
457  self.assertEqual(aCopy.bar.value(), "it")
458  withType = EDAnalyzer("Test",type = int32(1))
459  self.assertEqual(withType.type.value(),1)
460  block = PSet(i = int32(9))
461  m = EDProducer("DumbProducer", block, j = int32(10))
462  self.assertEqual(9, m.i.value())
463  self.assertEqual(10, m.j.value())

References Types.untracked.

◆ testESPrefer()

def Modules.TestModules.testESPrefer (   self)

Definition at line 464 of file Modules.py.

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

◆ testIsTaskComponent()

def Modules.TestModules.testIsTaskComponent (   self)

Definition at line 515 of file Modules.py.

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

◆ testSequences()

def Modules.TestModules.testSequences (   self)

Definition at line 507 of file Modules.py.

507  def testSequences(self):
508  m = EDProducer("MProducer")
509  n = EDProducer("NProducer")
510  m.setLabel("m")
511  n.setLabel("n")
512  s1 = Sequence(m*n)
513  options = PrintOptions()
514 

◆ testService()

def Modules.TestModules.testService (   self)

Definition at line 500 of file Modules.py.

500  def testService(self):
501  empty = Service("Empty")
502  withParam = Service("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
503  self.assertEqual(withParam.foo.value(), 1)
504  self.assertEqual(withParam.bar.value(), "it")
505  self.assertEqual(empty.dumpPython(), "cms.Service(\"Empty\")\n")
506  self.assertEqual(withParam.dumpPython(), "cms.Service(\"Parameterized\",\n bar = cms.untracked.string(\'it\'),\n foo = cms.untracked.int32(1)\n)\n")

References Types.untracked.

◆ testSwitchProducer()

def Modules.TestModules.testSwitchProducer (   self)

Definition at line 551 of file Modules.py.

551  def testSwitchProducer(self):
552  # Constructor
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"))))
567 
568  # Case decision
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)
579 
580  # Mofications
581  from .Types import int32, string, PSet
582  sp = SwitchProducerTest(test1 = EDProducer("Foo",
583  a = int32(1),
584  b = PSet(c = int32(2))),
585  test2 = EDProducer("Bar",
586  aa = int32(11),
587  bb = PSet(cc = int32(12))))
588  # Simple clone
589  cl = sp.clone()
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")
597  # Modify clone
598  cl.test1.a = 3
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)
608  # Modify values with a dict
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")
616  # Replace/add/remove EDProducers
617  cl = sp.clone(test1 = EDProducer("Fred", x = int32(42)),
618  test3 = EDProducer("Wilma", y = int32(24)),
619  test2 = None)
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")))))
627 
628  # Dump
629  sp = SwitchProducerTest(test2 = EDProducer("Foo",
630  a = int32(1),
631  b = PSet(c = int32(2))),
632  test1 = EDProducer("Bar",
633  aa = int32(11),
634  bb = PSet(cc = int32(12))))
635  self.assertEqual(sp.dumpPython(),
636 """SwitchProducerTest(
637  test1 = cms.EDProducer("Bar",
638  aa = cms.int32(11),
639  bb = cms.PSet(
640  cc = cms.int32(12)
641  )
642  ),
643  test2 = cms.EDProducer("Foo",
644  a = cms.int32(1),
645  b = cms.PSet(
646  c = cms.int32(2)
647  )
648  )
649 )
650 """)
651  # Pickle
652  import pickle
653  sp = SwitchProducerPickleable(cpu = EDProducer("Foo"))
654  pkl = pickle.dumps(sp)
655  unpkl = pickle.loads(pkl)
656  self.assertEqual(unpkl.cpu.type_(), "Foo")
657 

◆ testSwithProducerWithAlias()

def Modules.TestModules.testSwithProducerWithAlias (   self)

Definition at line 658 of file Modules.py.

658  def testSwithProducerWithAlias(self):
659  # Constructor
660  sp = SwitchProducerTest(test1 = EDProducer("Foo"), test2 = EDAlias())
661  self.assertEqual(sp.test1.type_(), "Foo")
662  self.assertTrue(isinstance(sp.test2, EDAlias))
663 
664  # Modifications
665  from .Types import int32, string, PSet, VPSet
666  sp = SwitchProducerTest(test1 = EDProducer("Foo"),
667  test2 = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
668 
669  # Simple clone
670  cl = sp.clone()
671  self.assertTrue(hasattr(cl.test2, "foo"))
672  # Modify clone
673  cl.test2.foo[0].type = "Foo3"
674  self.assertEqual(cl.test2.foo[0].type, "Foo3")
675  # Modify values with a dict
676  cl = sp.clone(test2 = dict(foo = {0: dict(type = "Foo4")}))
677  self.assertEqual(cl.test2.foo[0].type, "Foo4")
678  # Replace or add EDAlias
679  cl = sp.clone(test1 = EDAlias(foo = VPSet(PSet(type = string("Foo5")))),
680  test3 = EDAlias(foo = VPSet(PSet(type = string("Foo6")))))
681  self.assertEqual(cl.test1.foo[0].type, "Foo5")
682  self.assertEqual(cl.test3.foo[0].type, "Foo6")
683  # Modify clone
684  cl.test1 = EDProducer("Xyzzy")
685  self.assertEqual(cl.test1.type_(), "Xyzzy")
686  cl.test1 = EDAlias(foo = VPSet(PSet(type = string("Foo7"))))
687  self.assertEqual(cl.test1.foo[0].type, "Foo7")
688 
689 
690  # Dump
691  from .Types import int32, string, PSet, VPSet
692  sp = SwitchProducerTest(test1 = EDProducer("Foo"),
693  test2 = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
694 
695  self.assertEqual(sp.dumpPython(),
696 """SwitchProducerTest(
697  test1 = cms.EDProducer("Foo"),
698  test2 = cms.EDAlias(
699  foo = cms.VPSet(cms.PSet(
700  type = cms.string('Foo2')
701  ))
702  )
703 )
704 """)
705 
706  # Pickle
707  import pickle
708  sp = SwitchProducerPickleable(cpu = EDAlias(foo = VPSet(PSet(type = string("Foo2")))))
709  pkl = pickle.dumps(sp)
710  unpkl = pickle.loads(pkl)
711  self.assertEqual(sp.cpu.foo[0].type, "Foo2")
712  unittest.main()
mixOne_cfi.ESProducer
ESProducer
Definition: mixOne_cfi.py:33
Service
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HistogramManager_cfi.VPSet
def VPSet(*args)
Definition: HistogramManager_cfi.py:404
mps_fire.Path
Path
Definition: mps_fire.py:298
Types.untracked
untracked
Definition: Types.py:34
cmsswSequenceInfo.Sequence
Sequence
Definition: cmsswSequenceInfo.py:14
CollectionTags_cfi.Source
Source
Definition: CollectionTags_cfi.py:11