Skip to content

Commit

Permalink
Merge pull request #34493 from makortel/py3FWCoreParameterSet
Browse files Browse the repository at this point in the history
Use python3 in FWCore/ParameterSet unit tests
  • Loading branch information
cmsbuild authored Jul 16, 2021
2 parents 0eedb62 + 6ca99d6 commit d219d09
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 97 deletions.
28 changes: 14 additions & 14 deletions FWCore/ParameterSet/python/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,13 +2431,13 @@ def testTask(self):
# Also note that the mutating visitor replaces sequences and tasks that have
# modified contents with their modified contents, it does not modify the sequence
# or task itself.
self.assertTrue(process.path21.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.d, process.mesproducer, process.messource, process.mfilter, process.mproducer10, process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
self.assertTrue(process.path21.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.d, process.mesproducer, process.messource, process.mfilter, process.mproducer10, process.mproducer2, process.mproducer8, process.myTask5), process.myTask100, process.myTask5)\n')

process.path22 = process.path21.copyAndExclude([process.d, process.mesproducer, process.mfilter])
self.assertTrue(process.path22.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.messource, process.mproducer10, process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
self.assertTrue(process.path22.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.messource, process.mproducer10, process.mproducer2, process.mproducer8, process.myTask5), process.myTask100, process.myTask5)\n')

process.path23 = process.path22.copyAndExclude([process.messource, process.mproducer10])
self.assertTrue(process.path23.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None), cms.Task(process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
self.assertTrue(process.path23.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None), cms.Task(process.mproducer2, process.mproducer8, process.myTask5), process.myTask100, process.myTask5)\n')

process.a = EDAnalyzer("MyAnalyzer")
process.b = OutputModule("MyOutputModule")
Expand Down Expand Up @@ -3116,14 +3116,14 @@ def testTaskPlaceholder(self):
process.i = cms.EDProducer("mi")
process.j = cms.EDProducer("mj")
process.b = cms.EDAnalyzer("mb")
process.t8 = cms.Task(cms.TaskPlaceholder("j"))
process.t6 = cms.Task(cms.TaskPlaceholder("h"))
process.t7 = cms.Task(cms.TaskPlaceholder("i"), process.a, process.t6)
process.t4 = cms.Task(cms.TaskPlaceholder("f"))
process.t5 = cms.Task(cms.TaskPlaceholder("g"), cms.TaskPlaceholder("t4"), process.a)
process.t3 = cms.Task(cms.TaskPlaceholder("e"))
process.t1 = cms.Task(cms.TaskPlaceholder("c"))
process.t2 = cms.Task(cms.TaskPlaceholder("d"), process.a, process.t1)
process.t3 = cms.Task(cms.TaskPlaceholder("e"))
process.t5 = cms.Task(cms.TaskPlaceholder("g"), cms.TaskPlaceholder("t4"), process.a)
process.t4 = cms.Task(cms.TaskPlaceholder("f"))
process.t6 = cms.Task(cms.TaskPlaceholder("h"))
process.t7 = cms.Task(cms.TaskPlaceholder("i"), process.a, process.t6)
process.t8 = cms.Task(cms.TaskPlaceholder("j"))
process.path1 = cms.Path(process.b, process.t2, process.t3)
process.endpath1 = cms.EndPath(process.b, process.t5)
process.schedule = cms.Schedule(*[ process.path1, process.endpath1 ], tasks=[process.t7, process.t8])""")
Expand All @@ -3139,14 +3139,14 @@ def testTaskPlaceholder(self):
process.i = cms.EDProducer("mi")
process.j = cms.EDProducer("mj")
process.b = cms.EDAnalyzer("mb")
process.t8 = cms.Task(process.j)
process.t1 = cms.Task(process.c)
process.t2 = cms.Task(process.a, process.d, process.t1)
process.t3 = cms.Task(process.e)
process.t4 = cms.Task(process.f)
process.t6 = cms.Task(process.h)
process.t7 = cms.Task(process.a, process.i, process.t6)
process.t4 = cms.Task(process.f)
process.t8 = cms.Task(process.j)
process.t5 = cms.Task(process.a, process.g, process.t4)
process.t3 = cms.Task(process.e)
process.t1 = cms.Task(process.c)
process.t2 = cms.Task(process.a, process.d, process.t1)
process.path1 = cms.Path(process.b, process.t2, process.t3)
process.endpath1 = cms.EndPath(process.b, process.t5)
process.schedule = cms.Schedule(*[ process.path1, process.endpath1 ], tasks=[process.t7, process.t8])""")
Expand Down
4 changes: 2 additions & 2 deletions FWCore/ParameterSet/python/DictTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def __init__(self,*args,**kw):
dict.__init__(self,*args,**kw)
self.list = list()
if len(args) == 1:
if not hasattr(args[0],'iterkeys'):
if not hasattr(args[0],'keys'):
s = set()
#must protect against adding the same key multiple times
for x,y in iter(args[0]):
if x not in s:
self.list.append(x)
s.add(x)
else:
self.list = list(args[0].iterkeys())
self.list = list(args[0].keys())
return
self.list = list(six.iterkeys(super(SortedKeysDict,self)))

