Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
8dedb440
Commit
8dedb440
authored
1 year ago
by
Manon Blanco
Browse files
Options
Downloads
Patches
Plain Diff
Allow to create element without zone and on folder
parent
19675ca5
No related branches found
Branches containing commit
Tags
0.3.2
Tags containing commit
1 merge request
!473
Allow to create element without zone and on folder
Pipeline
#148486
passed
1 year ago
Stage: test
Stage: build
Stage: release
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/element.py
+25
-12
25 additions, 12 deletions
arkindex_worker/worker/element.py
tests/test_elements_worker/test_elements.py
+39
-15
39 additions, 15 deletions
tests/test_elements_worker/test_elements.py
with
64 additions
and
27 deletions
arkindex_worker/worker/element.py
+
25
−
12
View file @
8dedb440
...
...
@@ -86,8 +86,9 @@ class ElementMixin:
element
:
Element
,
type
:
str
,
name
:
str
,
polygon
:
list
[
list
[
int
|
float
]],
polygon
:
list
[
list
[
int
|
float
]]
|
None
=
None
,
confidence
:
float
|
None
=
None
,
image
:
str
|
None
=
None
,
slim_output
:
bool
=
True
,
)
->
str
:
"""
...
...
@@ -96,8 +97,10 @@ class ElementMixin:
:param Element element: The parent element.
:param type: Slug of the element type for this child element.
:param name: Name of the child element.
:param polygon:
P
olygon of the child element.
:param polygon:
Optional p
olygon of the child element.
:param confidence: Optional confidence score, between 0.0 and 1.0.
:param image: Optional image ID of the child element.
:param slim_output: Whether to return the child ID or the full child.
:returns: UUID of the created element.
"""
assert
element
and
isinstance
(
...
...
@@ -109,19 +112,29 @@ class ElementMixin:
assert
name
and
isinstance
(
name
,
str
),
"
name shouldn
'
t be null and should be of type str
"
assert
polygon
and
isinstance
(
assert
polygon
is
None
or
isinstance
(
polygon
,
list
),
"
polygon shouldn
'
t be null and should be of type list
"
assert
len
(
polygon
)
>=
3
,
"
polygon should have at least three points
"
assert
all
(
isinstance
(
point
,
list
)
and
len
(
point
)
==
2
for
point
in
polygon
),
"
polygon points should be lists of two items
"
assert
all
(
isinstance
(
coord
,
int
|
float
)
for
point
in
polygon
for
coord
in
point
),
"
polygon points should be lists of two numbers
"
),
"
polygon should be None or a list
"
if
polygon
is
not
None
:
assert
len
(
polygon
)
>=
3
,
"
polygon should have at least three points
"
assert
all
(
isinstance
(
point
,
list
)
and
len
(
point
)
==
2
for
point
in
polygon
),
"
polygon points should be lists of two items
"
assert
all
(
isinstance
(
coord
,
int
|
float
)
for
point
in
polygon
for
coord
in
point
),
"
polygon points should be lists of two numbers
"
assert
confidence
is
None
or
(
isinstance
(
confidence
,
float
)
and
0
<=
confidence
<=
1
),
"
confidence should be None or a float in [0..1] range
"
assert
image
is
None
or
isinstance
(
image
,
str
),
"
image should be None or string
"
if
image
is
not
None
:
# Make sure it's a valid UUID
try
:
UUID
(
image
)
except
ValueError
as
e
:
raise
ValueError
(
"
image is not a valid uuid.
"
)
from
e
if
polygon
and
image
is
None
:
assert
element
.
zone
,
"
An image or a parent with an image is required to create an element with a polygon.
"
assert
isinstance
(
slim_output
,
bool
),
"
slim_output should be of type bool
"
if
self
.
is_read_only
:
...
...
@@ -133,7 +146,7 @@ class ElementMixin:
body
=
{
"
type
"
:
type
,
"
name
"
:
name
,
"
image
"
:
element
.
zone
.
image
.
id
,
"
image
"
:
image
,
"
corpus
"
:
element
.
corpus
.
id
,
"
polygon
"
:
polygon
,
"
parent
"
:
element
.
id
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_elements.py
+
39
−
15
View file @
8dedb440
...
...
@@ -428,19 +428,7 @@ def test_create_sub_element_wrong_name(mock_elements_worker):
def
test_create_sub_element_wrong_polygon
(
mock_elements_worker
):
elt
=
Element
({
"
zone
"
:
None
})
with
pytest
.
raises
(
AssertionError
,
match
=
"
polygon shouldn
'
t be null and should be of type list
"
):
mock_elements_worker
.
create_sub_element
(
element
=
elt
,
type
=
"
something
"
,
name
=
"
0
"
,
polygon
=
None
,
)
with
pytest
.
raises
(
AssertionError
,
match
=
"
polygon shouldn
'
t be null and should be of type list
"
):
with
pytest
.
raises
(
AssertionError
,
match
=
"
polygon should be None or a list
"
):
mock_elements_worker
.
create_sub_element
(
element
=
elt
,
type
=
"
something
"
,
...
...
@@ -504,6 +492,42 @@ def test_create_sub_element_wrong_confidence(mock_elements_worker, confidence):
)
@pytest.mark.parametrize
(
(
"
image
"
,
"
error_type
"
,
"
error_message
"
),
[
(
1
,
AssertionError
,
"
image should be None or string
"
),
(
"
not a uuid
"
,
ValueError
,
"
image is not a valid uuid.
"
),
],
)
def
test_create_sub_element_wrong_image
(
mock_elements_worker
,
image
,
error_type
,
error_message
):
with
pytest
.
raises
(
error_type
,
match
=
re
.
escape
(
error_message
)):
mock_elements_worker
.
create_sub_element
(
element
=
Element
({
"
zone
"
:
None
}),
type
=
"
something
"
,
name
=
"
blah
"
,
polygon
=
[[
0
,
0
],
[
0
,
10
],
[
10
,
10
],
[
10
,
0
],
[
0
,
0
]],
image
=
image
,
)
def
test_create_sub_element_wrong_image_and_polygon
(
mock_elements_worker
):
with
pytest
.
raises
(
AssertionError
,
match
=
re
.
escape
(
"
An image or a parent with an image is required to create an element with a polygon.
"
),
):
mock_elements_worker
.
create_sub_element
(
element
=
Element
({
"
zone
"
:
None
}),
type
=
"
something
"
,
name
=
"
blah
"
,
polygon
=
[[
0
,
0
],
[
0
,
10
],
[
10
,
10
],
[
10
,
0
],
[
0
,
0
]],
image
=
None
,
)
def
test_create_sub_element_api_error
(
responses
,
mock_elements_worker
):
elt
=
Element
(
{
...
...
@@ -580,7 +604,7 @@ def test_create_sub_element(responses, mock_elements_worker, slim_output):
assert
json
.
loads
(
responses
.
calls
[
-
1
].
request
.
body
)
==
{
"
type
"
:
"
something
"
,
"
name
"
:
"
0
"
,
"
image
"
:
"
22222222-2222-2222-2222-222222222222
"
,
"
image
"
:
None
,
"
corpus
"
:
"
11111111-1111-1111-1111-111111111111
"
,
"
polygon
"
:
[[
1
,
1
],
[
2
,
2
],
[
2
,
1
],
[
1
,
2
]],
"
parent
"
:
"
12341234-1234-1234-1234-123412341234
"
,
...
...
@@ -625,7 +649,7 @@ def test_create_sub_element_confidence(responses, mock_elements_worker):
assert
json
.
loads
(
responses
.
calls
[
-
1
].
request
.
body
)
==
{
"
type
"
:
"
something
"
,
"
name
"
:
"
0
"
,
"
image
"
:
"
22222222-2222-2222-2222-222222222222
"
,
"
image
"
:
None
,
"
corpus
"
:
"
11111111-1111-1111-1111-111111111111
"
,
"
polygon
"
:
[[
1
,
1
],
[
2
,
2
],
[
2
,
1
],
[
1
,
2
]],
"
parent
"
:
"
12341234-1234-1234-1234-123412341234
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment