def test_init_simple_add_rgba(): """ simplest possible initilization -- no preset color palette """ img = Image(width=400, height=400, preset_colors=None) img.add_color('white', (255, 255, 255, 127))
def test_add_colors_max(): img = Image(10, 10, preset_colors='BW') # should be able to add this many: for i in range(253): img.add_color("color_%i" % i, (i, i, i)) # adding one more should raise an exception: with pytest.raises(ValueError): img.add_color("color_max", (10, 100, 200))
def test_add_colors_repeat(): img = Image(10, 10, preset_colors='BW') index_1 = img.add_color('blue', (0, 0, 255)) with pytest.raises(ValueError): # adding one with the same name should raise an exception img.add_color('blue', (0, 0, 200)) # Adding the same color with a different name: # adds another index -- should it? index_2 = img.add_color('full_blue', (0, 0, 255)) assert index_1 != index_2
def test_add_colors(): img = Image(10, 10, preset_colors='BW') assert img.get_color_names() == ['transparent', 'black', 'white'] img.add_color('light grey', (220, 220, 220)) assert img.get_color_names() == [ 'transparent', 'black', 'white', 'light grey' ] assert img.get_color_index('light grey') == 3 img.draw_rectangle((2, 2), (7, 7), fill_color='light grey') img.save(outfile('test_image_grey.bmp')) with pytest.raises(ValueError): # color doesn't exist img.draw_rectangle((2, 2), (7, 7), fill_color='red')