def test_construction_from_file(self): """_Image(path) constructor produces correct attribute values""" # exercise --------------------- image = _Image(test_image_path) # verify ----------------------- assert_that(image.ext, is_(equal_to('.jpeg'))) assert_that(image._content_type, is_(equal_to('image/jpeg'))) assert_that(len(image._blob), is_(equal_to(3277))) assert_that(image._desc, is_(equal_to('python-icon.jpeg')))
def test_construction_from_stream(self): """_Image(stream) construction produces correct attribute values""" # exercise --------------------- with open(test_image_path) as f: stream = StringIO(f.read()) image = _Image(stream) # verify ----------------------- assert_that(image.ext, is_(equal_to('.jpg'))) assert_that(image._content_type, is_(equal_to('image/jpeg'))) assert_that(len(image._blob), is_(equal_to(3277))) assert_that(image._desc, is_(equal_to('image.jpg')))
def test__scale_calculates_correct_dimensions(self): """_Image._scale() calculates correct dimensions""" # setup ------------------------ test_cases = ( ((None, None), (Px(204), Px(204))), ((1000, None), (1000, 1000)), ((None, 3000), (3000, 3000)), ((3337, 9999), (3337, 9999))) image = _Image(test_image_path) # verify ----------------------- for params, expected in test_cases: width, height = params assert_that(image._scale(width, height), is_(equal_to(expected)))
def test__size_returns_image_native_pixel_dimensions(self): """_Image._size is width, height tuple of image pixel dimensions""" image = _Image(test_image_path) assert_that(image._size, is_(equal_to((204, 204))))
def test_construction_from_file_raises_on_bad_path(self): """_Image(path) constructor raises on bad path""" # verify ----------------------- with self.assertRaises(IOError): _Image('foobar27.png')