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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pipelines
Commits
6852ad45
Commit
6852ad45
authored
2 years ago
by
Yannick DAYER
Browse files
Options
Downloads
Patches
Plain Diff
[tests] Use pytest.raises and fix typos.
parent
67577e06
No related branches found
No related tags found
1 merge request
!98
DelayedSample tweak
Pipeline
#63241
passed
2 years ago
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pipelines/tests/test_samples.py
+9
-12
9 additions, 12 deletions
bob/pipelines/tests/test_samples.py
with
9 additions
and
12 deletions
bob/pipelines/tests/test_samples.py
+
9
−
12
View file @
6852ad45
...
...
@@ -5,6 +5,7 @@ import pickle
import
tempfile
import
numpy
as
np
import
pytest
from
bob.pipelines
import
(
DelayedSample
,
...
...
@@ -124,15 +125,15 @@ def test_delayed_samples():
delayed_sample
.
annot
=
"
changed
"
assert
delayed_sample
.
annot
==
"
changed
"
#
t
est DelayedSample.from_s
m
aple
#
T
est DelayedSample.from_sa
m
ple
#
c
heck if a non-delayed sample is correctly converted to a delayed sample
#
C
heck if a non-delayed sample is correctly converted to a delayed sample
non_delayed_sample
=
Sample
(
1
)
delayed_sample
=
DelayedSample
.
from_sample
(
non_delayed_sample
,
annot
=
"
test
"
)
assert
delayed_sample
.
data
==
1
assert
delayed_sample
.
annot
==
"
test
"
#
c
heck if converting a delayed sample will not load the data and delayed attributes
#
C
heck if converting a delayed sample will not load the data and delayed attributes
raise_error
=
True
def
never_load
():
...
...
@@ -144,32 +145,28 @@ def test_delayed_samples():
delayed_sample
=
DelayedSample
(
never_load
,
delayed_attributes
=
dict
(
annot
=
never_load
)
)
#
s
hould not raise an error when creating the delayed sample
#
S
hould not raise an error when creating the delayed sample
child_sample
=
DelayedSample
.
from_sample
(
delayed_sample
)
raise_error
=
False
assert
child_sample
.
data
==
0
assert
child_sample
.
annot
==
0
# If attribute is in kwargs and delayed_sample, it should raise exception
has_throw
=
False
try
:
# If attribute is in kwargs and delayed_sample, it should raise an exception
with
pytest
.
raises
(
ValueError
):
DelayedSample
(
load_data
,
delayed_attributes
=
{
"
annotations
"
:
load_annot
},
annotations
=
"
some_other_annotations
"
,
)
except
ValueError
:
has_throw
=
True
assert
has_throw
,
"
Duplicated attributes not detected
"
# kwargs should take precedence over
r
parent's delayed_attributes
# kwargs should take precedence over
the
parent's delayed_attributes
parent
=
DelayedSample
(
load_data
,
delayed_attributes
=
{
"
annotation
"
:
load_annot
},
non_delay_attribute
=
4
,
)
# annotation=100
takes over
parent.annotation
# annotation=100
overwrites
parent.annotation
child
=
DelayedSample
(
lambda
:
12
,
parent
=
parent
,
annotation
=
100
)
assert
child
.
data
==
12
...
...
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