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
47ced4f6
Commit
47ced4f6
authored
4 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Patches
Plain Diff
Support existing identical classifications.
parent
a085c87e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!26
Support existing identical classifications.
Pipeline
#77980
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker.py
+28
-10
28 additions, 10 deletions
arkindex_worker/worker.py
tests/test_elements_worker.py
+51
-0
51 additions, 0 deletions
tests/test_elements_worker.py
with
79 additions
and
10 deletions
arkindex_worker/worker.py
+
28
−
10
View file @
47ced4f6
...
...
@@ -350,16 +350,34 @@ class ElementsWorker(BaseWorker):
)
return
self
.
api_client
.
request
(
"
CreateClassification
"
,
body
=
{
"
element
"
:
element
.
id
,
"
ml_class
"
:
self
.
get_ml_class_id
(
element
.
corpus
.
id
,
ml_class
),
"
worker_version
"
:
self
.
worker_version_id
,
"
confidence
"
:
confidence
,
"
high_confidence
"
:
high_confidence
,
},
)
try
:
self
.
api_client
.
request
(
"
CreateClassification
"
,
body
=
{
"
element
"
:
element
.
id
,
"
ml_class
"
:
self
.
get_ml_class_id
(
element
.
corpus
.
id
,
ml_class
),
"
worker_version
"
:
self
.
worker_version_id
,
"
confidence
"
:
confidence
,
"
high_confidence
"
:
high_confidence
,
},
)
except
ErrorResponse
as
e
:
# Detect already existing classification
if
(
e
.
status_code
==
400
and
"
non_field_errors
"
in
e
.
content
and
"
The fields element, worker_version, ml_class must make a unique set.
"
in
e
.
content
[
"
non_field_errors
"
]
):
logger
.
warning
(
f
"
This worker version has already set
{
ml_class
}
on element
{
element
.
id
}
"
)
return
# Propagate any other API error
raise
self
.
report
.
add_classification
(
element
.
id
,
ml_class
)
def
create_entity
(
self
,
element
,
name
,
type
,
corpus
,
metas
=
None
,
validated
=
None
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker.py
+
51
−
0
View file @
47ced4f6
...
...
@@ -991,6 +991,57 @@ def test_create_classification(responses, mock_elements_worker):
"
high_confidence
"
:
True
,
}
# Classification has been created and reported
assert
mock_elements_worker
.
report
.
report_data
[
"
elements
"
][
elt
.
id
][
"
classifications
"
]
==
{
"
a_class
"
:
1
}
def
test_create_classification_duplicate
(
responses
,
mock_elements_worker
):
mock_elements_worker
.
classes
=
{
"
11111111-1111-1111-1111-111111111111
"
:
{
"
a_class
"
:
"
0000
"
}
}
elt
=
Element
(
{
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
,
"
corpus
"
:
{
"
id
"
:
"
11111111-1111-1111-1111-111111111111
"
},
}
)
responses
.
add
(
responses
.
POST
,
"
http://testserver/api/v1/classifications/
"
,
status
=
400
,
json
=
{
"
non_field_errors
"
:
[
"
The fields element, worker_version, ml_class must make a unique set.
"
]
},
)
mock_elements_worker
.
create_classification
(
element
=
elt
,
ml_class
=
"
a_class
"
,
confidence
=
0.42
,
high_confidence
=
True
,
)
assert
len
(
responses
.
calls
)
==
2
assert
[
call
.
request
.
url
for
call
in
responses
.
calls
]
==
[
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
"
http://testserver/api/v1/classifications/
"
,
]
assert
json
.
loads
(
responses
.
calls
[
1
].
request
.
body
)
==
{
"
element
"
:
"
12341234-1234-1234-1234-123412341234
"
,
"
ml_class
"
:
"
0000
"
,
"
worker_version
"
:
"
12341234-1234-1234-1234-123412341234
"
,
"
confidence
"
:
0.42
,
"
high_confidence
"
:
True
,
}
# Classification has NOT been created
assert
mock_elements_worker
.
report
.
report_data
[
"
elements
"
]
==
{}
def
test_create_entity_wrong_element
(
mock_elements_worker
):
with
pytest
.
raises
(
AssertionError
)
as
e
:
...
...
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