Skip to content

Commit 43da8c6

Browse files
authored
Merge pull request #13 from dev-yoonik/fix/process-configuration-default-value
Fixed configurations default value.
2 parents 21560da + f58ab7f commit 43da8c6

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v0.3.4
9+
10+
### Added
11+
12+
- Extra face process request argument 'processings' validations.
13+
14+
### Fixed
15+
16+
- Process default configurations value to empty array instead of None.
17+
818
## v0.3.3
919

1020
### Fixed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="yk_face",
8-
version="0.3.3",
8+
version="0.3.4",
99
description="Python SDK for the YouFace API.",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

tests/test_face.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ def loop():
4343

4444
@pytest.mark.parametrize('use_async', [(True,), (False,)])
4545
@pytest.mark.parametrize('configurations', [
46+
None,
47+
[],
4648
[
4749
ProcessRequestConfig(name="config1", value="12490812.523"),
4850
ProcessRequestConfig(name="config1.1", value="stringvalue"),
4951
ProcessRequestConfig(name="config2", bvalue=True),
5052
ProcessRequestConfig(name="config3", bvalue=False),
51-
]
53+
],
5254
])
5355
def test_face_process_with_valid_image(
5456
use_async: bool,
@@ -84,6 +86,91 @@ def test_face_process_with_valid_image(
8486
__template = detected_face.get("template")
8587

8688

89+
@pytest.mark.parametrize('use_async', [(True,), (False,)])
90+
@pytest.mark.parametrize('processings', [
91+
None,
92+
["detect", "analyze"],
93+
["detect", "templify"],
94+
["detect", "analyze", "templify"],
95+
])
96+
def test_face_process_processings(
97+
use_async: bool,
98+
processings,
99+
loop: asyncio.AbstractEventLoop
100+
):
101+
"""
102+
Test sync and async process request method when passed valid processings values.
103+
:param use_async: flag to use the async function
104+
:param loop: event loop for the current test
105+
:return:
106+
"""
107+
try:
108+
if use_async:
109+
loop.run_until_complete(
110+
YKF.face.process_async(
111+
__image_file,
112+
configurations=[],
113+
processings=processings,
114+
)
115+
)
116+
else:
117+
YKF.face.process(__image_file)
118+
except YoonikApiException as exc:
119+
raise exc
120+
121+
122+
@pytest.mark.parametrize('use_async', [(True,), (False,)])
123+
@pytest.mark.parametrize('processings', [[]])
124+
def test_face_process_with_invalid_empty_processings(
125+
use_async: bool,
126+
processings,
127+
loop: asyncio.AbstractEventLoop
128+
):
129+
"""
130+
Test sync and async process request method when passed processings with empty values.
131+
:param use_async: flag to use the async function
132+
:param loop: event loop for the current test
133+
:return:
134+
"""
135+
with pytest.raises(ValueError):
136+
if use_async:
137+
loop.run_until_complete(
138+
YKF.face.process_async(
139+
__image_file,
140+
configurations=[],
141+
processings=processings,
142+
)
143+
)
144+
else:
145+
YKF.face.process(__image_file)
146+
147+
148+
@pytest.mark.parametrize('use_async', [(True,), (False,)])
149+
@pytest.mark.parametrize('processings', [1, "2", b"4", dict(), set()])
150+
def test_face_process_with_invalid_processings(
151+
use_async: bool,
152+
processings,
153+
loop: asyncio.AbstractEventLoop
154+
):
155+
"""
156+
Test sync and async process request method when passed processing of incorrect type.
157+
:param use_async: flag to use the async function
158+
:param loop: event loop for the current test
159+
:return:
160+
"""
161+
with pytest.raises(TypeError):
162+
if use_async:
163+
loop.run_until_complete(
164+
YKF.face.process_async(
165+
__image_file,
166+
configurations=[],
167+
processings=processings,
168+
)
169+
)
170+
else:
171+
YKF.face.process(__image_file)
172+
173+
87174
@pytest.mark.parametrize('use_async', [(True,), (False,)])
88175
@pytest.mark.parametrize('configurations', [
89176
[

yk_face/face.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ def __process_request_validation(
4040
raise ValueError("image must be provided")
4141

4242
image_b64 = parse_image(image)
43+
configurations = configurations or []
4344
if processings is None:
4445
processings = ['detect', 'analyze', 'templify']
46+
elif type(processings) is not list:
47+
raise TypeError("The provided processings are not of expected type.")
48+
elif len(processings) == 0:
49+
raise ValueError("The processings were not provided.")
50+
4551
process_request = ProcessRequest(
4652
image=image_b64,
4753
processings=processings,

0 commit comments

Comments
 (0)