class TestChannelDialogController(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) model = channels_dialog.ChannelsDialogModel(window) controller = channels_dialog.ChannelsDialogController(model, None) def test_init(self): assert self.controller.model == self.model assert self.controller.view is None def test_update_menus_indices(self): assert self.model.menu_indices == [0, 1, 2] self.model.red_model.update_index(1) self.model.green_model.update_index(3) self.model.blue_model.update_index(0) assert self.model.menu_indices == [0, 1, 2] self.controller.update_menu_indices() assert self.model.menu_indices == [1, 3, 0] def test_update_current_index(self): assert self.model.current_index == 0 self.model.main_window.controller.next_image() assert self.model.current_index == 0 self.controller.update_current_index() assert self.model.current_index == 1 self.model.main_window.controller.previous_image() assert self.model.current_index == 1 self.controller.update_current_index() assert self.model.current_index == 0
def test_model_image_view(): image_view = window.view_canvas model = histogram.HistogramModel(image_view) model.image_view == image_view model.image_view == model._image_view # Test setter method image_view2 = pdsview.PDSViewer(pdsview.ImageSet([FILE_3])).view_canvas model.image_view = image_view2 assert model.image_view == image_view2
class TestChannelsDialogModel(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) model = channels_dialog.ChannelsDialogModel(window) def test_init(self): assert self.model._views == set() assert self.model.current_index == 0 assert isinstance(self.model.rgb_models, tuple) assert len(self.model.rgb_models) == 3 for model in self.model.rgb_models: assert isinstance(model, band_widget.BandWidgetModel) assert self.model.red_model.name == 'Red' assert self.model.red_model.rgb_index == 0 assert self.model.green_model.name == 'Green' assert self.model.green_model.rgb_index == 1 assert self.model.blue_model.name == 'Blue' assert self.model.blue_model.rgb_index == 2 assert isinstance(self.model.menu_indices, list) assert self.model.menu_indices == [0, 1, 2] def test_images(self): images = self.window.image_set.images expected_images = [image[0] for image in images] assert self.model.images == expected_images def test_rgb(self): assert self.model.rgb == self.window.image_set.rgb def test_image_names(self): names = [ FILE_5_NAME, FILE_3_NAME, FILE_1_NAME, FILE_2_NAME, FILE_4_NAME ] assert self.model.image_names == names def test_rgb_names(self): rgb_names = [FILE_5_NAME, FILE_3_NAME, FILE_1_NAME] assert self.model.rgb_names == rgb_names def test_alphas(self): assert self.model.alphas == [1., 1., 1.] self.model.red_model.alpha_value = 75 self.model.green_model.alpha_value = 50 self.model.blue_model.alpha_value = 25 assert self.model.alphas == [.75, .5, .25]
class TestBandWidgetController(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) channels_model = channels_dialog.ChannelsDialogModel(window) model = band_widget.BandWidgetModel(channels_model, 0, 'Test') controller = band_widget.BandWidgetController(model, None) def test_init(self): assert self.controller.model == self.model assert self.controller.view is None def test_update_index(self): assert self.model.index == 0 new_index = 1 self.controller.update_index(new_index, True) assert self.model.index == new_index new_index = 0 self.controller.update_index(new_index, True) assert self.model.index == new_index def test_reset_index(self): assert self.model.index == 0 new_index = 1 self.model._index = new_index self.controller.reset_index() assert self.model.index == 0 def test_update_alpha_value(self): assert self.model.alpha_value == 100. self.controller.update_alpha(50.) assert self.model.alpha_value == 50. self.controller.update_alpha(75.) assert self.model.alpha_value == 75. self.controller.update_alpha(-1) assert self.model.alpha_value == 0. self.controller.update_alpha(-100000) assert self.model.alpha_value == 0. self.controller.update_alpha(101) assert self.model.alpha_value == 100. self.controller.update_alpha(10000) assert self.model.alpha_value == 100. self.controller.update_alpha(0) assert self.model.alpha_value == 0. self.controller.update_alpha(100) assert self.model.alpha_value == 100.
import pytest import numpy as np from qtpy import QtWidgets, QtCore from matplotlib.lines import Line2D from pdsview import pdsview, histogram FILE_1 = os.path.join('tests', 'mission_data', '1p190678905erp64kcp2600l8c1.img') FILE_2 = os.path.join('tests', 'mission_data', '2p129641989eth0361p2600r8m1.img') FILE_3 = os.path.join('tests', 'mission_data', '1p134482118erp0902p2600r8m1.img') test_images = pdsview.ImageSet([FILE_1, FILE_2]) window = pdsview.PDSViewer(test_images) image_view = window.view_canvas def test_model_init(): model = histogram.HistogramModel(image_view) assert model._image_view == image_view assert model._views == set() assert model._cut_low is None assert model._cut_high is None assert model._bins == 100 def test_model_image_view(): image_view = window.view_canvas model = histogram.HistogramModel(image_view)
class TestPDSViewer(object): filepaths = [FILE_1, FILE_2, FILE_3, FILE_4, FILE_5] test_set = pdsview.ImageSet(filepaths) viewer = pdsview.PDSViewer(test_set) viewer.show() def test_init(self): assert self.viewer.image_set == self.test_set assert self.viewer in self.test_set._views assert self.viewer._label_window is None assert self.viewer._label_window_pos is None assert self.viewer.channels_window is None assert not self.viewer.channels_window_is_open assert self.viewer.channels_window_pos is None assert isinstance(self.viewer.view_canvas, ImageViewCanvas) assert isinstance(self.viewer.next_image_btn, QtWidgets.QPushButton) assert isinstance(self.viewer.previous_image_btn, QtWidgets.QPushButton) assert isinstance(self.viewer.open_label, QtWidgets.QPushButton) assert isinstance(self.viewer.next_channel_btn, QtWidgets.QPushButton) assert isinstance(self.viewer.previous_channel_btn, QtWidgets.QPushButton) assert isinstance(self.viewer.restore_defaults, QtWidgets.QPushButton) assert isinstance(self.viewer.channels_button, QtWidgets.QPushButton) assert isinstance(self.viewer.x_value_lbl, QtWidgets.QLabel) assert isinstance(self.viewer.y_value_lbl, QtWidgets.QLabel) assert isinstance(self.viewer.pixel_value_lbl, QtWidgets.QLabel) assert isinstance(self.viewer.pixels, QtWidgets.QLabel) assert isinstance(self.viewer.std_dev, QtWidgets.QLabel) assert isinstance(self.viewer.mean, QtWidgets.QLabel) assert isinstance(self.viewer.median, QtWidgets.QLabel) assert isinstance(self.viewer.min, QtWidgets.QLabel) assert isinstance(self.viewer.max, QtWidgets.QLabel) assert isinstance(self.viewer.histogram, HistogramModel) assert isinstance(self.viewer.histogram_widget, HistogramWidget) assert isinstance(self.viewer.rgb_check_box, QtWidgets.QCheckBox) assert self.viewer.windowTitle() == FILE_5_NAME assert self.viewer.pixels.text() == '#Pixels: 32768' assert self.viewer.std_dev.text() == 'Std Dev: 16.100793' assert self.viewer.mean.text() == 'Mean: 24.6321' assert self.viewer.median.text() == 'Median: 22.0' assert self.viewer.min.text() == 'Min: 17' assert self.viewer.max.text() == 'Max: 114' assert self.viewer.x_value_lbl.text() == 'X: ????' assert self.viewer.y_value_lbl.text() == 'Y: ????' assert self.viewer.pixel_value_lbl.text() == 'Value: ????' assert not self.viewer.rgb_check_box.isChecked() def test_current_image(self): expected = self.test_set.current_image[self.test_set.channel] assert self.viewer.current_image == expected def test_refresh_ROI_text(self): self.viewer.min.setText("Min: 0") self.viewer.max.setText("Max: 100") self.viewer._refresh_ROI_text() assert self.viewer.min.text() == 'Min: 17' assert self.viewer.max.text() == 'Max: 114' def test_reset_ROI(self): self.viewer.min.setText("Min: 0") self.viewer.max.setText("Max: 100") self.viewer._reset_ROI() assert self.viewer.min.text() == 'Min: 17' assert self.viewer.max.text() == 'Max: 114' # TODO: When have RGB Image Test _disable_next_previous def test_reset_display_values(self): self.viewer.x_value_lbl.setText("X: 42") self.viewer.y_value_lbl.setText("Y: 42") self.viewer.pixel_value_lbl.setText("Value: 42") self.viewer._reset_display_values() assert self.viewer.x_value_lbl.text() == 'X: ????' assert self.viewer.y_value_lbl.text() == 'Y: ????' assert self.viewer.pixel_value_lbl.text() == 'Value: ????' def test_window_cascade(self, qtbot): """Tests the window cascade.""" # Initial checks assert self.viewer._label_window is None assert self.viewer.open_label.isEnabled() # Open the label window and run appropriate checks qtbot.mouseClick(self.viewer.open_label, QtCore.Qt.LeftButton) qtbot.add_widget(self.viewer._label_window) assert self.viewer._label_window is not None assert self.viewer._label_window._finder_window is None assert self.viewer._label_window.is_open # Open the finder window and run appropriate checks qtbot.mouseClick(self.viewer._label_window.find_button, QtCore.Qt.LeftButton) assert self.viewer._label_window._finder_window is not None qtbot.add_widget(self.viewer._label_window._finder_window) assert not (self.viewer._label_window._finder_window.query_edit) # Hide windows and check to make sure they are hidden qtbot.mouseClick(self.viewer._label_window._finder_window.ok_button, QtCore.Qt.LeftButton) assert self.viewer._label_window._finder_window.isHidden() qtbot.mouseClick(self.viewer._label_window.cancel_button, QtCore.Qt.LeftButton) assert self.viewer._label_window.isHidden() # Test the ability for the parent (label) to hide the child (finder) qtbot.mouseClick(self.viewer.open_label, QtCore.Qt.LeftButton) qtbot.mouseClick(self.viewer._label_window.find_button, QtCore.Qt.LeftButton) assert not (self.viewer._label_window.isHidden()) assert not (self.viewer._label_window._finder_window.isHidden()) qtbot.mouseClick(self.viewer._label_window.cancel_button, QtCore.Qt.LeftButton) assert self.viewer._label_window.isHidden() assert self.viewer._label_window._finder_window.isHidden() def test_label_refresh(self, qtbot): """Tests the label display and refresh features.""" qtbot.mouseClick(self.viewer.open_label, QtCore.Qt.LeftButton) qtbot.add_widget(self.viewer._label_window) label_contents = self.viewer._label_window.label_contents assert label_contents.toPlainText()[233:236] == "341" qtbot.mouseClick(self.viewer.next_image_btn, QtCore.Qt.LeftButton) label_contents = self.viewer._label_window.label_contents assert label_contents.toPlainText()[228:231] == "338" qtbot.mouseClick(self.viewer.previous_image_btn, QtCore.Qt.LeftButton) label_contents = self.viewer._label_window.label_contents assert label_contents.toPlainText()[233:236] == "341" def test_channels_dialog(self, qtbot): assert self.viewer.channels_window is None assert not self.viewer.channels_window_is_open assert self.viewer.channels_window_pos is None qtbot.add_widget(self.viewer) qtbot.mouseClick(self.viewer.channels_button, QtCore.Qt.LeftButton) assert self.viewer.channels_window is not None assert self.viewer.channels_window_is_open assert isinstance(self.viewer.channels_window, ChannelsDialog) assert self.viewer.channels_window_pos is None qtbot.add_widget(self.viewer.channels_window) new_pos = QtCore.QPoint(42, 24) self.viewer.channels_window.move(new_pos) qtbot.mouseClick(self.viewer.channels_window.close_button, QtCore.Qt.LeftButton) assert self.viewer.channels_window_pos is not None assert self.viewer.channels_window_pos == new_pos qtbot.mouseClick(self.viewer.channels_button, QtCore.Qt.LeftButton) self.viewer.channels_window.pos() == new_pos def test_apply_parameters(self, qtbot): """Test that images maintain their parameters""" self.viewer.save_parameters() image1 = self.viewer.current_image assert image1.sarr[0] == 0 assert image1.sarr[255] == 255 # assert image1.zoom == 1.0 assert image1.rotation == 0.0 assert image1.transforms == (False, False, False) assert image1.cuts == (17, 25) # Change parameters image1.sarr[0] = 42 image1.sarr[255] = 13 self.viewer.view_canvas.get_rgbmap().set_sarr(image1.sarr) # self.viewer.view_canvas.zoom_to(3) self.viewer.view_canvas.rotate(45) self.viewer.view_canvas.transform(False, True, False) self.viewer.view_canvas.cut_levels(24, 95) qtbot.mouseClick(self.viewer.next_image_btn, QtCore.Qt.LeftButton) # Test the second image parameters are None by defualt image2 = self.viewer.current_image # Test the view was reset to defualt paramters for the image assert self.viewer.view_canvas.get_rgbmap().get_sarr()[0] == 0 assert self.viewer.view_canvas.get_rgbmap().get_sarr()[255] == 255 # assert self.viewer.view_canvas.get_zoom() == 1.0 assert self.viewer.view_canvas.get_rotation() == 0.0 assert self.viewer.view_canvas.get_transforms() == (False, False, False) assert self.viewer.view_canvas.get_cut_levels() == (22, 26) # Test changing back to the first image maintains image1's parameters qtbot.mouseClick(self.viewer.previous_image_btn, QtCore.Qt.LeftButton) image1 = self.viewer.image_set.current_image[0] assert image1.sarr[0] == 42 assert image1.sarr[255] == 13 # assert image1.zoom == 3.0 assert image1.rotation == 45.0 assert image1.transforms == (False, True, False) assert image1.cuts == (24, 95) # Test that image2 stored its parameters image2 = self.viewer.image_set.images[1][0] assert image2.sarr[0] == 0 assert image2.sarr[255] == 255 # assert image2.zoom == 4.746031746031746 assert image2.rotation == 0.0 assert image2.transforms == (False, False, False) assert image2.cuts == (22, 26) def test_restore(self, qtbot): image1 = self.viewer.image_set.current_image[0] image1.sarr[0] = 42 image1.sarr[255] = 13 self.viewer.view_canvas.get_rgbmap().set_sarr(image1.sarr) # self.viewer.view_canvas.zoom_to(3) self.viewer.view_canvas.rotate(45) self.viewer.view_canvas.transform(False, True, False) self.viewer.view_canvas.cut_levels(24, 95) assert image1.sarr[0] == 42 assert image1.sarr[255] == 13 # assert image1.zoom == 3.0 assert image1.rotation == 45.0 assert image1.transforms == (False, True, False) assert image1.cuts == (24, 95) qtbot.mouseClick(self.viewer.restore_defaults, QtCore.Qt.LeftButton) self.viewer.save_parameters() assert image1.sarr[0] == 0 assert image1.sarr[255] == 255 # assert image1.zoom == 1.0 assert image1.rotation == 0.0 assert image1.transforms == (False, False, False) assert image1.cuts == (17, 25) def test_set_ROI_text(self, qtbot): """Test the ROI text to contain the correct values""" # Test Whole image ROI assert self.viewer.pixels.text() == '#Pixels: 32768' assert self.viewer.std_dev.text() == 'Std Dev: 16.100793' assert self.viewer.mean.text() == 'Mean: 24.6321' assert self.viewer.median.text() == 'Median: 22.0' assert self.viewer.min.text() == 'Min: 17' assert self.viewer.max.text() == 'Max: 114' # Test 2x2 random ROI # .5 values because these are the edge of the ROI pixels self.viewer.set_ROI_text(14.5, 512.5, 16.5, 514.5) assert self.viewer.pixels.text() == '#Pixels: 4' assert self.viewer.std_dev.text() == 'Std Dev: 1.000000' assert self.viewer.mean.text() == 'Mean: 23.0000' assert self.viewer.median.text() == 'Median: 23.0' assert self.viewer.min.text() == 'Min: 22' assert self.viewer.max.text() == 'Max: 24' def test_top_right_pixel_snap(self): test_snap_1 = self.viewer.top_right_pixel_snap(10, 5) assert test_snap_1[0] == 5.5 assert test_snap_1[1] test_snap_2 = self.viewer.top_right_pixel_snap(-5, 5) assert not test_snap_2[1] test_snap_3 = self.viewer.top_right_pixel_snap(5.4, 10) assert test_snap_3[0] == 5.5 assert test_snap_3[1] test_snap_4 = self.viewer.top_right_pixel_snap(5.5, 10) assert test_snap_4[0] == 5.5 assert test_snap_4[1] test_snap_5 = self.viewer.top_right_pixel_snap(5.6, 10) assert test_snap_5[0] == 6.5 assert test_snap_5[1] def test_bottom_left_pixel_snap(self): test_snap_1 = self.viewer.bottom_left_pixel_snap(-5, 5) assert test_snap_1[0] == -0.5 assert test_snap_1[1] test_snap_2 = self.viewer.bottom_left_pixel_snap(10, 5) assert not test_snap_2[1] test_snap_3 = self.viewer.bottom_left_pixel_snap(5.4, 10) assert test_snap_3[0] == 4.5 assert test_snap_3[1] test_snap_4 = self.viewer.bottom_left_pixel_snap(5.5, 10) assert test_snap_4[0] == 5.5 assert test_snap_4[1] def test_left_right_bottom_top(self): test_coords_1 = self.viewer.left_right_bottom_top(1, 2, 1, 2) assert test_coords_1[0:4] == (1, 2, 1, 2) assert test_coords_1[4] assert test_coords_1[5] test_coords_2 = self.viewer.left_right_bottom_top(2, 1, 1, 2) assert test_coords_2[0:4] == (1, 2, 1, 2) assert not test_coords_2[4] assert test_coords_2[5] test_coords_3 = self.viewer.left_right_bottom_top(1, 2, 2, 1) assert test_coords_3[0:4] == (1, 2, 1, 2) assert test_coords_3[4] assert not test_coords_3[5] test_coords_4 = self.viewer.left_right_bottom_top(2, 1, 2, 1) assert test_coords_4[0:4] == (1, 2, 1, 2) assert not test_coords_4[4] assert not test_coords_4[5]
class TestChannelsDialog(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) window.channels_dialog() dialog = window.channels_window model = dialog.model window.show() def add_widget_wrapper(func): @wraps(func) def wrapper(self, qtbot): self.dialog.show() qtbot.addWidget(self.dialog) return func(self, qtbot) return wrapper @add_widget_wrapper def test_init(self, qtbot): assert self.dialog.model == self.model assert self.dialog in self.model._views assert isinstance( self.dialog.controller, channels_dialog.ChannelsDialogController ) assert isinstance(self.dialog, QtWidgets.QDialog) assert isinstance(self.dialog.image_tree, QtWidgets.QTreeWidget) for item in self.dialog.items: assert isinstance(item, QtWidgets.QTreeWidgetItem) selection_mode = QtWidgets.QAbstractItemView.NoSelection assert self.dialog.image_tree.selectionMode() == selection_mode assert self.model.image_names == [ item.text(0) for item in self.dialog.items] assert self.dialog.current_item.isSelected() assert isinstance(self.dialog.rgb_check_box, QtWidgets.QCheckBox) assert isinstance(self.dialog.red_widget, band_widget.BandWidget) assert isinstance(self.dialog.green_widget, band_widget.BandWidget) assert isinstance(self.dialog.blue_widget, band_widget.BandWidget) @add_widget_wrapper def test_current_item(self, qtbot): assert self.dialog.current_item.text(0) == self.dialog.items[0].text(0) qtbot.mouseClick(self.window.next_image_btn, QtCore.Qt.LeftButton) assert self.model.current_index == 1 assert self.dialog.current_item.text(0) == self.dialog.items[1].text(0) qtbot.mouseClick(self.window.previous_image_btn, QtCore.Qt.LeftButton) assert self.model.current_index == 0 assert self.dialog.current_item.text(0) == self.dialog.items[0].text(0) # TODO: CANNOT TEST RGB UNTIL AN RGB IMAGE IS ADDED TO THE TEST DATA # @add_widget_wrapper # def test_check_rgb(self, qtbot) @add_widget_wrapper def test_change_image(self, qtbot): def check_selected(index1, index2): assert self.dialog.items[index1].isSelected() assert not self.dialog.items[index2].isSelected() check_selected(0, 1) qtbot.mouseClick(self.window.next_image_btn, QtCore.Qt.LeftButton) check_selected(1, 0) qtbot.mouseClick(self.window.previous_image_btn, QtCore.Qt.LeftButton) check_selected(0, 1) qtbot.mouseClick(self.window.previous_image_btn, QtCore.Qt.LeftButton) check_selected(-1, 0) qtbot.mouseClick(self.window.next_image_btn, QtCore.Qt.LeftButton) check_selected(0, 1) @add_widget_wrapper def test_set_menus_index(self, qtbot): widgets = [ self.dialog.red_widget, self.dialog.green_widget, self.dialog.blue_widget ] def check_currentIndex(): for widget, index in zip(widgets, self.model.menu_indices): assert widget.menu.currentIndex() == index self.model.menu_indices = [0, 1, 2] self.dialog.set_menus_index() check_currentIndex() r, g, b = 4, 0, 2 self.model.menu_indices = [r, g, b] self.dialog.set_menus_index() check_currentIndex() self.model.menu_indices = [0, 1, 2] self.dialog.set_menus_index() check_currentIndex() assert self.model.menu_indices == [0, 1, 2] @add_widget_wrapper def test_update_menus_current_item(self, qtbot): assert self.test_images.rgb == self.model.images[:3] r, g, b = 4, 0, 2 new_rgb = [ self.model.images[r], self.model.images[g], self.model.images[b] ] self.test_images.rgb = new_rgb self.dialog.update_menus_current_item() assert self.model.red_model.index == r assert self.model.green_model.index == g assert self.model.blue_model.index == b red_text = self.dialog.red_widget.menu.currentText() assert red_text == self.model.image_names[r] green_text = self.dialog.green_widget.menu.currentText() assert green_text == self.model.image_names[g] blue_text = self.dialog.blue_widget.menu.currentText() assert blue_text == self.model.image_names[b] self.test_images.rgb = self.model.images[:3] assert self.test_images.rgb == self.model.images[:3] @add_widget_wrapper def test_close_dialog(self, qtbot): assert not self.window.channels_window_is_open qtbot.mouseClick(self.window.channels_button, QtCore.Qt.LeftButton) assert self.window.channels_window_is_open pos = self.dialog.pos() x, y = pos.x(), pos.y() new_pos = QtCore.QPoint(x + 5, y - 10) self.dialog.move(new_pos) qtbot.mouseClick(self.dialog.close_button, QtCore.Qt.LeftButton) assert not self.window.channels_window_is_open assert self.window.channels_window_pos == new_pos qtbot.mouseClick(self.window.channels_button, QtCore.Qt.LeftButton) assert self.window.channels_window_is_open assert self.dialog.pos() == new_pos
class TestBandWidgetModel(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) channels_model = channels_dialog.ChannelsDialogModel(window) model = band_widget.BandWidgetModel(channels_model, 0, 'Test') def test_init1(self): test_name = 'Test1' test_rgb_index = 0 model = band_widget.BandWidgetModel(self.channels_model, test_rgb_index, test_name) assert isinstance(model.max_alpha, float) assert model.max_alpha == 100. assert isinstance(model.min_alpha, float) assert model.min_alpha == 0. assert model._views == set() assert model.name == test_name assert model.rgb_index == test_rgb_index assert model.channels_model == self.channels_model assert model._index == 0 assert model._alpha_value == model.max_alpha def test_init2(self): test_name = 'Test2' test_rgb_index = 2 model = band_widget.BandWidgetModel(self.channels_model, test_rgb_index, test_name) assert isinstance(model.max_alpha, float) assert model.max_alpha == 100. assert isinstance(model.min_alpha, float) assert model.min_alpha == 0. assert model._views == set() assert model.name == test_name assert model.rgb_index == test_rgb_index assert model.channels_model == self.channels_model assert model._index == 2 assert model._alpha_value == model.max_alpha def test_index(self): assert self.model.index == self.model._index def test_selected_image(self): expected_selected_image = self.channels_model.images[self.model.index] assert self.model.selected_image == expected_selected_image def test_update_index(self): assert self.model.index == 0 new_index = 1 new_selected_image = self.channels_model.images[new_index] self.model.update_index(new_index) assert self.model.index == new_index assert self.model.selected_image == new_selected_image new_index = 0 new_selected_image = self.channels_model.images[new_index] self.model.index = new_index assert self.model.index == new_index assert self.model.selected_image == new_selected_image def test_alpha_value(self): assert self.model.alpha_value == self.model._alpha_value self.model.alpha_value = 50. assert self.model.alpha_value == 50. self.model.alpha_value = 100. assert self.model.alpha_value == 100.
class TestBandWidget(object): test_images = pdsview.ImageSet(test_files) window = pdsview.PDSViewer(test_images) channels_model = channels_dialog.ChannelsDialogModel(window) model = band_widget.BandWidgetModel(channels_model, 0, 'Test') band = band_widget.BandWidget(model) def check_menu_text(self): for index, name in enumerate(self.channels_model.image_names): assert self.band.menu.itemText(index) == name def test_init(self): assert self.band.model == self.model assert isinstance(self.band.controller, band_widget.BandWidgetController) assert isinstance(self.band.menu, QtWidgets.QComboBox) assert isinstance(self.band.alpha_slider, QtWidgets.QSlider) assert isinstance(self.band.alpha_value, QtWidgets.QLabel) assert isinstance(self.band.alpha_label, QtWidgets.QLabel) assert isinstance(self.band.layout, QtWidgets.QGridLayout) self.check_menu_text() assert self.band.alpha_value.text() == str(int(self.model.max_alpha)) assert self.band.alpha_label.text() == 'Test %' assert self.band.alpha_slider.value() == self.model.max_alpha def test_add_text_to_menu(self): self.check_menu_text() test_names = ['foo', 'bar'] self.band.add_text_to_menu(test_names) num_names = len(self.channels_model.image_names) assert self.band.menu.itemText(num_names + 0) == test_names[0] assert self.band.menu.itemText(num_names + 1) == test_names[1] self.band.menu.removeItem(num_names + 0) self.band.menu.removeItem(num_names + 1) self.check_menu_text() def test_set_current_index(self): assert self.band.menu.currentIndex() == 0 self.model.index = 1 self.band.set_current_index() assert self.band.menu.currentIndex() == 1 self.model.index = 0 self.band.set_current_index() assert self.band.menu.currentIndex() == 0 def test_image_selected(self): assert self.model.index == 0 new_index = 1 new_selected_image = self.channels_model.images[new_index] self.band.image_selected(new_index) assert self.model.index == new_index assert self.model.selected_image == new_selected_image new_index = 0 new_selected_image = self.channels_model.images[new_index] self.band.image_selected(new_index) assert self.model.index == new_index assert self.model.selected_image == new_selected_image def test_value_changed(self): assert self.model.alpha_value == 100. assert self.band.alpha_value.text() == '100' self.band.alpha_slider.setValue(50.) assert self.model.alpha_value == 50. assert self.band.alpha_value.text() == '50' self.band.alpha_slider.setValue(75.) assert self.model.alpha_value == 75. assert self.band.alpha_value.text() == '75' self.band.alpha_slider.setValue(-1) assert self.model.alpha_value == 0. assert self.band.alpha_value.text() == '0' self.band.alpha_slider.setValue(-100000) assert self.model.alpha_value == 0. assert self.band.alpha_value.text() == '0' self.band.alpha_slider.setValue(101) assert self.model.alpha_value == 100. assert self.band.alpha_value.text() == '100' self.band.alpha_slider.setValue(10000) assert self.model.alpha_value == 100. self.band.alpha_slider.setValue(0) assert self.band.alpha_value.text() == '0' assert self.model.alpha_value == 0. self.band.alpha_slider.setValue(100) assert self.model.alpha_value == 100. assert self.band.alpha_value.text() == '100'