def test_fem_id_exception(self): temp_fem = ExcaliburFem(1) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'get_id: resolved FEM object pointer to null'): temp_fem.get_id()
def test_double_close(self): the_fem = ExcaliburFem(0) the_fem.close() with assert_raises(ExcaliburFemError) as cm: the_fem.close() assert_equal(cm.exception.value, 'close: FEM object pointer has null FEM handle')
def test_fem_id_exception(self): temp_fem = ExcaliburFem(1, self.fem_address, self.fem_port, self.data_address) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'get_id: resolved FEM object pointer to null'): temp_fem.get_id()
def test_cmd_exception(self): chip_id = 0 cmd_id = 1 temp_fem = ExcaliburFem(1) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'cmd: resolved FEM object pointer to null'): temp_fem.cmd(chip_id, cmd_id)
def test_cmd_exception(self): chip_id = 0 cmd_id = 1 temp_fem = ExcaliburFem(1, self.fem_address, self.fem_port, self.data_address) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'cmd: resolved FEM object pointer to null'): temp_fem.cmd(chip_id, cmd_id)
def test_get_int_exception(self): chip_id = 0 param_id = 1001 param_len = 10 temp_fem = ExcaliburFem(1) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'get_int: resolved FEM object pointer to null'): temp_fem.get_int(chip_id, param_id, param_len)
def test_get_int_exception(self): chip_id = 0 param_id = 1001 param_len = 10 temp_fem = ExcaliburFem(1, self.fem_address, self.fem_port, self.data_address) temp_fem.fem_handle = None with assert_raises_regexp( ExcaliburFemError, 'get_int: resolved FEM object pointer to null'): temp_fem.get_int(chip_id, param_id, param_len)
def _connect_fem(self, idx): connect_ok = True logging.debug( 'Connecting FEM {} at {}:{}, data_addr {} timeout {} ms'.format( self.fems[idx].fem_id, self.fems[idx].host_addr, self.fems[idx].port, self.fems[idx].data_addr, self.fems[idx].timeout_ms)) try: self.fems[idx].fem = ExcaliburFem(self.fems[idx].fem_id, self.fems[idx].host_addr, self.fems[idx].port, self.fems[idx].data_addr, self.fems[idx].timeout_ms) self.fems[ idx].state = ExcaliburDetectorFemConnection.STATE_CONNECTED self.fems[idx].connected = True self._set_fem_error_state(idx, FEM_RTN_OK, '') logging.debug('Connected FEM {}'.format(self.fems[idx].fem_id)) except ExcaliburFemError as e: self.fems[idx].state = ExcaliburDetectorFemConnection.STATE_ERROR self.fems[idx].connected = False self.fems[idx].error_code = FEM_RTN_INTERNALERROR self.fems[idx].error_msg = str(e) logging.error('Failed to connect to FEM {} at {}:{}: {}'.format( self.fems[idx].fem_id, self.fems[idx].host_addr, self.fems[idx].port, str(e))) connect_ok = False else: # Set up chip enables according to asic enable mask try: (param_id, _, _, _, _) = self.fe_param_map['medipix_chip_disable'] for chip_idx in range(CHIPS_PER_FEM): chip_disable = 0 if chip_idx + 1 in self.fems[ idx].chips_enabled else 1 rc = self.fems[idx].fem.set_int(chip_idx + 1, param_id, 0, chip_disable) if rc != FEM_RTN_OK: self.fems[idx].error_msg = self.fems[ idx].fem.get_error_msg() logging.error( 'FEM {}: chip {} enable set returned error {}: {}'. format(self.fems[idx].fem_id, rc, self.fems[idx].error_msg)) except Exception as e: self.fems[idx].error_code = FEM_RTN_INTERNALERROR self.fems[ idx].error_msg = 'Unable to build chip enable list for FEM {}: {}'.format( idx, e) logging.error(self.fems[idx].error_msg) connect_ok = False self._decrement_pending(connect_ok)
def test_missing_library(self): with assert_raises_regexp( ExcaliburFemError, 'Failed to load API module: No module named'): fem = ExcaliburFem(self.fem_id, self.fem_address, self.fem_port, self.data_address)
def test_illegal_fem_id(self): id = -1 with assert_raises(ExcaliburFemError) as cm: bad_fem = ExcaliburFem(id, self.fem_address, self.fem_port, self.data_address) assert_equal( cm.exception.value, 'Failed to initialise FEM connection: Illegal ID specified')
def test_double_close(self): the_fem = ExcaliburFem(0, self.fem_address, self.fem_port, self.data_address) the_fem.close() with assert_raises(ExcaliburFemError) as cm: the_fem.close() assert_equal(cm.exception.value, 'close: FEM object pointer has null FEM handle')
def setup_class(cls): cls.fem_id = 1234 cls.fem_address = '192.168.0.100' cls.fem_port = 6969 cls.data_address = '10.0.2.1' # Enable use of stub API for testing ExcaliburFem.use_stub_api = True # Unload any previously loaded API module, to ensure we use the correct stub version for this test class if ExcaliburFem._fem_api is not None: del sys.modules[ExcaliburFem._fem_api.__name__] ExcaliburFem._fem_api = None cls.the_fem = ExcaliburFem(cls.fem_id, cls.fem_address, cls.fem_port, cls.data_address)