def test_views_non_contiguous(): A = np.arange(16).reshape((4, 4)) A = A[::2, :] with all_warnings(): assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2)) assert_warns(RuntimeWarning, view_as_windows, A, (2, 2))
def test_update_on_save(): pic = novice.Picture(array=np.zeros((3, 3, 3))) with all_warnings(): # precision loss pic.size = (6, 6) assert pic.modified assert pic.path is None fd, filename = tempfile.mkstemp(suffix=".jpg") os.close(fd) try: pic.save(filename) assert not pic.modified assert_equal(pic.path, os.path.abspath(filename)) assert_equal(pic.format, "jpeg") finally: os.unlink(filename)
def test_update_on_save(): pic = novice.Picture(array=np.zeros((3, 3, 3))) # prevent attempting to save low-contrast image pic[0, 0] = (255, 255, 255) with all_warnings(): # precision loss pic.size = (6, 6) assert pic.modified assert pic.path is None fd, filename = tempfile.mkstemp(suffix=".png") os.close(fd) try: pic.save(filename) assert not pic.modified assert_equal(pic.path, os.path.abspath(filename)) assert_equal(pic.format, "png") finally: os.unlink(filename)
def test_modify(): pic = novice.open(SMALL_IMAGE_PATH) assert_equal(pic.modified, False) for p in pic: if p.x < (pic.width / 2): p.red /= 2 p.green /= 2 p.blue /= 2 for p in pic: if p.x < (pic.width / 2): assert p.red <= 128 assert p.green <= 128 assert p.blue <= 128 s = pic.size with all_warnings(): # precision loss pic.size = (pic.width / 2, pic.height / 2) assert_equal(pic.size, (int(s[0] / 2), int(s[1] / 2))) assert pic.modified assert pic.path is None
def test_negative_intensity(): with all_warnings(): labels = np.arange(100).reshape(10, 10) image = -1 * np.ones((10, 10)) assert_warns(UserWarning, label2rgb, labels, image)