def test_compress_smaller_b(self): ''' Function to test that an exception gets raised when a smaller b needs to be chosen in order to compress the image ''' with pytest.raises(Exception): compress(big_img, 4, outpath)
def test_compress_already_compressed(self): ''' Function to test that the function raises exceptions when images that cannot be compressed further are passed in ''' with pytest.raises(Exception): compress(small_img, 8, outpath) with pytest.raises(Exception): compress(small_img, 1, outpath)
def test_compress_shape(self): ''' Function to test that compressed image shape is the same ''' com_path = compress(img_path, 3, outpath) assert imread(com_path).shape == imread(img_path).shape com_path = compress(img_path, 1, outpath) assert imread(com_path).shape == imread(img_path).shape com_path = compress(img_path, 6, outpath) assert imread(com_path).shape == imread(img_path).shape
def test_compress_value(self): ''' Function to test that a ValueError is raised when invalid values are passed in for b ''' with pytest.raises(ValueError): compress(img_path, -1, outpath) with pytest.raises(ValueError): compress(img_path, 9, outpath) with pytest.raises(ValueError): compress(img_path, 0, outpath) with pytest.raises(ValueError): compress(img_path, 1000, outpath) with pytest.raises(ValueError): compress(img_path, -1000, outpath)
def test_compress_size(self): ''' Function to test that the size of the compressed image is correct ''' compressed_img = compress(img_path, 3, outpath) assert image_size(compressed_img) < 7 / 8 * image_size(img_path) compressed_img = compress(img_path, 1, outpath) assert image_size(compressed_img) < 5 / 8 * image_size(img_path) compressed_img = compress(img_path, 6, outpath) assert image_size(compressed_img) <= 8 / 8 * image_size(img_path) compressed_img = compress(img_path, 8, outpath) assert image_size(compressed_img) <= image_size(img_path)
def test_compress_type(self): ''' Function to test that a TypeError is raised when an invalid type is passed in for image or b ''' with pytest.raises(TypeError): compress(img_path, 6.5, outpath) with pytest.raises(TypeError): compress(imread(img_path), 2, outpath) with pytest.raises(TypeError): compress(5, True, outpath) with pytest.raises(TypeError): compress(img_path, 3, 5)