def check_res(colormap): return ( len(colormap.colors) == 4 and np.allclose(colormap.colors[1], color_from_qcolor(color1)) and np.allclose(colormap.colors[2], color_from_qcolor(color2)) and colormap.controls[1] == 0.1 and colormap.controls[2] == 0.8)
def test_custom_colors_save(self, qtbot): settings = ViewSettings() widget = PColormapCreator(settings) qtbot.addWidget(widget) color1 = QColor(10, 40, 12) color2 = QColor(100, 4, 220) widget.color_picker.setCustomColor(2, color1) widget.color_picker.setCustomColor(7, color2) widget._save_custom_colors() custom_color_list = settings.get_from_profile("custom_colors") assert custom_color_list[2] == color_from_qcolor(color1) assert custom_color_list[7] == color_from_qcolor(color2) widget2 = PColormapCreator(settings) assert widget2.color_picker.customColor(2) == color1 assert widget2.color_picker.customColor(7) == color2
def test_distribute(self, qtbot): widget = ColormapCreator() qtbot.addWidget(widget) color1 = QColor(10, 40, 12) color2 = QColor(100, 4, 220) color3 = QColor(100, 24, 220) color4 = QColor(100, 134, 22) color5 = QColor(100, 134, 122) widget.color_picker.setCurrentColor(color1) widget.add_color(0.1) widget.color_picker.setCurrentColor(color2) widget.add_color(0.3) widget.color_picker.setCurrentColor(color3) widget.add_color(0.6) widget.color_picker.setCurrentColor(color4) widget.add_color(0.9) widget.color_picker.setCurrentColor(color5) widget.add_color(0.95) li = widget.current_colormap() for el, pos, col in zip( li, [0.1, 0.3, 0.6, 0.9, 0.95], [ color_from_qcolor(color1), color_from_qcolor(color2), color_from_qcolor(color3), color_from_qcolor(color4), color_from_qcolor(color5), ], ): assert el.color_position == pos assert el.color == col widget.distribute_btn.click() li = widget.current_colormap() for el, pos, col in zip( li, [0, 0.25, 0.5, 0.75, 1], [ color_from_qcolor(color1), color_from_qcolor(color2), color_from_qcolor(color3), color_from_qcolor(color4), color_from_qcolor(color5), ], ): assert el.color_position == pos assert el.color == col
def test_color_conversion(): color1 = QColor(70, 52, 190) color2 = color_from_qcolor(color1) assert qcolor_from_color(color2) == color1 assert color_from_qcolor(qcolor_from_color(color2)) == color2
def check_res(colormap): return (len(colormap) == 2 and colormap[0].color == color_from_qcolor(color1) and colormap[1].color == color_from_qcolor(color2) and colormap[0].color_position == 0.1 and colormap[1].color_position == 0.8)
def test_distribute(self, qtbot): widget = ColormapCreator() qtbot.addWidget(widget) color1 = QColor(10, 40, 12) color2 = QColor(100, 4, 220) color3 = QColor(100, 24, 220) color4 = QColor(100, 134, 22) color5 = QColor(100, 134, 122) widget.color_picker.setCurrentColor(color1) widget.add_color(0.1) widget.color_picker.setCurrentColor(color2) widget.add_color(0.3) widget.color_picker.setCurrentColor(color3) widget.add_color(0.6) widget.color_picker.setCurrentColor(color4) widget.add_color(0.9) widget.color_picker.setCurrentColor(color5) widget.add_color(0.95) li = widget.current_colormap() assert np.array_equal(li.controls, [0, 0.1, 0.3, 0.6, 0.9, 0.95, 1]) for el, col in zip( li.colors, [ color_from_qcolor(color1), color_from_qcolor(color1), color_from_qcolor(color2), color_from_qcolor(color3), color_from_qcolor(color4), color_from_qcolor(color5), color_from_qcolor(color5), ], ): assert np.allclose(el, col) widget.distribute_btn.click() li = widget.current_colormap() assert np.array_equal(li.controls, [0, 0.25, 0.5, 0.75, 1]) for el, col in zip( li.colors, [ color_from_qcolor(color1), color_from_qcolor(color2), color_from_qcolor(color3), color_from_qcolor(color4), color_from_qcolor(color5), ], ): assert np.allclose(el, col)