Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
b9c09806
Commit
b9c09806
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix execute_before
parent
1a1d9ac2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/coding/decorators/arguments.py
+21
-10
21 additions, 10 deletions
satella/coding/decorators/arguments.py
tests/test_coding/test_decorators.py
+4
-4
4 additions, 4 deletions
tests/test_coding/test_decorators.py
with
26 additions
and
15 deletions
satella/__init__.py
+
1
−
1
View file @
b9c09806
__version__
=
'
2.9.12_a
2
'
__version__
=
'
2.9.12_a
3
'
This diff is collapsed.
Click to expand it.
satella/coding/decorators/arguments.py
+
21
−
10
View file @
b9c09806
...
...
@@ -28,23 +28,34 @@ def execute_before(callable_: tp.Callable[[], None]):
>>>
...
>>>
nothing
()
As well as the following
:
You can even specify custom parameters for the callable
:
>>>
do_things
(
execute
=
True
)
to simply execute the callable.
>>>
@execute_before
>>>
def
i_am_2
(
two
):
>>>
assert
two
==
2
>>>
@i_am_2
(
2
)
>>>
def
run_me
():
>>>
pass
"""
def
outer
(
fun
=
None
,
execute
:
bool
=
False
):
if
execute
:
return
callable_
()
else
:
def
outer
(
*
args
,
**
kwargs
):
if
len
(
args
)
==
1
and
not
kwargs
and
callable
(
args
[
0
])
:
fun
=
args
[
0
]
@wraps
(
fun
)
def
inner
(
*
args
,
**
kwargs
):
def
inner
(
*
my_
args
,
**
my_
kwargs
):
callable_
()
return
fun
(
*
args
,
**
kwargs
)
return
fun
(
*
my_
args
,
**
my_
kwargs
)
return
inner
else
:
def
inner
(
func
):
@wraps
(
func
)
def
inner2
(
*
my_args
,
**
my_kwargs
):
callable_
(
*
args
,
**
kwargs
)
return
func
(
*
my_args
,
**
my_kwargs
)
return
inner2
return
inner
return
outer
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_decorators.py
+
4
−
4
View file @
b9c09806
...
...
@@ -18,17 +18,17 @@ class TestDecorators(unittest.TestCase):
a
=
0
@execute_before
def
increase_a
():
def
increase_a
(
factor
=
1
):
nonlocal
a
a
+=
1
a
+=
factor
@increase_a
@increase_a
(
factor
=
2
)
def
launch_me
():
nonlocal
a
a
+=
1
launch_me
()
self
.
assertEqual
(
a
,
2
)
self
.
assertEqual
(
a
,
3
)
def
test_precondition_none
(
self
):
@precondition
(
short_none
(
'
x == 2
'
))
...
...
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