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

Member Function Documentation

◆ testEDAnalyzer()

def Modules.TestModules.testEDAnalyzer (   self)

Definition at line 451 of file Modules.py.

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

References Types.untracked.

◆ testESPrefer()

def Modules.TestModules.testESPrefer (   self)

Definition at line 465 of file Modules.py.

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

◆ testIsTaskComponent()

def Modules.TestModules.testIsTaskComponent (   self)

Definition at line 516 of file Modules.py.

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

◆ testSequences()

def Modules.TestModules.testSequences (   self)

Definition at line 508 of file Modules.py.

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

◆ testService()

def Modules.TestModules.testService (   self)

Definition at line 501 of file Modules.py.

501  def testService(self):
502  empty = Service("Empty")
503  withParam = Service("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
504  self.assertEqual(withParam.foo.value(), 1)
505  self.assertEqual(withParam.bar.value(), "it")
506  self.assertEqual(empty.dumpPython(), "cms.Service(\"Empty\")\n")
507  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 552 of file Modules.py.

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

◆ testSwithProducerWithAlias()

def Modules.TestModules.testSwithProducerWithAlias (   self)

Definition at line 659 of file Modules.py.

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