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

Member Function Documentation

def Modules.TestModules.testEDAnalyzer (   self)

Definition at line 447 of file Modules.py.

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

Definition at line 461 of file Modules.py.

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

Definition at line 512 of file Modules.py.

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

Definition at line 504 of file Modules.py.

504  def testSequences(self):
505  m = EDProducer("MProducer")
506  n = EDProducer("NProducer")
507  m.setLabel("m")
508  n.setLabel("n")
509  s1 = Sequence(m*n)
510  options = PrintOptions()
511 
def testSequences(self)
Definition: Modules.py:504
def Modules.TestModules.testService (   self)

Definition at line 497 of file Modules.py.

497  def testService(self):
498  empty = Service("Empty")
499  withParam = Service("Parameterized",foo=untracked(int32(1)), bar = untracked(string("it")))
500  self.assertEqual(withParam.foo.value(), 1)
501  self.assertEqual(withParam.bar.value(), "it")
502  self.assertEqual(empty.dumpPython(), "cms.Service(\"Empty\")\n")
503  self.assertEqual(withParam.dumpPython(), "cms.Service(\"Parameterized\",\n bar = cms.untracked.string(\'it\'),\n foo = cms.untracked.int32(1)\n)\n")
def testService(self)
Definition: Modules.py:497
def Modules.TestModules.testSwitchProducer (   self)

Definition at line 548 of file Modules.py.

References cmsPerfStripChart.dict.

549  # Constructor
550  sp = SwitchProducerTest(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
551  self.assertEqual(sp.test1.type_(), "Foo")
552  self.assertEqual(sp.test2.type_(), "Bar")
553  self.assertRaises(ValueError, lambda: SwitchProducerTest(nonexistent = EDProducer("Foo")))
554  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = EDAnalyzer("Foo")))
555  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = EDFilter("Foo")))
556  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = Source("Foo")))
557  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = OutputModule("Foo")))
558  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = Looper("Foo")))
559  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = Service("Foo")))
560  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = ESSource("Foo")))
561  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = ESProducer("Foo")))
562  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = ESPrefer("Foo")))
563  self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer("Foo"))))
564 
565  # Case decision
566  sp = SwitchProducerTest(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
567  self.assertEqual(sp._getProducer().type_(), "Bar")
568  sp = SwitchProducerTest1Dis(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
569  self.assertEqual(sp._getProducer().type_(), "Bar")
570  sp = SwitchProducerTest2Dis(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
571  self.assertEqual(sp._getProducer().type_(), "Foo")
572  sp = SwitchProducerTest(test1 = EDProducer("Bar"))
573  self.assertEqual(sp._getProducer().type_(), "Bar")
574  sp = SwitchProducerTest1Dis(test1 = EDProducer("Bar"))
575  self.assertRaises(RuntimeError, sp._getProducer)
576 
577  # Mofications
578  from .Types import int32, string, PSet
579  sp = SwitchProducerTest(test1 = EDProducer("Foo",
580  a = int32(1),
581  b = PSet(c = int32(2))),
582  test2 = EDProducer("Bar",
583  aa = int32(11),
584  bb = PSet(cc = int32(12))))
585  # Simple clone
586  cl = sp.clone()
587  self.assertEqual(cl.test1.type_(), "Foo")
588  self.assertEqual(cl.test1.a.value(), 1)
589  self.assertEqual(cl.test1.b.c.value(), 2)
590  self.assertEqual(cl.test2.type_(), "Bar")
591  self.assertEqual(cl.test2.aa.value(), 11)
592  self.assertEqual(cl.test2.bb.cc.value(), 12)
593  self.assertEqual(sp._getProducer().type_(), "Bar")
594  # Modify clone
595  cl.test1.a = 3
596  self.assertEqual(cl.test1.a.value(), 3)
597  cl.test1 = EDProducer("Fred")
598  self.assertEqual(cl.test1.type_(), "Fred")
599  def _assignEDAnalyzer():
600  cl.test1 = EDAnalyzer("Foo")
601  self.assertRaises(TypeError, _assignEDAnalyzer)
602  def _assignSwitchProducer():
603  cl.test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer("Foo")))
604  self.assertRaises(TypeError, _assignSwitchProducer)
605  # Modify values with a dict
606  cl = sp.clone(test1 = dict(a = 4, b = dict(c = None)),
607  test2 = dict(aa = 15, bb = dict(cc = 45, dd = string("foo"))))
608  self.assertEqual(cl.test1.a.value(), 4)
609  self.assertEqual(cl.test1.b.hasParameter("c"), False)
610  self.assertEqual(cl.test2.aa.value(), 15)
611  self.assertEqual(cl.test2.bb.cc.value(), 45)
612  self.assertEqual(cl.test2.bb.dd.value(), "foo")
613  # Replace/add/remove EDProducers
614  cl = sp.clone(test1 = EDProducer("Fred", x = int32(42)),
615  test3 = EDProducer("Wilma", y = int32(24)),
616  test2 = None)
617  self.assertEqual(cl.test1.type_(), "Fred")
618  self.assertEqual(cl.test1.x.value(), 42)
619  self.assertEqual(cl.test3.type_(), "Wilma")
620  self.assertEqual(cl.test3.y.value(), 24)
621  self.assertEqual(hasattr(cl, "test2"), False)
622  self.assertRaises(TypeError, lambda: sp.clone(test1 = EDAnalyzer("Foo")))
623  self.assertRaises(TypeError, lambda: sp.clone(test1 = SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer("Foo")))))
624 
625  # Dump
626  sp = SwitchProducerTest(test2 = EDProducer("Foo",
627  a = int32(1),
628  b = PSet(c = int32(2))),
629  test1 = EDProducer("Bar",
630  aa = int32(11),
631  bb = PSet(cc = int32(12))))
632  self.assertEqual(sp.dumpPython(),
633 """SwitchProducerTest(
634  test1 = cms.EDProducer("Bar",
635  aa = cms.int32(11),
636  bb = cms.PSet(
637  cc = cms.int32(12)
638  )
639  ),
640  test2 = cms.EDProducer("Foo",
641  a = cms.int32(1),
642  b = cms.PSet(
643  c = cms.int32(2)
644  )
645  )
646 )
647 """)
648  # Pickle
649  import pickle
650  sp = SwitchProducerPickleable(cpu = EDProducer("Foo"))
651  pkl = pickle.dumps(sp)
652  unpkl = pickle.loads(pkl)
653  self.assertEqual(unpkl.cpu.type_(), "Foo")
654 
def testSwitchProducer(self)
Definition: Modules.py:548
def Modules.TestModules.testSwithProducerWithAlias (   self)

Definition at line 655 of file Modules.py.

References cmsPerfStripChart.dict.

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