def __init__(self, parent=None): super().__init__(parent) self._calculator = None # Create the status items chi_item = StatusItem('chiSq', title='Current \u03c7\u00b2', additionalData=1) chi_item.setReturn(True) chi_item.title = 'Previous \u03c7\u00b2' chi_item.setReturn(False) self._interestedList = StatusList([ chi_item, StatusItem('numPars', title='Fit parameters', additionalData=1), StatusItem('numData', title='Experiments', additionalData=0), StatusItem('numPhases', title='Phases', additionalData=0) ]) # minor properties self._first_role = Qt.UserRole + 1 self._statusBarModel = QStandardItemModel() self._chartDisplayModel = QStandardItemModel() # set role names self._role_names_list = ['label', 'value'] self._roles_list = [] self._roles_dict = {'status': {}, 'plot': {}} self._setRolesListAndDict() self._statusBarModel.setItemRoleNames(self._roles_dict['status']) self._chartDisplayModel.setItemRoleNames(self._roles_dict['plot']) self._log = logger.getLogger(self.__class__.__module__)
def test_StatusItem_creation(): # Empty Item creation.... with pytest.raises(TypeError): item = StatusItem() assert isinstance(StatusItem('test0'), StatusItem) assert isinstance(StatusItem('test0', 0), StatusItem) assert isinstance(StatusItem('test0', 0, 'Testing Object Number 0'), StatusItem) assert isinstance(StatusItem('test0', 0, 'Testing Object Number 0', 1), StatusItem)
def test_StatusItem_getValue(): def getValue(thisItem): return thisItem.value item = StatusItem('test0') assert getValue(item) == None item = StatusItem('test0', 0) assert getValue(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0') assert getValue(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0', 1) assert getValue(item) == 0
def test_StatusItem_getName(): def getName(thisItem): return thisItem.name item = StatusItem('test0') assert getName(item) == 'test0' item = StatusItem('test0', 0) assert getName(item) == 'test0' item = StatusItem('test0', 0, 'Testing Object Number 0') assert getName(item) == 'test0' item = StatusItem('test0', 0, 'Testing Object Number 0', 1) assert getName(item) == 'test0'
def test_item_StatusList_creation(): item1 = StatusItem('test1', 1, 'Testing Object Number 1') item2 = StatusItem('test2', 2, 'Testing Object Number 2') item3 = StatusItem('test3', 3, 'Testing Object Number 3') oldList = [item1, item2] thisList = StatusList(oldList) assert len(thisList) == 2 assert (item1 in thisList) == True assert (item3 in thisList) == False # Note that the current implementation cant do `i, item in thisList:` i = 0 for item in thisList: assert item == oldList[i] i += 1
def test_StatusList_add(): n = 3 thisList, oldList = createStatusList(n) n_new = n + 1 newItem = StatusItem('test%i' % n_new, n_new, 'Testing Object Number %i' % n_new) thisList.add(newItem) assert len(thisList) == n_new
def test_StatusItem_setValue(): n = 2 def setValue(thisItem, n): thisItem.value = n + 2 def getValue(thisItem): return thisItem.value item = StatusItem('test0') setValue(item, n) assert getValue(item) == (n + 2) item = StatusItem('test0', 0) setValue(item, n) assert getValue(item) == (n + 2) item = StatusItem('test0', 0, 'Testing Object Number 0') setValue(item, n) assert getValue(item) == (n + 2) item = StatusItem('test0', 0, 'Testing Object Number 0', 1) setValue(item, n) assert getValue(item) == (n + 2)
def test_StatusItem_setName(): n = 2 def setName(thisItem, n): thisItem.name = 'test%i' % (n + 2) def getName(thisItem): return thisItem.name item = StatusItem('test0') setName(item, n) assert getName(item) == 'test%i' % (n + 2) item = StatusItem('test0', 0) setName(item, n) assert getName(item) == 'test%i' % (n + 2) item = StatusItem('test0', 0, 'Testing Object Number 0') setName(item, n) assert getName(item) == 'test%i' % (n + 2) item = StatusItem('test0', 0, 'Testing Object Number 0', 1) setName(item, n) assert getName(item) == 'test%i' % (n + 2)
def test_StatusItem_getPrevious(): n = 2 def setValue(thisItem, n): thisItem.value = n + 2 def getPrevious(thisItem): return thisItem.previous # Test the case where value changes item = StatusItem('test0') setValue(item, n) assert getPrevious(item) == None item = StatusItem('test0', 0) setValue(item, n) assert getPrevious(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0') setValue(item, n) assert getPrevious(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0', 1) setValue(item, n) assert getPrevious(item) == 0 # Test the case where they are the same item = StatusItem('test0') setValue(item, n) setValue(item, n) assert getPrevious(item) == None item = StatusItem('test0', 0) setValue(item, n) setValue(item, n) assert getPrevious(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0') setValue(item, n) setValue(item, n) assert getPrevious(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0', 1) setValue(item, n) setValue(item, n) assert getPrevious(item) == 0
def createStatusList(n): thisList = [] for i in range(n): thisList.append( StatusItem('test%i' % i, i, 'Testing Object Number %i' % i)) return StatusList(thisList), thisList
def test_StatusItem_previousName(): def setValue(thisItem, value): thisItem.value = value def getValue(thisItem): return thisItem.value def getName(thisItem): return thisItem.name item = StatusItem('test0') setValue(item, 0) setValue(item, 1) item.setReturn(True) item.title = 'test0 Previous' assert getName(item) == 'test0_previous' assert getValue(item) == 0 item = StatusItem('test0', 0) setValue(item, 1) item.setReturn(True) item.title = 'test0 Previous' assert getName(item) == 'test0_previous' assert getValue(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0') setValue(item, 1) item.setReturn(True) item.title = 'test0 Previous' assert getName(item) == 'test0_previous' assert getValue(item) == 0 item = StatusItem('test0', 0, 'Testing Object Number 0', 1) setValue(item, 1) item.setReturn(True) item.title = 'test0 Previous' assert getName(item) == 'test0_previous' assert getValue(item) == 0
def test_StatusItem_hasPrevious(): def getHasPrevious(thisItem): return thisItem.hasPrevious def setValue(thisItem, value): thisItem.value = value item = StatusItem('test0') assert getHasPrevious(item) == False setValue(item, 0) setValue(item, 1) assert getHasPrevious(item) == False item.setReturn(True) item.title = 'test0 Previous' item.setReturn(False) assert getHasPrevious(item) == True item = StatusItem('test0', 0) assert getHasPrevious(item) == False setValue(item, 1) assert getHasPrevious(item) == False item.setReturn(True) item.title = 'test0 Previous' item.setReturn(False) assert getHasPrevious(item) == True item = StatusItem('test0', 0, 'Testing Object Number 0') assert getHasPrevious(item) == False setValue(item, 1) assert getHasPrevious(item) == False item.setReturn(True) item.title = 'test0 Previous' item.setReturn(False) assert getHasPrevious(item) == True item = StatusItem('test0', 0, 'Testing Object Number 0', 1) assert getHasPrevious(item) == False setValue(item, 1) assert getHasPrevious(item) == False item.setReturn(True) item.title = 'test0 Previous' item.setReturn(False) assert getHasPrevious(item) == True