-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtest_saveload.py
75 lines (56 loc) · 1.93 KB
/
test_saveload.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# vim: set fileencoding=utf-8 :
import os
import tempfile
import pyvips
from pathlib import Path
from helpers import temp_filename, skip_if_no, IMAGES, JPEG_FILE
class TestSaveLoad:
@classmethod
def setup_class(cls):
cls.tempdir = tempfile.mkdtemp()
@skip_if_no('jpegload')
def test_save_file(self):
filename = temp_filename(self.tempdir, '.jpg')
im = pyvips.Image.black(10, 20)
im.write_to_file(filename)
assert os.path.isfile(filename)
os.remove(filename)
@skip_if_no('jpegload')
def test_load_file(self):
filename = temp_filename(self.tempdir, '.jpg')
im = pyvips.Image.black(10, 20)
im.write_to_file(filename)
x = pyvips.Image.new_from_file(filename)
assert x.width == 10
assert x.height == 20
assert x.bands == 1
os.remove(x.filename)
@skip_if_no('jpegload')
def test_save_file_pathlib(self):
filename = Path(temp_filename(self.tempdir, '.jpg'))
im = pyvips.Image.black(10, 20)
im.write_to_file(filename)
assert filename.exists()
filename.unlink()
@skip_if_no('jpegload')
def test_load_file_pathlib(self):
filename = Path(IMAGES) / 'sample.jpg'
assert filename.exists()
im_a = pyvips.Image.new_from_file(JPEG_FILE)
im_b = pyvips.Image.new_from_file(filename)
assert im_a.bands == im_b.bands
assert im_a.width == im_b.width
assert im_a.height == im_b.height
@skip_if_no('jpegload')
def test_save_buffer(self):
im = pyvips.Image.black(10, 20)
buf = im.write_to_buffer('.jpg')
assert len(buf) > 100
@skip_if_no('jpegload')
def test_load_buffer(self):
im = pyvips.Image.black(10, 20)
buf = im.write_to_buffer('.jpg')
x = pyvips.Image.new_from_buffer(buf, '')
assert x.width == 10
assert x.height == 20
assert x.bands == 1