Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
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
FSL
fslpy
Commits
24a0ecb0
Commit
24a0ecb0
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test deprecated module
parent
7df42bed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_deprecated.py
+61
-0
61 additions, 0 deletions
tests/test_deprecated.py
with
61 additions
and
0 deletions
tests/test_deprecated.py
0 → 100644
+
61
−
0
View file @
24a0ecb0
#!/usr/bin/env python
import
warnings
import
pytest
import
fsl.utils.deprecated
as
deprecated
# the line number of the warning is hard coded in
# the unit tests below. Don't change the line number!
def
emit_warning
():
deprecated
.
warn
(
'
blag
'
,
vin
=
'
1.0.0
'
,
rin
=
'
2.0.0
'
,
msg
=
'
yo
'
)
WARNING_LINE_NUMBER
=
13
@deprecated.deprecated
(
vin
=
'
1.0.0
'
,
rin
=
'
2.0.0
'
,
msg
=
'
yo
'
)
def
depfunc
():
pass
def
call_dep_func
():
depfunc
()
DEPRECATED_LINE_NUMBER
=
23
def
_check_warning
(
w
,
name
,
lineno
):
assert
issubclass
(
w
.
category
,
DeprecationWarning
)
assert
'
{} is deprecated
'
.
format
(
name
)
in
str
(
w
.
message
)
assert
'
test_deprecated.py
'
in
str
(
w
.
filename
)
assert
w
.
lineno
==
lineno
def
test_warn
():
deprecated
.
resetWarningCache
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'
always
'
)
emit_warning
()
assert
len
(
w
)
==
1
_check_warning
(
w
[
0
],
'
blag
'
,
WARNING_LINE_NUMBER
)
# warning should only be emitted once
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'
always
'
)
emit_warning
()
assert
len
(
w
)
==
0
def
test_deprecated
():
deprecated
.
resetWarningCache
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'
always
'
)
call_dep_func
()
assert
len
(
w
)
==
1
_check_warning
(
w
[
0
],
'
depfunc
'
,
DEPRECATED_LINE_NUMBER
)
# warning should only be emitted once
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'
always
'
)
call_dep_func
()
assert
len
(
w
)
==
0
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