Expand Down
4 changes: 2 additions & 2 deletions FWCore/ParameterSet/python/Mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def __init__(self):
self.assertEqual(t,pythonized)
def testUsingBlock(self):
a = UsingBlock("a")
self.assert_(isinstance(a, _ParameterTypeBase))
self.assertTrue(isinstance(a, _ParameterTypeBase))
def testConstruction(self):
class __Test(_TypedParameterizable):
pass
Expand Down Expand Up @@ -929,7 +929,7 @@ def __init__(self):
def testSpecialImportRegistry(self):
reg = _SpecialImportRegistry()
reg.registerSpecialImportForType(int, "import foo")
self.assertRaises(lambda x: reg.registerSpecialImportForType(int, "import bar"))
self.assertRaises(RuntimeError, lambda: reg.registerSpecialImportForType(int, "import bar"))
reg.registerSpecialImportForType(str, "import bar")
self.assertEqual(reg.getSpecialImports(), [])
reg.registerUse([1])
Expand Down
51 changes: 27 additions & 24 deletions FWCore/ParameterSet/python/SequenceTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ def _replaceIfHeldDirectly(self,original,replacement):
if original == i:
self._collection[self._collection.index(original)] = replacement
didReplace = True
elif isinstance(i,_UnarySequenceOperator):
if i._replace(original, replacement):
didReplace = True
if replacement is None:
self._collection[self._collection.index(i)] = None
elif isinstance(i,_UnarySequenceOperator) and i._has(original):
didReplace = True
if replacement is None:
self._collection[self._collection.index(i)] = None
else:
self._collection[self._collection.index(i)] = type(i)(replacement)
if replacement is None:
self._collection = [ i for i in self._collection if i is not None]
return didReplace
Expand Down Expand Up @@ -545,26 +546,20 @@ def __init__(self, operand):
raise RuntimeError("This operator cannot accept a non sequenceable type")
def __eq__(self, other):
# allows replace(~a, b)
return isinstance(self, type(other)) and self._operand==other._operand
return type(self) is type(other) and self._operand==other._operand
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
# this definition implies that self._operand MUST NOT be changed after the construction
return hash((type(self), self._operand))
def _findDependencies(self,knownDeps, presentDeps):
self._operand._findDependencies(knownDeps, presentDeps)
def _clonesequence(self, lookuptable):
return type(self)(self._operand._clonesequence(lookuptable))
def _replace(self, original, replacement):
if self._operand == original:
self._operand = replacement
return True
return False
def _remove(self, original):
if (self._operand == original): return (None, True)
(self._operand, found) = self._operand._remove(original)
if self._operand == None: return (None, True)
return (self, found)
def _has(self, op):
return self._operand == op
def resolve(self, processDict,keepIfCannotResolve=False):
self._operand = self._operand.resolve(processDict,keepIfCannotResolve)
return self
return type(self)(self._operand.resolve(processDict,keepIfCannotResolve))
def isOperation(self):
return True
def _visitSubNodes(self,visitor):
Expand Down Expand Up @@ -1929,16 +1924,12 @@ def testResolve(self):
s3 = Sequence(m2)
p = Path(s1*s2)
l = list()
d = dict()
d['s1'] = s1
d['s2'] = s2
d['s3'] = s3
#resolver = ResolveVisitor(d)
#p.visit(resolver)
namesVisitor = DecoratedNodeNameVisitor(l)
p.visit(namesVisitor)
self.assertEqual(l, ['m1'])
p.resolve(d)
p.resolve(dict(s1=s1, s2=s2, s3=s3))
l[:] = []
p.visit(namesVisitor)
self.assertEqual(l, ['m1', 'm2'])
Expand All @@ -1948,9 +1939,21 @@ def testResolve(self):
s3 = Sequence(m2)
s4 = SequencePlaceholder("s2")
p=Path(s1+s4)
p.resolve(d)
p.resolve(dict(s1=s1, s2=s2, s3=s3, s4=s4))
p.visit(namesVisitor)
self.assertEqual(l, ['m1', 'm2'])
l[:]=[]
m3 = DummyModule("m3")
m4 = DummyModule("m4")
s1 = Sequence(~m1)
s2 = SequencePlaceholder("s3")
s3 = Sequence(ignore(m2))
s4 = Sequence(wait(m3) + ignore(wait(m4)))
d = dict(s1=s1, s2=s2, s3=s3, s4=s4)
p = Path(s1*s2*s4)
p.resolve(dict(s1=s1, s2=s2, s3=s3, s4=s4))
p.visit(namesVisitor)
self.assertEqual(l, ['!m1', '-m2', '|m3', '+m4'])
def testReplace(self):
m1 = DummyModule("m1")
m2 = DummyModule("m2")
Expand Down
Loading

0 comments on commit d219d09

Please sign in to comment.