Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pipelines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
bob
bob.pipelines
Commits
360d4c13
Commit
360d4c13
authored
2 years ago
by
Yannick DAYER
Browse files
Options
Downloads
Patches
Plain Diff
[tests] Adds tests for the param validity checkers
parent
1624d3e1
No related branches found
No related tags found
1 merge request
!105
[utils.py] changed return type in check_parameters_for_validity to ensure that a list is returned
Pipeline
#67548
passed
2 years ago
Stage: qa
Stage: test
Stage: doc
Stage: dist
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_utils.py
+113
-0
113 additions, 0 deletions
tests/test_utils.py
with
113 additions
and
0 deletions
tests/test_utils.py
+
113
−
0
View file @
360d4c13
import
random
import
numpy
as
np
import
pytest
from
sklearn.pipeline
import
make_pipeline
from
sklearn.preprocessing
import
FunctionTransformer
...
...
@@ -13,6 +14,8 @@ from bob.pipelines import (
Sample
,
SampleSet
,
SampleWrapper
,
check_parameter_for_validity
,
check_parameters_for_validity
,
flatten_samplesets
,
is_pipeline_wrapped
,
wrap
,
...
...
@@ -133,3 +136,113 @@ def test_break_sample_set():
assert
np
.
allclose
(
[
len
(
s
)
for
s
in
new_samplesets
],
np
.
ones
(
n_samples
*
n_samples
)
)
def
test_check_parameter_validity
():
valid_values
=
[
"
accept
"
,
"
true
"
]
desc_str
=
"
desc_str
"
# Valid parameter
param
=
"
true
"
retval
=
check_parameter_for_validity
(
param
,
"
desc_str
"
,
valid_values
)
assert
retval
==
param
# Default value
param
=
None
default
=
"
accept
"
retval
=
check_parameter_for_validity
(
param
,
desc_str
,
valid_values
,
default
)
assert
retval
==
default
# Invalid parameter
param
=
"
false
"
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameter_for_validity
(
param
,
desc_str
,
valid_values
)
assert
(
str
(
except_info
.
value
)
==
f
"
The given
{
desc_str
}
'
{
param
}
'
is not allowed. Please choose one of
{
valid_values
}
.
"
)
# Invalid default parameter
param
=
None
default
=
"
false
"
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameter_for_validity
(
param
,
desc_str
,
valid_values
,
default
)
assert
(
str
(
except_info
.
value
)
==
f
"
The given
{
desc_str
}
'
{
default
}
'
is not allowed. Please choose one of
{
valid_values
}
.
"
)
# Too many parameters
param
=
[
"
accept
"
,
"
accept
"
]
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameter_for_validity
(
param
,
desc_str
,
valid_values
)
assert
(
str
(
except_info
.
value
)
==
f
"
The
{
desc_str
}
has to be one of
{
valid_values
}
, it might not be more than one (
{
param
}
was given).
"
)
def
test_check_parameters_validity
():
valid_values
=
[
"
accept
"
,
"
true
"
]
desc_str
=
"
desc_str
"
# Valid single parameter
param
=
"
true
"
retval
=
check_parameters_for_validity
(
param
,
"
desc_str
"
,
valid_values
)
assert
type
(
retval
)
is
list
assert
retval
==
[
param
]
# Valid multi parameter
param
=
[
"
true
"
,
"
accept
"
]
retval
=
check_parameters_for_validity
(
param
,
"
desc_str
"
,
valid_values
)
assert
type
(
retval
)
is
list
assert
retval
==
param
# Tuple parameter
param
=
(
"
true
"
,
"
accept
"
)
retval
=
check_parameters_for_validity
(
param
,
"
desc_str
"
,
valid_values
)
assert
type
(
retval
)
is
list
assert
retval
==
list
(
param
)
# Default value
param
=
None
default
=
"
accept
"
retval
=
check_parameters_for_validity
(
param
,
desc_str
,
valid_values
,
default
)
assert
type
(
retval
)
is
list
assert
retval
==
[
default
]
# Invalid parameter
param
=
"
false
"
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameters_for_validity
(
param
,
desc_str
,
valid_values
)
assert
(
str
(
except_info
.
value
)
==
f
"
Invalid
{
desc_str
}
'
{
param
}
'
. Valid values are
{
valid_values
}
, or lists/tuples of those
"
)
# Invalid multi parameter
param
=
[
"
accept
"
,
"
false
"
]
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameters_for_validity
(
param
,
desc_str
,
valid_values
)
assert
(
str
(
except_info
.
value
)
==
f
"
Invalid
{
desc_str
}
'
{
param
[
1
]
}
'
. Valid values are
{
valid_values
}
, or lists/tuples of those
"
)
# Invalid default parameter
param
=
None
default
=
"
false
"
with
pytest
.
raises
(
ValueError
)
as
except_info
:
retval
=
check_parameters_for_validity
(
param
,
desc_str
,
valid_values
,
default
)
assert
(
str
(
except_info
.
value
)
==
f
"
Invalid
{
desc_str
}
'
{
default
}
'
. Valid values are
{
valid_values
}
, or lists/tuples of those
"
)
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