def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) dummy_tg_ctrl.add_element(self.dummy_tg) pool.add_element(dummy_tg_ctrl) pool.add_element(self.dummy_tg) self.cfg = createPoolSynchronizationConfiguration( (dummy_tg_ctrl, ), ((self.dummy_tg, ), ), ) # Create mock and define its functions ctrl_methods = [ 'PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll' ] self.mock_tg_ctrl = Mock(spec=ctrl_methods) self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering') dummy_tg_ctrl.ctrl = self.mock_tg_ctrl self.tgaction = PoolSynchronization(self.dummy_tg) self.tgaction.add_element(self.dummy_tg)
def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) dummy_tg_ctrl.add_element(self.dummy_tg) pool.add_element(dummy_tg_ctrl) pool.add_element(self.dummy_tg) self.conf_ctrl = createControllerConfiguration(dummy_tg_ctrl, [self.dummy_tg]) self.ctrls = get_acq_ctrls([self.conf_ctrl]) # self.cfg = createPoolSynchronizationConfiguration((dummy_tg_ctrl,), # ((self.dummy_tg,),),) # Create mock and define its functions ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreSynchAll', 'PreSynchOne', 'SynchOne', 'SynchAll'] self.mock_tg_ctrl = Mock(spec=ctrl_methods) self.mock_tg_ctrl.StateOne.return_value = (State.Moving, 'triggering') dummy_tg_ctrl.ctrl = self.mock_tg_ctrl self.tgaction = PoolSynchronization(self.dummy_tg) self.tgaction.add_element(self.dummy_tg)
def setUp(self): """Setup: - Use resources for Controller, CounterTimer and MeasurementGroup features. - Create Controller, CounterTimer and MeasurementGroup. """ pool = FakePool() pc = createPoolController(pool, dummyPoolCTCtrlConf01) pct = createPoolCounterTimer(pool, pc, dummyCounterTimerConf01) pc.add_element(pct) pool.add_element(pc) pool.add_element(pct) self.pmg = createPoolMeasurementGroup(pool, dummyMeasurementGroupConf01) self._pct = pct # keep a reference to use it in test_acquisition
def setUp(self): """Create a Controller, and Motor objects from dummy configurations """ unittest.TestCase.setUp(self) try: from mock import Mock except ImportError: self.skipTest("mock module is not available") pool = FakePool() dummy_mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01) self.dummy_mot = createPoolMotor(pool, dummy_mot_ctrl, dummyMotorConf01) self.dummy_mot2 = createPoolMotor(pool, dummy_mot_ctrl, dummyMotorConf02) dummy_mot_ctrl.add_element(self.dummy_mot) pool.add_element(dummy_mot_ctrl) pool.add_element(self.dummy_mot) pool.add_element(self.dummy_mot2) # {moveable: (position, dial_position, # do_backlash, backlash, instability_time=None)} self.items = {self.dummy_mot: (0, 0, False, 0), self.dummy_mot2: (0, 0, False, 0)} # Create mock and define its functions ctrl_methods = ['PreStartAll', 'StartAll', 'PreStartOne', 'StartOne', 'PreStateAll', 'StateAll', 'PreStateOne', 'StateOne', 'PreReadAll', 'PreReadOne', 'ReadOne', 'ReadAll', 'PreStopAll', 'StopAll', 'PreStopOne', 'StopOne', 'PreAbortAll', 'AbortAll', 'PreAbortOne', 'AbortOne'] self.mock_mot_ctrl = Mock(spec=ctrl_methods) self.mock_mot_ctrl.StateOne.return_value = (State.Moving, 'moving') dummy_mot_ctrl.ctrl = self.mock_mot_ctrl self.motionaction = PoolMotion(self.dummy_mot) self.motionaction.add_element(self.dummy_mot) self.motionaction.add_element(self.dummy_mot2)
def setUp(self): """Setup: - Use resources for Controller, CounterTimer and MeasurementGroup features. - Create Controller, CounterTimer and MeasurementGroup. """ pool = FakePool() pc = createPoolController(pool, dummyPoolCTCtrlConf01) pct = createPoolCounterTimer(pool, pc, dummyCounterTimerConf01) pool.add_element(pc) pool.add_element(pct) self.pmg = createPoolMeasurementGroup( pool, dummyMeasurementGroupConf01) pool.add_element(self.pmg) self._pct = pct # keep a reference to use it in test_acquisition
def setUp(self): """Create a Controller, TriggerGate and PoolSynchronization objects from dummy configurations """ unittest.TestCase.setUp(self) pool = FakePool() dummy_tg_ctrl = createPoolController(pool, dummyPoolTGCtrlConf01) self.dummy_tg = createPoolTriggerGate(pool, dummy_tg_ctrl, dummyTriggerGateConf01) # marrying the element with the controller dummy_tg_ctrl.add_element(self.dummy_tg) self.ctrl_conf = createControllerConfiguration(dummy_tg_ctrl, [self.dummy_tg]) # marrying the element with the action self.tg_action = PoolSynchronization(self.dummy_tg) self.tg_action.add_element(self.dummy_tg)
def test_state(monkeypatch, mock_StateOne): """Test variants of StateOne return value: - state - state, status """ pool = FakePool() # when SEP19 gets implemented it should be possible to mock directly # the imported class DummyCounterTimerController = pool.ctrl_manager.getControllerClass( "DummyCounterTimerController") monkeypatch.setattr(DummyCounterTimerController, "StateOne", mock_StateOne) ct_ctrl = createPoolController(pool, dummyPoolCTCtrlConf01) ct = createPoolCounterTimer(pool, ct_ctrl, dummyCounterTimerConf01) ct_ctrl.add_element(ct) pool.add_element(ct_ctrl) pool.add_element(ct) assert ct.state == State.On assert type(ct.status) == str
def test_state(monkeypatch, mock_StateOne): """Test variants of StateOne return value: - state - state, status - state, status, limit_switches """ pool = FakePool() # when SEP19 gets implemented it should be possible to mock directly # the imported class DummyMotorController = pool.ctrl_manager.getControllerClass( "DummyMotorController") monkeypatch.setattr(DummyMotorController, "StateOne", mock_StateOne) mot_ctrl = createPoolController(pool, dummyPoolMotorCtrlConf01) mot = createPoolMotor(pool, mot_ctrl, dummyMotorConf01) mot_ctrl.add_element(mot) pool.add_element(mot_ctrl) pool.add_element(mot) assert mot.state == State.On assert type(mot.status) == str assert mot.limit_switches.value == (False, ) * 3
class BasePoolTestCase(object): """Base pool test for setting the environment.""" POOLPATH = [] LOGLEVEL = logging.WARNING def createController(self, name, klass, lib, props={}): c_cfg = createCtrlConf(self.pool, name, klass, lib, props) ctrl_obj = createPoolController(self.pool, c_cfg) self.ctrls[name] = ctrl_obj self.pool.add_element(ctrl_obj) return ctrl_obj def createCTElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolCounterTimer(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # CT elements self.cts[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createZeroDElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolZeroDExpChannel(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # ZeroD elements self.zerods[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createTGElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolTriggerGate(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # TG elements self.tgs[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createMotorElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolMotor(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # MOT elements self.mots[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createPCElement(self, ctrl_obj, name, axis, elements=[]): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolPseudoCounter(self.pool, ctrl_obj, e_cfg, elements) ctrl_obj.add_element(elem_obj) self.pcs[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createPMElement(self, ctrl_obj, name, axis, elements=[]): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolPseudoMotor(self.pool, ctrl_obj, e_cfg, elements) ctrl_obj.add_element(elem_obj) self.pms[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def setUp(self): """Create a collection of controllers and elements. """ self.nctctrls = self.nzerodctrls = self.ntgctrls = self.nmotctrls = 4 self.nctelems = self.nzerodelems = self.ntgelems = self.nmotelems = 5 self.pool = FakePool(self.POOLPATH, self.LOGLEVEL) # Use debug mode self.ctrls = {} self.cts = {} self.zerods = {} self.tgs = {} self.mots = {} self.pcs = {} self.pms = {} # Create nctctrls CT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_ct_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyCounterTimerController', 'DummyCounterTimerController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_ct_%s_%s' % (ctrl, axis) self.createCTElement(ctrl_obj, name, axis) # Create nzerodctrls ZeroD ctrls for ctrl in range(1, self.nzerodctrls + 1): name = '_test_0d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyZeroDController', 'DummyZeroDController.py') # Create nelems ZeroD elements for each ctrl for axis in range(1, self.nzerodelems + 1): name = '_test_0d_%s_%s' % (ctrl, axis) self.createZeroDElement(ctrl_obj, name, axis) # Create ntgctrls TG ctrls for ctrl in range(1, self.ntgctrls + 1): name = '_test_tg_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTriggerGateController', 'DummyTriggerGateController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.ntgelems + 1): name = '_test_tg_%s_%s' % (ctrl, axis) self.createTGElement(ctrl_obj, name, axis) # Create nctrls MOT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_mot_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyMotorController', 'DummyMotorController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_mot_%s_%s' % (ctrl, axis) self.createMotorElement(ctrl_obj, name, axis) # Check the elements creation cts = len(self.cts.keys()) tgs = len(self.tgs.keys()) mots = len(self.mots.keys()) expected_cts = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of CT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_cts, cts, self.cts.keys()) if cts != expected_cts: raise Exception(msg) expected_tgs = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of TG elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_tgs, tgs, self.tgs.keys()) if tgs != expected_tgs: raise Exception(msg) expected_mots = self.nmotelems * self.nmotctrls msg = 'Something happened during the creation of MOT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (self.nmotelems, mots, self.mots.keys()) if mots != expected_mots: raise Exception(msg) def tearDown(self): self.pool.cleanup() self.pool = None self.ctrls = None self.cts = None self.tgs = None
def setUp(self): """Create a collection of controllers and elements. """ self.nctctrls = self.nzerodctrls = self.ntgctrls = self.nmotctrls = 4 self.nctelems = self.nzerodelems = self.ntgelems = self.nmotelems = 5 self.pool = FakePool(self.POOLPATH, self.LOGLEVEL) # Use debug mode self.ctrls = {} self.cts = {} self.zerods = {} self.tgs = {} self.mots = {} self.pcs = {} self.pms = {} # Create nctctrls CT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_ct_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyCounterTimerController', 'DummyCounterTimerController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_ct_%s_%s' % (ctrl, axis) self.createCTElement(ctrl_obj, name, axis) # Create nzerodctrls ZeroD ctrls for ctrl in range(1, self.nzerodctrls + 1): name = '_test_0d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyZeroDController', 'DummyZeroDController.py') # Create nelems ZeroD elements for each ctrl for axis in range(1, self.nzerodelems + 1): name = '_test_0d_%s_%s' % (ctrl, axis) self.createZeroDElement(ctrl_obj, name, axis) # Create ntgctrls TG ctrls for ctrl in range(1, self.ntgctrls + 1): name = '_test_tg_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTriggerGateController', 'DummyTriggerGateController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.ntgelems + 1): name = '_test_tg_%s_%s' % (ctrl, axis) self.createTGElement(ctrl_obj, name, axis) # Create nctrls MOT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_mot_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyMotorController', 'DummyMotorController.py') # Create nelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_mot_%s_%s' % (ctrl, axis) self.createMotorElement(ctrl_obj, name, axis) # Check the elements creation cts = len(self.cts.keys()) tgs = len(self.tgs.keys()) mots = len(self.mots.keys()) expected_cts = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of CT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_cts, cts, self.cts.keys()) if cts != expected_cts: raise Exception(msg) expected_tgs = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of TG elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_tgs, tgs, self.tgs.keys()) if tgs != expected_tgs: raise Exception(msg) expected_mots = self.nmotelems * self.nmotctrls msg = 'Something happened during the creation of MOT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (self.nmotelems, mots, self.mots.keys()) if mots != expected_mots: raise Exception(msg)
def setUp(self): """Create a FakePool object. """ self.pool = FakePool()
def setUp(self): """Instantiate a fake Pool and create a Controller""" pool = FakePool() self.pc = createPoolController(pool, dummyPoolCTCtrlConf01)
def setUp(self): """Create a collection of controllers and elements. """ self.nctctrls = self.nzerodctrls = self.ntgctrls = self.nmotctrls = 4 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodctrls = 1 self.nctelems = self.nzerodelems = self.ntgelems = self.nmotelems = 5 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodelems = 1 self.pool = FakePool(self.POOLPATH, self.LOGLEVEL) # Use debug mode self.ctrls = {} self.cts = {} self.zerods = {} self.twods = {} self.tgs = {} self.mots = {} self.pcs = {} self.pms = {} self.exp_channels = {} # Create nctctrls CT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_ct_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyCounterTimerController', 'DummyCounterTimerController.py') # use the first trigger/gate element by default ctrl_obj.set_ctrl_attr("synchronizer", "_test_tg_1_1") # Create nctelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_ct_%s_%s' % (ctrl, axis) self.createCTElement(ctrl_obj, name, axis) self.exp_channels.update(self.cts) # Create nzerodctrls ZeroD ctrls for ctrl in range(1, self.nzerodctrls + 1): name = '_test_0d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyZeroDController', 'DummyZeroDController.py') # Create nzerodelems ZeroD elements for each ctrl for axis in range(1, self.nzerodelems + 1): name = '_test_0d_%s_%s' % (ctrl, axis) self.createZeroDElement(ctrl_obj, name, axis) self.exp_channels.update(self.zerods) # Create ntwodctrls TwoD ctrls for ctrl in range(1, self.ntwodctrls + 1): name = '_test_2d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTwoDController', 'DummyTwoDController.py') # use the first trigger/gate element by default ctrl_obj.set_ctrl_attr("synchronizer", "_test_tg_1_1") # Create ntwodelems TwoD elements for each ctrl for axis in range(1, self.ntwodelems + 1): name = '_test_2d_%s_%s' % (ctrl, axis) self.createTwoDElement(ctrl_obj, name, axis) self.exp_channels.update(self.twods) # Create ntgctrls TG ctrls for ctrl in range(1, self.ntgctrls + 1): name = '_test_tg_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTriggerGateController', 'DummyTriggerGateController.py') # Create ntgelems TG elements for each ctrl for axis in range(1, self.ntgelems + 1): name = '_test_tg_%s_%s' % (ctrl, axis) self.createTGElement(ctrl_obj, name, axis) # Create nmotctrls MOT ctrls for ctrl in range(1, self.nmotctrls + 1): name = '_test_mot_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyMotorController', 'DummyMotorController.py') # Create nmotelems MOT elements for each ctrl for axis in range(1, self.nmotelems + 1): name = '_test_mot_%s_%s' % (ctrl, axis) self.createMotorElement(ctrl_obj, name, axis) # Check the elements creation cts = len(list(self.cts.keys())) tgs = len(list(self.tgs.keys())) mots = len(list(self.mots.keys())) expected_cts = self.nctelems * self.nctctrls msg = 'Something happened during the creation of CT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_cts, cts, list(self.cts.keys())) if cts != expected_cts: raise Exception(msg) expected_tgs = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of TG elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_tgs, tgs, list(self.tgs.keys())) if tgs != expected_tgs: raise Exception(msg) expected_mots = self.nmotelems * self.nmotctrls msg = 'Something happened during the creation of MOT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (self.nmotelems, mots, list(self.mots.keys())) if mots != expected_mots: raise Exception(msg)
def setUp(self): """Create a Controller and a CounterTimer element""" pool = FakePool() pc = createPoolController(pool, dummyPoolCTCtrlConf01) self.pct = createPoolCounterTimer(pool, pc, dummyCounterTimerConf01)
class BasePoolTestCase(object): """Base pool test for setting the environment.""" POOLPATH = [] LOGLEVEL = logging.WARNING def createController(self, name, klass, lib, props={}): c_cfg = createCtrlConf(self.pool, name, klass, lib, props) ctrl_obj = createPoolController(self.pool, c_cfg) self.ctrls[name] = ctrl_obj self.pool.add_element(ctrl_obj) return ctrl_obj def createCTElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolCounterTimer(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # CT elements self.cts[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createZeroDElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolZeroDExpChannel(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # ZeroD elements self.zerods[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createTwoDElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolTwoDExpChannel(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # TwoD elements self.twods[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createTGElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolTriggerGate(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # TG elements self.tgs[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createMotorElement(self, ctrl_obj, name, axis): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolMotor(self.pool, ctrl_obj, e_cfg) ctrl_obj.add_element(elem_obj) # MOT elements self.mots[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createPCElement(self, ctrl_obj, name, axis, elements=[]): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolPseudoCounter(self.pool, ctrl_obj, e_cfg, elements) ctrl_obj.add_element(elem_obj) self.pcs[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def createPMElement(self, ctrl_obj, name, axis, elements=[]): e_cfg = createElemConf(self.pool, axis, name) elem_obj = createPoolPseudoMotor(self.pool, ctrl_obj, e_cfg, elements) ctrl_obj.add_element(elem_obj) self.pms[name] = elem_obj self.pool.add_element(elem_obj) return elem_obj def setUp(self): """Create a collection of controllers and elements. """ self.nctctrls = self.nzerodctrls = self.ntgctrls = self.nmotctrls = 4 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodctrls = 1 self.nctelems = self.nzerodelems = self.ntgelems = self.nmotelems = 5 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodelems = 1 self.pool = FakePool(self.POOLPATH, self.LOGLEVEL) # Use debug mode self.ctrls = {} self.cts = {} self.zerods = {} self.twods = {} self.tgs = {} self.mots = {} self.pcs = {} self.pms = {} # Create nctctrls CT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_ct_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyCounterTimerController', 'DummyCounterTimerController.py') # Create nctelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_ct_%s_%s' % (ctrl, axis) self.createCTElement(ctrl_obj, name, axis) # Create nzerodctrls ZeroD ctrls for ctrl in range(1, self.nzerodctrls + 1): name = '_test_0d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyZeroDController', 'DummyZeroDController.py') # Create nzerodelems ZeroD elements for each ctrl for axis in range(1, self.nzerodelems + 1): name = '_test_0d_%s_%s' % (ctrl, axis) self.createZeroDElement(ctrl_obj, name, axis) # Create ntwodctrls TwoD ctrls for ctrl in range(1, self.ntwodctrls + 1): name = '_test_2d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTwoDController', 'DummyTwoDController.py') # Create ntwodelems TwoD elements for each ctrl for axis in range(1, self.ntwodelems + 1): name = '_test_2d_%s_%s' % (ctrl, axis) self.createTwoDElement(ctrl_obj, name, axis) # Create ntgctrls TG ctrls for ctrl in range(1, self.ntgctrls + 1): name = '_test_tg_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTriggerGateController', 'DummyTriggerGateController.py') # Create ntgelems TG elements for each ctrl for axis in range(1, self.ntgelems + 1): name = '_test_tg_%s_%s' % (ctrl, axis) self.createTGElement(ctrl_obj, name, axis) # Create nmotctrls MOT ctrls for ctrl in range(1, self.nmotctrls + 1): name = '_test_mot_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyMotorController', 'DummyMotorController.py') # Create nmotelems MOT elements for each ctrl for axis in range(1, self.nmotelems + 1): name = '_test_mot_%s_%s' % (ctrl, axis) self.createMotorElement(ctrl_obj, name, axis) # Check the elements creation cts = len(self.cts.keys()) tgs = len(self.tgs.keys()) mots = len(self.mots.keys()) expected_cts = self.nctelems * self.nctctrls msg = 'Something happened during the creation of CT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_cts, cts, self.cts.keys()) if cts != expected_cts: raise Exception(msg) expected_tgs = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of TG elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_tgs, tgs, self.tgs.keys()) if tgs != expected_tgs: raise Exception(msg) expected_mots = self.nmotelems * self.nmotctrls msg = 'Something happened during the creation of MOT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (self.nmotelems, mots, self.mots.keys()) if mots != expected_mots: raise Exception(msg) def tearDown(self): self.pool.cleanup() self.pool = None self.ctrls = None self.cts = None self.tgs = None
def setUp(self): """Create a collection of controllers and elements. """ self.nctctrls = self.nzerodctrls = self.ntgctrls = self.nmotctrls = 4 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodctrls = 1 self.nctelems = self.nzerodelems = self.ntgelems = self.nmotelems = 5 # dummy controller generates an array of zeros (1024x1024) for each # axis, many axes may increase the memory consumption of testsuite self.ntwodelems = 1 self.pool = FakePool(self.POOLPATH, self.LOGLEVEL) # Use debug mode self.ctrls = {} self.cts = {} self.zerods = {} self.twods = {} self.tgs = {} self.mots = {} self.pcs = {} self.pms = {} # Create nctctrls CT ctrls for ctrl in range(1, self.nctctrls + 1): name = '_test_ct_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyCounterTimerController', 'DummyCounterTimerController.py') # Create nctelems CT elements for each ctrl for axis in range(1, self.nctelems + 1): name = '_test_ct_%s_%s' % (ctrl, axis) self.createCTElement(ctrl_obj, name, axis) # Create nzerodctrls ZeroD ctrls for ctrl in range(1, self.nzerodctrls + 1): name = '_test_0d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyZeroDController', 'DummyZeroDController.py') # Create nzerodelems ZeroD elements for each ctrl for axis in range(1, self.nzerodelems + 1): name = '_test_0d_%s_%s' % (ctrl, axis) self.createZeroDElement(ctrl_obj, name, axis) # Create ntwodctrls TwoD ctrls for ctrl in range(1, self.ntwodctrls + 1): name = '_test_2d_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTwoDController', 'DummyTwoDController.py') # Create ntwodelems TwoD elements for each ctrl for axis in range(1, self.ntwodelems + 1): name = '_test_2d_%s_%s' % (ctrl, axis) self.createTwoDElement(ctrl_obj, name, axis) # Create ntgctrls TG ctrls for ctrl in range(1, self.ntgctrls + 1): name = '_test_tg_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyTriggerGateController', 'DummyTriggerGateController.py') # Create ntgelems TG elements for each ctrl for axis in range(1, self.ntgelems + 1): name = '_test_tg_%s_%s' % (ctrl, axis) self.createTGElement(ctrl_obj, name, axis) # Create nmotctrls MOT ctrls for ctrl in range(1, self.nmotctrls + 1): name = '_test_mot_ctrl_%s' % ctrl ctrl_obj = self.createController(name, 'DummyMotorController', 'DummyMotorController.py') # Create nmotelems MOT elements for each ctrl for axis in range(1, self.nmotelems + 1): name = '_test_mot_%s_%s' % (ctrl, axis) self.createMotorElement(ctrl_obj, name, axis) # Check the elements creation cts = len(self.cts.keys()) tgs = len(self.tgs.keys()) mots = len(self.mots.keys()) expected_cts = self.nctelems * self.nctctrls msg = 'Something happened during the creation of CT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_cts, cts, self.cts.keys()) if cts != expected_cts: raise Exception(msg) expected_tgs = self.ntgelems * self.ntgctrls msg = 'Something happened during the creation of TG elements.\n' + \ 'Expected %s and there are %s, %s' % \ (expected_tgs, tgs, self.tgs.keys()) if tgs != expected_tgs: raise Exception(msg) expected_mots = self.nmotelems * self.nmotctrls msg = 'Something happened during the creation of MOT elements.\n' + \ 'Expected %s and there are %s, %s' % \ (self.nmotelems, mots, self.mots.keys()) if mots != expected_mots: raise Exception(msg)