Skip to content

Commit

Permalink
Simplify SwitchProducer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Jan 10, 2022
1 parent eec95a9 commit 6a7e1a2
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions FWCore/ParameterSet/python/Modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,23 +423,9 @@ class SwitchProducerTest(SwitchProducer):
def __init__(self, **kargs):
super(SwitchProducerTest,self).__init__(
dict(
test1 = lambda accelerators: (True, -10),
test2 = lambda accelerators: (True, -9),
test3 = lambda accelerators: (True, -8)
), **kargs)
class SwitchProducerTest1Dis(SwitchProducer):
def __init__(self, **kargs):
super(SwitchProducerTest1Dis,self).__init__(
dict(
test1 = lambda accelerators: (False, -10),
test2 = lambda accelerators: (True, -9)
), **kargs)
class SwitchProducerTest2Dis(SwitchProducer):
def __init__(self, **kargs):
super(SwitchProducerTest2Dis,self).__init__(
dict(
test1 = lambda accelerators: (True, -10),
test2 = lambda accelerators: (False, -9)
test1 = lambda accelerators: ("test1" in accelerators, -10),
test2 = lambda accelerators: ("test2" in accelerators, -9),
test3 = lambda accelerators: ("test3" in accelerators, -8)
), **kargs)
class SwitchProducerPickleable(SwitchProducer):
def __init__(self, **kargs):
Expand Down Expand Up @@ -566,17 +552,14 @@ def testSwitchProducer(self):
self.assertRaises(TypeError, lambda: SwitchProducerTest(test1 = SwitchProducerTest(test1 = EDProducer("Foo"))))

# Case decision
accelerators = []
accelerators = ["test1", "test2", "test3"]
sp = SwitchProducerTest(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
self.assertEqual(sp._getProducer(accelerators).type_(), "Bar")
sp = SwitchProducerTest1Dis(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
self.assertEqual(sp._getProducer(accelerators).type_(), "Bar")
sp = SwitchProducerTest2Dis(test1 = EDProducer("Foo"), test2 = EDProducer("Bar"))
self.assertEqual(sp._getProducer(accelerators).type_(), "Foo")
self.assertEqual(sp._getProducer(["test1", "test2", "test3"]).type_(), "Bar")
self.assertEqual(sp._getProducer(["test2", "test3"]).type_(), "Bar")
self.assertEqual(sp._getProducer(["test1", "test3"]).type_(), "Foo")
sp = SwitchProducerTest(test1 = EDProducer("Bar"))
self.assertEqual(sp._getProducer(accelerators).type_(), "Bar")
sp = SwitchProducerTest1Dis(test1 = EDProducer("Bar"))
self.assertRaises(RuntimeError, sp._getProducer, accelerators)
self.assertEqual(sp._getProducer(["test1", "test2", "test3"]).type_(), "Bar")
self.assertRaises(RuntimeError, sp._getProducer, ["test2", "test3"])

# Mofications
from .Types import int32, string, PSet
Expand Down

0 comments on commit 6a7e1a2

Please sign in to comment.