Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
force-bdss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Adham Hashibon
force-bdss
Commits
a95aa5e1
Commit
a95aa5e1
authored
6 years ago
by
Stefano Borini
Browse files
Options
Downloads
Patches
Plain Diff
Added stricter controls over the returned values by the datasource
parent
1acbe751
No related branches found
No related tags found
1 merge request
!155
Added stricter controls over the returned values by the datasource.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
force_bdss/core_evaluation_driver.py
+29
-0
29 additions, 0 deletions
force_bdss/core_evaluation_driver.py
force_bdss/tests/test_core_evaluation_driver.py
+34
-0
34 additions, 0 deletions
force_bdss/tests/test_core_evaluation_driver.py
with
63 additions
and
0 deletions
force_bdss/core_evaluation_driver.py
+
29
−
0
View file @
a95aa5e1
...
@@ -3,6 +3,7 @@ import logging
...
@@ -3,6 +3,7 @@ import logging
from
traits.api
import
on_trait_change
from
traits.api
import
on_trait_change
from
force_bdss.core.data_value
import
DataValue
from
force_bdss.ids
import
InternalPluginID
from
force_bdss.ids
import
InternalPluginID
from
.base_core_driver
import
BaseCoreDriver
from
.base_core_driver
import
BaseCoreDriver
...
@@ -142,6 +143,17 @@ def _compute_layer_results(environment_data_values,
...
@@ -142,6 +143,17 @@ def _compute_layer_results(environment_data_values,
"
Run method raised exception.
"
)
"
Run method raised exception.
"
)
raise
raise
if
not
isinstance
(
res
,
list
):
error_txt
=
(
"
The run method of data source {} must return a list.
"
"
It returned instead {}. Fix the run() method to return
"
"
the appropriate entity.
"
.
format
(
factory
.
name
,
type
(
res
)
))
log
.
error
(
error_txt
)
raise
RuntimeError
(
error_txt
)
if
len
(
res
)
!=
len
(
out_slots
):
if
len
(
res
)
!=
len
(
out_slots
):
error_txt
=
(
error_txt
=
(
"
The number of data values ({} values) returned
"
"
The number of data values ({} values) returned
"
...
@@ -169,6 +181,23 @@ def _compute_layer_results(environment_data_values,
...
@@ -169,6 +181,23 @@ def _compute_layer_results(environment_data_values,
log
.
error
(
error_txt
)
log
.
error
(
error_txt
)
raise
RuntimeError
(
error_txt
)
raise
RuntimeError
(
error_txt
)
for
idx
,
dv
in
enumerate
(
res
):
if
not
isinstance
(
dv
,
DataValue
):
error_txt
=
(
"
The result list returned by DataSource {} contains
"
"
an entry that is not a DataValue. An entry of type
"
"
{} was instead found in position {}.
"
"
Fix the DataSource.run() method
"
"
to return the appropriate entity.
"
.
format
(
factory
.
name
,
type
(
dv
),
idx
)
)
log
.
error
(
error_txt
)
raise
RuntimeError
(
error_txt
)
# At this point, the returned data values are unnamed.
# At this point, the returned data values are unnamed.
# Add the names as specified by the user.
# Add the names as specified by the user.
for
dv
,
output_slot_info
in
zip
(
res
,
model
.
output_slot_info
):
for
dv
,
output_slot_info
in
zip
(
res
,
model
.
output_slot_info
):
...
...
This diff is collapsed.
Click to expand it.
force_bdss/tests/test_core_evaluation_driver.py
+
34
−
0
View file @
a95aa5e1
...
@@ -77,6 +77,40 @@ class TestCoreEvaluationDriver(unittest.TestCase):
...
@@ -77,6 +77,40 @@ class TestCoreEvaluationDriver(unittest.TestCase):
"
the number of output slots
"
):
"
the number of output slots
"
):
driver
.
application_started
()
driver
.
application_started
()
def
test_error_for_incorrect_return_type
(
self
):
def
run
(
self
,
*
args
,
**
kwargs
):
return
"
hello
"
ds_factory
=
self
.
registry
.
data_source_factories
[
0
]
ds_factory
.
run_function
=
run
driver
=
CoreEvaluationDriver
(
application
=
self
.
mock_application
)
with
testfixtures
.
LogCapture
():
with
six
.
assertRaisesRegex
(
self
,
RuntimeError
,
"
The run method of data source test_data_source must
"
"
return a list. It returned instead <type
'
str
'
>. Fix
"
"
the run\(\) method to return the appropriate entity.
"
):
driver
.
application_started
()
def
test_error_for_incorrect_data_value_entries
(
self
):
def
run
(
self
,
*
args
,
**
kwargs
):
return
[
"
hello
"
]
ds_factory
=
self
.
registry
.
data_source_factories
[
0
]
ds_factory
.
run_function
=
run
driver
=
CoreEvaluationDriver
(
application
=
self
.
mock_application
)
with
testfixtures
.
LogCapture
():
with
six
.
assertRaisesRegex
(
self
,
RuntimeError
,
"
The result list returned by DataSource test_data_source
"
"
contains an entry that is not a DataValue.
"
"
An entry of type <type
'
str
'
> was instead found
"
"
in position 0.
"
"
Fix the DataSource.run\(\) method to
"
"
return the appropriate entity.
"
):
driver
.
application_started
()
def
test_error_for_missing_ds_output_names
(
self
):
def
test_error_for_missing_ds_output_names
(
self
):
def
run
(
self
,
*
args
,
**
kwargs
):
def
run
(
self
,
*
args
,
**
kwargs
):
...
...
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