This repository has been archived by the owner on Apr 17, 2021. It is now read-only.
forked from kebu/py-avataaars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
85 lines (71 loc) · 2.53 KB
/
test.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
76
77
78
79
80
81
82
83
84
85
import tempfile
import pathlib
import pytest
import py_avataaars as pa
attrs = dict(
style=pa.AvatarStyle,
skin_color=pa.SkinColor,
hair_color=pa.HairColor,
facial_hair_type=pa.FacialHairType,
facial_hair_color=dict(
facial_hair_color=pa.FacialHairColor,
facial_hair_type=pa.FacialHairType.BEARD_MAJESTIC,
),
top_type=pa.TopType,
hat_color=dict(
hat_color=pa.ClotheColor,
top_type=pa.TopType.HAT,
),
mouth_type=pa.MouthType,
eye_type=pa.EyesType,
nose_type=pa.NoseType,
eyebrow_type=pa.EyebrowType,
accessories_type=pa.AccessoriesType,
clothe_type=pa.ClotheType,
clothe_color=pa.ClotheColor,
clothe_graphic_type=pa.ClotheGraphicType,
)
@pytest.fixture(scope="session")
def image_file(tmpdir_factory):
fn = tmpdir_factory.mktemp("data").join("img.png")
avatar = pa.PyAvataaar(mouth_type=pa.MouthType.SMILE, )
avatar.render_png_file(str(fn))
return fn
def test_create_avataaar(image_file):
assert image_file.exists()
def test_create_all():
with tempfile.TemporaryDirectory() as tmp_dir_name:
for attr, value in attrs.items():
print(f"Rendering {attr}")
attributes = {}
if isinstance(value, dict):
new_value = value.pop(attr)
attributes.update(value)
value = new_value
for attr_type in value:
attributes.update({
attr: attr_type,
})
avatar = pa.PyAvataaar(**attributes)
avatar_file = pathlib.Path(tmp_dir_name).joinpath(f'{attr_type.name.lower()}.png')
avatar.render_png_file(str(avatar_file))
assert avatar_file.exists()
@pytest.mark.skip
def test_create_all_locally():
output_dir = pathlib.Path(__file__).parent.joinpath('out')
for attr, value in attrs.items():
print(f"Rendering {attr}")
attr_types_dir = output_dir.joinpath(attr)
attr_types_dir.mkdir(parents=True, exist_ok=True)
attributes = {}
if isinstance(value, dict):
new_value = value.pop(attr)
attributes.update(value)
value = new_value
for attr_type in value:
attributes.update({
attr: attr_type,
})
avatar = pa.PyAvataaar(**attributes)
avatar.render_png_file(str(attr_types_dir.joinpath(f'{attr_type.name.lower()}.png')))
avatar.render_svg_file(str(attr_types_dir.joinpath(f'{attr_type.name.lower()}.svg')))