def test_setDataType(): m = Model() assert m._y_calc_name == "y_calc_sum" assert m._y_obs_name == "y_obs" assert m._sy_obs_name == "sy_obs" m.setDataType("Boom") assert m._y_calc_name == "y_calc_sum" assert m._y_obs_name == "y_obs" assert m._sy_obs_name == "sy_obs" m.setDataType("Sum") assert m._y_calc_name == "y_calc_sum" assert m._y_obs_name == "y_obs" assert m._sy_obs_name == "sy_obs" m.setDataType("Difference") assert m._y_calc_name == "y_calc_diff" assert m._y_obs_name == "y_obs_diff" assert m._sy_obs_name == "sy_obs_diff" m.setDataType("Up") assert m._y_calc_name == "y_calc_up" assert m._y_obs_name == "y_obs_up" assert m._sy_obs_name == "sy_obs_up" m.setDataType("Down") assert m._y_calc_name == "y_calc_down" assert m._y_obs_name == "y_obs_down" assert m._sy_obs_name == "sy_obs_down"
def test_CellParametersModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert m._a_role == 257 assert m._gamma_role == 262 assert isinstance(m._model, QStandardItemModel) assert isinstance(m._project_dict, ProjectDict) assert len(m._model.roleNames()) == 6 # assure _setModelFromProject got called assert m._model.rowCount() == 1 assert m._model.columnCount() == 1 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data(role=m._a_role) == 8.36212 assert m._model.item(0, 0).data(role=m._b_role) == 8.36212 assert m._model.item(0, 0).data(role=m._c_role) == 8.36212 assert m._model.item(0, 0).data(role=m._alpha_role) == 90.0 assert m._model.item(0, 0).data(role=m._beta_role) == 90.0 assert m._model.item(0, 0).data(role=m._gamma_role) == 90.0 # test asModel assert m._model == m.asModel()
def test__yDiffMax(): m = Model() assert m._yDiffMax() == 1 m._setYDiffMax(2) assert m._yDiffMax() == 2 m._setYDiffMax(-99.99) assert m._yDiffMax() == -99.99
def test__yDiffMin(): m = Model() assert m._yDiffMin() == 0 m._setYDiffMin(2) assert m._yDiffMin() == 2 m._setYDiffMin(-99.99) assert m._yDiffMin() == -99.99
def test_CellBoxModelModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert m._x_role == 257 assert m._y_role == 258 assert m._z_role == 259 assert isinstance(m._model, QStandardItemModel) assert isinstance(m._project_dict, ProjectDict) assert len(m._model.roleNames()) == 3 # assure _setModelFromProject got called assert m._model.rowCount() == 3000 assert m._model.columnCount() == 1 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data(role=m._x_role) == 0.0 assert m._model.item(0, 0).data(role=m._y_role) == 0.0 assert m._model.item(0, 0).data(role=m._z_role) == 0.0 assert m._model.item(2999, 0).data(role=m._x_role) == 8.36212 assert m._model.item(2999, 0).data(role=m._y_role) == 8.36212 assert m._model.item(2999, 0).data(role=m._z_role) == pytest.approx(8.32867) # test asModel assert m._model == m.asModel()
def test_CalculatedDataModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) assert isinstance(m._headers_model, QStandardItemModel) assert isinstance(m._project_dict, ProjectDict) # assure _setModelFromProject got called assert m._model.rowCount() == 381 assert m._model.columnCount() == 8 assert m._headers_model.rowCount() == 1 assert m._headers_model.columnCount() == 8 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data(role=Qt.DisplayRole) == 4.0 assert pytest.approx( m._model.item(0, 3).data(role=Qt.DisplayRole), 438.3046174533981) assert m._model.item(380, 0).data(role=Qt.DisplayRole) == 80.0 assert pytest.approx( m._model.item(380, 3).data(role=Qt.DisplayRole), -58.83263649312255) # test asModel assert m._model == m.asModel() assert m._headers_model == m.asHeadersModel()
def test_FileStructureModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) # assure _setModelFromProject got called assert m._model.rowCount() == 1 assert m._model.columnCount() == 1 phaseRole = Qt.UserRole + 1 expRole = Qt.UserRole + 2 calcRole = Qt.UserRole + 3 assert len(m._model.roleNames()) == 3 assert m._model.roleNames()[phaseRole] == b"phasesRole" assert str(m._model.roleNames()[expRole]) == "b'experimentsRole'" assert str(m._model.roleNames()[calcRole]) == "b'calculationsRole'" assert 'data_Fe3O4' in m._model.item(0, 0).data(role=phaseRole) assert 'data_pd' in m._model.item(0, 0).data(role=expRole) assert '_refln_index_k' in m._model.item(0, 0).data(role=calcRole)
def test_AtomMspsModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) assert isinstance(m._project_dict, ProjectDict) assert m._label_role == 257 assert m._chi23_role == 265 # assure _setModelFromProject got called assert m._model.rowCount() == 3 assert m._model.columnCount() == 1 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data() == 'Fe3A' assert m._model.item(0, 0).data(role=m._type_role) == 'Cani' assert m._model.item(0, 0).data(role=m._chiiso_role) == '' assert m._model.item(0, 0).data(role=m._chi11_role) == -3.468 assert m._model.item(0, 0).data(role=m._chi22_role) == -3.468 assert m._model.item(0, 0).data(role=m._chi33_role) == -3.468 assert m._model.item(0, 0).data(role=m._chi12_role) == 0.0 assert m._model.item(0, 0).data(role=m._chi13_role) == 0.0 assert m._model.item(0, 0).data(role=m._chi23_role) == 0.0 assert m._model.item(1, 0).data() == 'Fe3B' assert m._model.item(1, 0).data(role=m._type_role) == 'Cani' assert m._model.item(1, 0).data(role=m._chiiso_role) == '' assert m._model.item(1, 0).data(role=m._chi11_role) == 3.041 assert m._model.item(1, 0).data(role=m._chi22_role) == 3.041 assert m._model.item(1, 0).data(role=m._chi33_role) == 3.041 assert m._model.item(1, 0).data(role=m._chi12_role) == 0.0 assert m._model.item(1, 0).data(role=m._chi13_role) == 0.0 assert m._model.item(1, 0).data(role=m._chi23_role) == 0.0 assert m._model.item(2, 0).data() == 'O' assert m._model.item(2, 0).data(role=m._type_role) is None assert m._model.item(2, 0).data(role=m._chi11_role) is None assert m._model.item(2, 0).data(role=m._chi11_role) is None assert m._model.item(2, 0).data(role=m._chi22_role) is None assert m._model.item(2, 0).data(role=m._chi33_role) is None assert m._model.item(2, 0).data(role=m._chi12_role) is None assert m._model.item(2, 0).data(role=m._chi13_role) is None assert m._model.item(2, 0).data(role=m._chi23_role) is None # test asModel assert m._model == m.asModel()
def test_AtomSitesModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) assert isinstance(m._project_dict, ProjectDict) assert m._label_role == 257 assert m._occupancy_role == 263 # assure _setModelFromProject got called assert m._model.rowCount() == 3 assert m._model.columnCount() == 1 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data() == 'Fe3A' assert m._model.item(0, 0).data(role=m._atom_role) == 'Fe3+' assert m._model.item(0, 0).data(role=m._color_role) == 0.945 assert m._model.item(0, 0).data(role=m._x_role) == 0.125 assert m._model.item(0, 0).data(role=m._y_role) == 0.125 assert m._model.item(0, 0).data(role=m._z_role) == 0.125 assert m._model.item(0, 0).data(role=m._occupancy_role) == 1.0 assert m._model.item(1, 0).data() == 'Fe3B' assert m._model.item(1, 0).data(role=m._atom_role) == 'Fe3+' assert m._model.item(1, 0).data(role=m._color_role) == 0.945 assert m._model.item(1, 0).data(role=m._x_role) == 0.5 assert m._model.item(1, 0).data(role=m._y_role) == 0.5 assert m._model.item(1, 0).data(role=m._z_role) == 0.5 assert m._model.item(1, 0).data(role=m._occupancy_role) == 1.0 assert m._model.item(2, 0).data() == 'O' assert m._model.item(2, 0).data(role=m._atom_role) == 'O2-' assert m._model.item(2, 0).data(role=m._color_role) == 0.5803 assert m._model.item(2, 0).data(role=m._x_role) == 0.25521 assert m._model.item(2, 0).data(role=m._y_role) == 0.25521 assert m._model.item(2, 0).data(role=m._z_role) == 0.25521 assert m._model.item(2, 0).data(role=m._occupancy_role) == 1.0 # test asModel assert m._model == m.asModel()
def test_StatusModelModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._statusBarModel, QStandardItemModel) assert isinstance(m._chartDisplayModel, QStandardItemModel) # assure _setModelFromProject got called assert m._statusBarModel.rowCount() == 4 assert m._statusBarModel.columnCount() == 1 assert m._chartDisplayModel.rowCount() == 2 assert m._chartDisplayModel.columnCount() == 1 assert len(m._statusBarModel.roleNames()) == len(m._roles_dict['status']) assert len(m._chartDisplayModel.roleNames()) == len(m._roles_dict['plot']) assert b'label' in m._roles_dict['status'].values() assert b'value' in m._roles_dict['status'].values() assert b'label' in m._roles_dict['plot'].values() assert b'value' in m._roles_dict['plot'].values() fr = Qt.UserRole + 1 offset = 100 assert m._statusBarModel.item(0, 0).data(role=fr + 1) == pytest.approx(340.79) assert m._statusBarModel.item(2, 0).data(role=fr + 1) == 1 assert m._statusBarModel.item(3, 0).data(role=fr + 1) == 1 assert m._statusBarModel.item(1, 0).data(role=fr + 1) == 1 assert m._chartDisplayModel.item(0, 0).data(role=fr + offset + 1) == pytest.approx(340.79) assert m._chartDisplayModel.item(1, 0).data(role=fr + offset + 1) == 1 assert m._statusBarModel == m.returnStatusBarModel() assert m._chartDisplayModel == m.returnChartModel()
def test_FitablesModelModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) # assure _setModelFromProject got called assert m._model.rowCount() == 24 assert m._model.columnCount() == 1 assert len(m._model.roleNames()) == len(m._roles_dict) assert b'path' in m._roles_dict.values() assert b'refine' in m._roles_dict.values() # Test stuff from _setModelFromProject here # first and last row assert m._model.item(0, 0).data(role=Qt.UserRole+2) == 'phases Fe3O4 cell length_a' assert m._model.item(0, 0).data(role=Qt.UserRole+3) == 8.36212 assert m._model.item(0, 0).data(role=Qt.UserRole+4) == 0.0 assert m._model.item(0, 0).data(role=Qt.UserRole+5) == pytest.approx(6.68969) assert m._model.item(0, 0).data(role=Qt.UserRole+6) == 10.034544 assert m._model.item(0, 0).data(role=Qt.UserRole+7) is True assert m._model.item(0, 0).data(role=Qt.UserRole+8) == '\u212B' assert m._model.item(21, 0).data(role=Qt.UserRole+2) == 'experiments pd resolution y' assert m._model.item(21, 0).data(role=Qt.UserRole+3) == 0.0 assert m._model.item(21, 0).data(role=Qt.UserRole+4) == 0.0 assert m._model.item(21, 0).data(role=Qt.UserRole+5) == -1.0 assert m._model.item(21, 0).data(role=Qt.UserRole+6) == 1.0 assert m._model.item(21, 0).data(role=Qt.UserRole+7) is False assert m._model.item(21, 0).data(role=Qt.UserRole+8) == '' # test asModel assert m._model == m.asModel()
def test_MeasuredDataModel(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) assert isinstance(m._model, QStandardItemModel) assert isinstance(m._headers_model, QStandardItemModel) # assure _setModelFromProject got called assert m._model.rowCount() == 381 assert m._model.columnCount() == 9 assert m._headers_model.rowCount() == 1 assert m._headers_model.columnCount() == 9 # Test stuff from _setModelFromProject here assert m._model.item(0, 0).data(role=Qt.DisplayRole) == 4.0 assert m._model.item(0, 6).data(role=Qt.DisplayRole) == 128.97 assert m._model.item(380, 0).data(role=Qt.DisplayRole) == 80.0 assert m._model.item(380, 6).data(role=Qt.DisplayRole) == 27.81 assert m._headers_model.item(0, 0).data(role=Qt.DisplayRole) == 'x' assert m._headers_model.item(0, 1).data(role=Qt.DisplayRole) == 'y_obs' assert m._headers_model.item(0, 2).data(role=Qt.DisplayRole) == 'sy_obs' assert m._headers_model.item(0, 3).data(role=Qt.DisplayRole) == 'y_obs_diff' assert m._headers_model.item(0, 4).data(role=Qt.DisplayRole) == 'sy_obs_diff' assert m._headers_model.item(0, 5).data(role=Qt.DisplayRole) == 'y_obs_up' assert m._headers_model.item(0, 6).data(role=Qt.DisplayRole) == 'sy_obs_up' assert m._headers_model.item(0, 7).data(role=Qt.DisplayRole) == 'y_obs_down' assert m._headers_model.item(0, 8).data(role=Qt.DisplayRole) == 'sy_obs_down' # test asModel assert m._model == m.asModel() assert m._headers_model == m.asHeadersModel()
def test_CellBoxModel_bad_calculator(): calculator = None # null calculator with pytest.raises(AttributeError): m = Model() m.setCalculatorInterface(calculator) # null file file_path = None # with pytest.raises(TypeError): calculator = CryspyCalculator(file_path) # epty file file_path = QUrl("file:Tests/Data/empty.cif").toLocalFile() # apparently it is fine now - no exception raised calculator = CryspyCalculator(file_path) # old style rcif file_path = QUrl("file:Tests/Data/full.rcif").toLocalFile() # with pytest.raises(AttributeError): calculator = CryspyCalculator(file_path)
def test_onModelChanged(): file_path = QUrl(TEST_FILE).toLocalFile() calculator = CryspyCalculator(file_path) interface = QtCalculatorInterface(calculator) m = Model() m.setCalculatorInterface(interface) phase_index = m._model.index(2, 0) # 3rd element (from phase block) experiment_index = m._model.index(m._model.rowCount()-3, 0) # 4th from below (from experiment block) # ###################### # Check unsupported role # ###################### edit_role = Qt.UserRole + 101 # path edit role new_edit = [] m._model.setData(phase_index, new_edit, edit_role) # ###################### # Check refine parameter # ###################### display_role = Qt.UserRole + 7 edit_role = Qt.UserRole + 107 old_display = False new_display = True old_edit = None new_edit = True # Initial state assert m._model.data(phase_index, display_role) == old_display assert m._model.data(phase_index, edit_role) == old_edit assert m._model.data(experiment_index, display_role) == old_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via display role m._model.setData(phase_index, new_display, display_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_display, display_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via edit role m._model.setData(phase_index, new_edit, edit_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_edit, edit_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # ##################### # Check value parameter # ##################### display_role = Qt.UserRole + 3 edit_role = Qt.UserRole + 103 old_display = 0 old_edit = None new_display = 0.5 new_edit = 0.5 # Initial state assert m._model.data(phase_index, display_role) == old_display assert m._model.data(phase_index, edit_role) == old_edit assert m._model.data(experiment_index, display_role) == old_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via display role m._model.setData(phase_index, new_display, display_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_display, display_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via edit role m._model.setData(phase_index, new_edit, edit_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_edit, edit_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via edit role outside min/max limits m._model.setData(phase_index, -100, Qt.UserRole + 103) assert m._model.data(phase_index, Qt.UserRole + 5) == -120 m._model.setData(phase_index, 100, Qt.UserRole + 103) assert m._model.data(phase_index, Qt.UserRole + 6) == 120 m._model.setData(phase_index, 1000, Qt.UserRole + 103) m._model.setData(phase_index, 1000, Qt.UserRole + 105) m._model.setData(phase_index, 1000, Qt.UserRole + 106) m._model.setData(phase_index, 100, Qt.UserRole + 103) assert m._model.data(phase_index, Qt.UserRole + 5) == 80 m._model.setData(phase_index, -1000, Qt.UserRole + 103) m._model.setData(phase_index, -1000, Qt.UserRole + 105) m._model.setData(phase_index, -1000, Qt.UserRole + 106) m._model.setData(phase_index, -100, Qt.UserRole + 103) assert m._model.data(phase_index, Qt.UserRole + 6) == -80 m._model.setData(phase_index, 0, Qt.UserRole + 105) m._model.setData(phase_index, 0, Qt.UserRole + 106) m._model.setData(phase_index, 0, Qt.UserRole + 103) assert m._model.data(phase_index, Qt.UserRole + 5) == -1 assert m._model.data(phase_index, Qt.UserRole + 6) == 1 m._model.setData(experiment_index, 0, Qt.UserRole + 105) m._model.setData(experiment_index, 0, Qt.UserRole + 106) m._model.setData(experiment_index, 0, Qt.UserRole + 103) assert m._model.data(experiment_index, Qt.UserRole + 5) == -1 assert m._model.data(experiment_index, Qt.UserRole + 6) == 1 # ################### # Check min parameter # ################### display_role = Qt.UserRole + 5 edit_role = Qt.UserRole + 105 old_display = -1 old_edit = None new_display = -0.5 new_edit = -0.5 # Initial state assert m._model.data(phase_index, display_role) == old_display assert m._model.data(phase_index, edit_role) == old_edit assert m._model.data(experiment_index, display_role) == old_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via display role m._model.setData(phase_index, new_display, display_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_display, display_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via edit role m._model.setData(phase_index, new_edit, edit_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_edit, edit_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # ################### # Check max parameter # ################### display_role = Qt.UserRole + 6 edit_role = Qt.UserRole + 106 old_display = 1 old_edit = None new_display = 0.5 new_edit = 0.5 # Initial state assert m._model.data(phase_index, display_role) == old_display assert m._model.data(phase_index, edit_role) == old_edit assert m._model.data(experiment_index, display_role) == old_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via display role m._model.setData(phase_index, new_display, display_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_display, display_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit # Model changes via edit role m._model.setData(phase_index, new_edit, edit_role) assert m._model.data(phase_index, display_role) == new_display assert m._model.data(phase_index, edit_role) == old_edit m._model.setData(experiment_index, new_edit, edit_role) assert m._model.data(experiment_index, display_role) == new_display assert m._model.data(experiment_index, edit_role) == old_edit