CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
Mixins.testMixins Class Reference
Inheritance diagram for Mixins.testMixins:

Public Member Functions

def testClone (self)
 
def testConstruction (self)
 
def testCopy (self)
 
def testLargeList (self)
 
def testLargeParameterizable (self)
 
def testListConstruction (self)
 
def testModified (self)
 
def testSpecialImportRegistry (self)
 
def testUsingBlock (self)
 

Public Attributes

 TestList
 
 tLPTest
 
 tLPTestType
 

Detailed Description

Definition at line 759 of file Mixins.py.

Member Function Documentation

◆ testClone()

def Mixins.testMixins.testClone (   self)

Definition at line 837 of file Mixins.py.

837  def testClone(self):
838  class __Test(_TypedParameterizable):
839  pass
840  class __TestType(_SimpleParameterTypeBase):
841  def _isValid(self,value):
842  return True
843  class __PSet(_ParameterTypeBase,_Parameterizable):
844  def __init__(self,*arg,**args):
845  #need to call the inits separately
846  _ParameterTypeBase.__init__(self)
847  _Parameterizable.__init__(self,*arg,**args)
848  def dumpPython(self,options=PrintOptions()):
849  return "__PSet(\n"+_Parameterizable.dumpPython(self, options)+options.indentation()+")"
850 
851  a = __Test("MyType",
852  t=__TestType(1),
853  u=__TestType(2),
854  w = __TestType(3),
855  x = __PSet(a = __TestType(4),
856  b = __TestType(6),
857  c = __PSet(gamma = __TestType(5))))
858  b = a.clone(t=3,
859  v=__TestType(4),
860  w= None,
861  x = dict(a = 7,
862  c = dict(gamma = 8),
863  d = __TestType(9)))
864  c = a.clone(x = dict(a=None, c=None))
865  self.assertEqual(a.t.value(),1)
866  self.assertEqual(a.u.value(),2)
867  self.assertEqual(b.t.value(),3)
868  self.assertEqual(b.u.value(),2)
869  self.assertEqual(b.v.value(),4)
870  self.assertEqual(b.x.a.value(),7)
871  self.assertEqual(b.x.b.value(),6)
872  self.assertEqual(b.x.c.gamma.value(),8)
873  self.assertEqual(b.x.d.value(),9)
874  self.assertEqual(hasattr(b,"w"), False)
875  self.assertEqual(hasattr(c.x,"a"), False)
876  self.assertEqual(hasattr(c.x,"c"), False)
877  self.assertRaises(TypeError,a.clone,**{"v":1})
878  d = a.clone(__PSet(k=__TestType(42)))
879  self.assertEqual(d.t.value(), 1)
880  self.assertEqual(d.k.value(), 42)
881  d2 = a.clone(__PSet(t=__TestType(42)))
882  self.assertEqual(d2.t.value(), 42)
883  d3 = a.clone(__PSet(t=__TestType(42)),
884  __PSet(u=__TestType(56)))
885  self.assertEqual(d3.t.value(), 42)
886  self.assertEqual(d3.u.value(), 56)
887  self.assertRaises(ValueError,a.clone,
888  __PSet(t=__TestType(42)),
889  __PSet(t=__TestType(56)))
890  d4 = a.clone(__PSet(t=__TestType(43)), u = 57)
891  self.assertEqual(d4.t.value(), 43)
892  self.assertEqual(d4.u.value(), 57)
893  self.assertRaises(TypeError,a.clone,t=__TestType(43),**{"doesNotExist":57})
894 
895  e = __Test("MyType")
896  self.assertEqual(len(e.parameterNames_()), 0)
897  f = e.clone(__PSet(a = __TestType(1)), b = __TestType(2))
898  self.assertEqual(f.a.value(), 1)
899  self.assertEqual(f.b.value(), 2)
900  g = e.clone()
901  self.assertEqual(len(g.parameterNames_()), 0)
902 

◆ testConstruction()

def Mixins.testMixins.testConstruction (   self)

Definition at line 803 of file Mixins.py.

803  def testConstruction(self):
804  class __Test(_TypedParameterizable):
805  pass
806  class __TestType(_SimpleParameterTypeBase):
807  def _isValid(self,value):
808  return True
809  class __PSet(_ParameterTypeBase,_Parameterizable):
810  def __init__(self,*arg,**args):
811  #need to call the inits separately
812  _ParameterTypeBase.__init__(self)
813  _Parameterizable.__init__(self,*arg,**args)
814 
815  a = __Test("MyType", __PSet(a=__TestType(1)))
816  self.assertEqual(a.a.value(), 1)
817  b = __Test("MyType", __PSet(a=__TestType(1)), __PSet(b=__TestType(2)))
818  self.assertEqual(b.a.value(), 1)
819  self.assertEqual(b.b.value(), 2)
820  self.assertRaises(ValueError, lambda: __Test("MyType", __PSet(a=__TestType(1)), __PSet(a=__TestType(2))))
821 

◆ testCopy()

def Mixins.testMixins.testCopy (   self)

Definition at line 822 of file Mixins.py.

822  def testCopy(self):
823  class __Test(_TypedParameterizable):
824  pass
825  class __TestType(_SimpleParameterTypeBase):
826  def _isValid(self,value):
827  return True
828  a = __Test("MyType",t=__TestType(1), u=__TestType(2))
829  b = a.copy()
830  self.assertEqual(b.t.value(),1)
831  self.assertEqual(b.u.value(),2)
832 
833  c = __Test("MyType")
834  self.assertEqual(len(c.parameterNames_()), 0)
835  d = c.copy()
836  self.assertEqual(len(d.parameterNames_()), 0)

◆ testLargeList()

def Mixins.testMixins.testLargeList (   self)

Definition at line 788 of file Mixins.py.

788  def testLargeList(self):
789  #lists larger than 255 entries can not be initialized
790  #using the constructor
791  args = [i for i in range(0,300)]
792 
793  t = TestList(*args)
794  pdump= t.dumpPython()
795  class cms(object):
796  def __init__(self):
797  self.TestList = TestList
798  pythonized = eval( pdump, globals(),{'cms':cms()} )
799  self.assertEqual(t,pythonized)

References resolutioncreator_cfi.object, and FastTimerService_cff.range.

◆ testLargeParameterizable()

def Mixins.testMixins.testLargeParameterizable (   self)

Definition at line 915 of file Mixins.py.

915  def testLargeParameterizable(self):
916  class tLPTest(_TypedParameterizable):
917  pass
918  class tLPTestType(_SimpleParameterTypeBase):
919  def _isValid(self,value):
920  return True
921  class __DummyModule(object):
922  def __init__(self):
923  self.tLPTest = tLPTest
924  self.tLPTestType = tLPTestType
925  p = tLPTest("MyType",** dict( [ ("a"+str(x), tLPTestType(x)) for x in range(0,300) ] ) )
926  #check they are the same
927  self.assertEqual(p.dumpPython(), eval(p.dumpPython(),{"cms": __DummyModule()}).dumpPython())

References Mixins.testMixins.tLPTest.

◆ testListConstruction()

def Mixins.testMixins.testListConstruction (   self)

Definition at line 760 of file Mixins.py.

760  def testListConstruction(self):
761  t = TestList(1)
762  self.assertEqual(t,[1])
763  t = TestList((1,))
764  self.assertEqual(t,[1])
765  t = TestList("one")
766  self.assertEqual(t,["one"])
767  t = TestList( [1,])
768  self.assertEqual(t,[1])
769  t = TestList( (x for x in [1]) )
770  self.assertEqual(t,[1])
771 
772  t = TestList(1,2)
773  self.assertEqual(t,[1,2])
774  t = TestList((1,2))
775  self.assertEqual(t,[1,2])
776  t = TestList("one","two")
777  self.assertEqual(t,["one","two"])
778  t = TestList(("one","two"))
779  self.assertEqual(t,["one","two"])
780  t = TestList( [1,2])
781  self.assertEqual(t,[1,2])
782  t = TestList( (x for x in [1,2]) )
783  self.assertEqual(t,[1,2])
784  t = TestList( iter((1,2)) )
785  self.assertEqual(t,[1,2])
786 
787 

◆ testModified()

def Mixins.testMixins.testModified (   self)

Definition at line 903 of file Mixins.py.

903  def testModified(self):
904  class __TestType(_SimpleParameterTypeBase):
905  def _isValid(self,value):
906  return True
907  a = __TestType(1)
908  self.assertEqual(a.isModified(),False)
909  a.setValue(1)
910  self.assertEqual(a.isModified(),False)
911  a.setValue(2)
912  self.assertEqual(a.isModified(),True)
913  a.resetModified()
914  self.assertEqual(a.isModified(),False)

◆ testSpecialImportRegistry()

def Mixins.testMixins.testSpecialImportRegistry (   self)

Definition at line 928 of file Mixins.py.

928  def testSpecialImportRegistry(self):
929  reg = _SpecialImportRegistry()
930  reg.registerSpecialImportForType(int, "import foo")
931  self.assertRaises(RuntimeError, lambda: reg.registerSpecialImportForType(int, "import bar"))
932  reg.registerSpecialImportForType(str, "import bar")
933  self.assertEqual(reg.getSpecialImports(), [])
934  reg.registerUse([1])
935  self.assertEqual(reg.getSpecialImports(), [])
936  reg.registerUse(1)
937  self.assertEqual(reg.getSpecialImports(), ["import foo"])
938  reg.registerUse(1)
939  self.assertEqual(reg.getSpecialImports(), ["import foo"])
940  reg.registerUse("a")
941  self.assertEqual(reg.getSpecialImports(), ["import bar", "import foo"])
942 
943  unittest.main()

◆ testUsingBlock()

def Mixins.testMixins.testUsingBlock (   self)

Definition at line 800 of file Mixins.py.

800  def testUsingBlock(self):
801  a = UsingBlock("a")
802  self.assertTrue(isinstance(a, _ParameterTypeBase))

Member Data Documentation

◆ TestList

Mixins.testMixins.TestList

Definition at line 797 of file Mixins.py.

◆ tLPTest

Mixins.testMixins.tLPTest

Definition at line 923 of file Mixins.py.

Referenced by Mixins.testMixins.testLargeParameterizable().

◆ tLPTestType

Mixins.testMixins.tLPTestType

Definition at line 924 of file Mixins.py.

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
str
#define str(s)
Definition: TestProcessor.cc:53
ConfigBuilder.dumpPython
def dumpPython(process, name)
Definition: ConfigBuilder.py:94
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21