-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtest_api.py
57 lines (42 loc) · 2.11 KB
/
test_api.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
# texturize — Copyright (c) 2020, Novelty Factory KG. See LICENSE for details.
import torch
import pytest
import PIL.ImageOps
from texturize import api, commands
def test_api_remix(image, size):
remix = commands.Remix(source=image)
for r in api.process_octaves(remix, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)
def test_api_remake(image, size):
remake = commands.Remake(target=image, source=image)
for r in api.process_octaves(remake, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)
def test_api_mashup(image, size):
mashup = commands.Mashup(sources=[image, image])
for r in api.process_octaves(mashup, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)
def test_api_enhance(image, size):
mashup = commands.Enhance(target=image, source=image, zoom=2)
for r in api.process_octaves(mashup, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)
def test_api_expand(image, size):
expand = commands.Expand(target=image, source=image, factor=(1.5, 1.5))
for r in api.process_octaves(expand, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)
def test_api_repair(image, size):
src = PIL.ImageOps.mirror(image)
repair = commands.Repair(target=image.convert("RGBA"), source=src)
for r in api.process_octaves(repair, size=size, iterations=2):
assert len(r.tensor) == 1
assert isinstance(r.tensor, torch.Tensor)
assert r.tensor.shape[2:] == (size[1] // r.scale, size[0] // r.scale)