-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_encode.py
48 lines (29 loc) · 1.08 KB
/
test_encode.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
45
46
47
48
from __future__ import absolute_import
import pytest
from blurhash import encode
def test_encode_file():
with open('tests/pic2.png', 'rb') as image_file:
result = encode(image_file, 4, 3)
assert result == b'LlMF%n00%#MwS|WCWEM{R*bbWBbH'
def test_encode_with_filename():
result = encode('tests/pic2.png', 4, 3)
assert result == b'LlMF%n00%#MwS|WCWEM{R*bbWBbH'
def test_encode_black_and_white_picture():
result = encode('tests/pic2_bw.png', 4, 3)
assert result == b'LjIY5?00?bIUofWBWBM{WBofWBj['
def test_invalid_image():
with pytest.raises(IOError):
encode('README.md', 4, 3)
def test_file_does_not_exist():
with pytest.raises(IOError):
encode('pic404.png', 4, 3)
def test_invalid_x_components():
with pytest.raises(ValueError):
encode('tests/pic2.png', 10, 3)
with pytest.raises(ValueError):
encode('tests/pic2.png', 0, 3)
def test_invalid_y_components():
with pytest.raises(ValueError):
encode('tests/pic2.png', 4, 10)
with pytest.raises(ValueError):
encode('tests/pic2.png', 4, 0)