Skip to content

Commit

Permalink
Fix unit tests python 3
Browse files Browse the repository at this point in the history
Changes in Config.py are only reordering things
  • Loading branch information
makortel committed Jul 14, 2021
1 parent 964d203 commit dd717c3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 73 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
4 changes: 3 additions & 1 deletion FWCore/ParameterSet/python/SequenceTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,11 @@ 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):
return hash((type(self), self._operand))

This comment has been minimized.

Copy link
@Dr15Jones

Dr15Jones Jul 14, 2021

Contributor

Unfortunately, (after some googling) this is flawed. Because the class type is mutable (ie. self.operand can be changed by call to _replace) the hash can change over the lifetime of the object. But hashes are not allowed to be changed since they are evaluted once when inserted in a container.

https://eng.lyft.com/hashing-and-equality-in-python-2ea8c738fb9d

I'm not sure what to do at the moment.

This comment has been minimized.

Copy link
@Dr15Jones

Dr15Jones Jul 14, 2021

Contributor

So I think what needs to be done is change _replace so that if the operand equals the item, the function generates a new _UnaryOperator of the right type containing the new object. Then line 204, in _replaceIfHeldDirectly needs to be modified to replace the old operator with the new one in the sequence.

Something similar would have to be done for _remove

This comment has been minimized.

Copy link
@Dr15Jones

Dr15Jones Jul 14, 2021

Contributor

As far as I can tell UnaryOperator._remove is not used anywhere

This comment has been minimized.

Copy link
@makortel

makortel Jul 14, 2021

Author Contributor

Thanks, I'll try that.

def _findDependencies(self,knownDeps, presentDeps):
self._operand._findDependencies(knownDeps, presentDeps)
def _clonesequence(self, lookuptable):
Expand Down
Loading

0 comments on commit dd717c3

Please sign in to comment.