def test_static_animation(): img1 = Image(200, 200) img2 = Image(200, 200) endpoints = np.array(((-100, 0), (100, 0))) offset = np.array((100, 100)) fname = "test_animation.gif" anim = Animation(outfile(fname)) anim.begin_anim(img1, 0) for ang in range(0, 360, 10): rad = np.deg2rad(ang) rot_matrix = [(np.cos(rad), np.sin(rad)), (-np.sin(rad), np.cos(rad))] points = np.dot(endpoints, rot_matrix).astype(np.int32) + offset img1.draw_line(points[0], points[1], 'red') img2.draw_line(points[0], points[1], 'red') assert img1 == img2 anim.add_frame(img1) anim.add_frame(img2) anim.close_anim() print anim.frames_written
def test_overflow(self): ''' Big enough to overflow an 32 bit int ''' img = Image(10, 10) val = int(2 ** 33) with pytest.raises(OverflowError): img.draw_line((-val, -val), (val, val), 'white', line_width=2)
def test_negative(self): '''negative coords value too large''' img = Image(10, 10) img.draw_line((-100, -100), (10, 10), 'white', line_width=2) # save this as an array arr = np.array(img) assert np.array_equal(arr, self.line_arr)
def test_outside(self): '''second value too large''' img = Image(10, 10) img.draw_line((0, 0), (100, 100), 'white', line_width=2) # save this as an array arr = np.array(img) assert np.array_equal(arr, self.line_arr)
def test_inside(self): '''just to make sure the comparing is working''' img = Image(10, 10) img.draw_line((0, 0), (10, 10), 'white', line_width=2) # save this one as an array arr = np.array(img) assert np.array_equal(arr, self.line_arr)
def test_overflow(self): ''' Big enough to overflow an 32 bit int ''' img = Image(10, 10) val = int(2**33) with pytest.raises(OverflowError): img.draw_line((-val, -val), (val, val), 'white', line_width=2)
def test_clip_draw(): img = Image(100, 100) img.clip_rect = ((20, 20), (80, 80)) img.draw_line((0, 0), (100, 100), color='red', line_width=4) img.draw_line((0, 100), (100, 0), color='blue', line_width=4) fname = "image_clip.bmp" img.save(outfile(fname)) assert check_file(fname)
def test_array(): img = Image(10, 5) img.draw_line((0, 0), (9, 4), 'black', line_width=1) print "result from __array__", img.__array__() arr = np.asarray(img) assert np.array_equal( arr, [[1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1]])
def test_line(): img = Image(100, 200) img.draw_line((0, 0), (99, 199), 'white') img.draw_line((0, 199), (99, 0), 'red', line_width=2) img.draw_line((0, 100), (99, 100), 'green', line_width=4) img.draw_line((50, 0), (50, 199), 'blue', line_width=8) img.save(outfile("test_image_line.bmp")) assert check_file("test_image_line.bmp") with pytest.raises(TypeError): img.draw_line((0, 0), (99, 199), 'white', line_width='fred')
def test_big(self): ''' really big values, negative and positive, but not quite enough to overflow an integer ''' img = Image(10, 10) val = int(2 ** 30) img.draw_line((-val, -val), (val, val), 'white', line_width=2) # save this as an array arr = np.array(img) assert np.array_equal(arr, self.line_arr)
def test_save_image(filetype): img = Image(400, 300) img.draw_line((0, 0), (399, 299), 'white', line_width=4) img.draw_line((0, 299), (399, 0), 'green', line_width=4) fname = "test_image_save." + filetype img.save(outfile(fname), filetype) if filetype is not "jpg": # jpeg is lossy and thus inconsistent assert check_file(fname) with pytest.raises(ValueError): img.save(outfile("test_image1.something"), "random_string")
def test_big(self): ''' really big values, negative and positive, but not quite enough to overflow an integer ''' img = Image(10, 10) val = int(2**30) img.draw_line((-val, -val), (val, val), 'white', line_width=2) # save this as an array arr = np.array(img) assert np.array_equal(arr, self.line_arr)
def test_line_clip(): img = Image(100, 200) img.draw_line((-30, -10), (150, 250), 'white') img.save(outfile("test_image_line_clip.bmp"))