-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_image.py
44 lines (30 loc) · 1.07 KB
/
test_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals
from pathlib import Path
from pytest import fixture
from .. import CROP, SCALE, get_save_format, get_size, resize
@fixture
def orig_image():
# 725x518
return (Path(__file__).parent / "cat.jpg").open("rb").read()
def test_get_save_format():
assert get_save_format("JPG") == "JPEG"
assert get_save_format("JPEG") == "JPEG"
assert get_save_format("PNG") == "PNG"
assert get_save_format("GIF") == "PNG"
assert get_save_format("unknown") == "JPEG"
def test_fit(orig_image):
image = resize(orig_image, 500, 500)
x, y = get_size(image)
assert (x, y) == (500, 357)
# image already fits in desired dimension
image = resize(orig_image, 1000, 1000)
x, y = get_size(image)
assert x == 725 and y == 518
def test_scale(orig_image):
image = resize(orig_image, 500, 500, SCALE)
assert get_size(image) == (500, 500)
def test_crop(orig_image):
image = resize(orig_image, 500, 500, CROP)
assert get_size(image) == (500, 500)