Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
cb78e6b2
Commit
cb78e6b2
authored
Mar 24, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qa: add a basic assertion in Patch to detect when patched code changes
parent
43fdd059
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
9 deletions
+19
-9
neo/tests/__init__.py
neo/tests/__init__.py
+19
-9
No files found.
neo/tests/__init__.py
View file @
cb78e6b2
...
...
@@ -409,10 +409,14 @@ class Patch(object):
Usage:
with Patch(someObject, attrToPatch=newValue) as patch:
with Patch(someObject,
[new,]
attrToPatch=newValue) as patch:
[... code that runs with patches ...]
[... code that runs without patch ...]
The 'new' positional parameter defaults to False and it must be equal to
not hasattr(someObject, 'attrToPatch')
It is an assertion to detect when a Patch is obsolete.
' as patch' is optional: 'patch.revert()' can be used to revert patches
in the middle of the 'with' clause.
...
...
@@ -424,7 +428,7 @@ class Patch(object):
In this case, patches are automatically reverted when 'patch' is deleted.
For patched callables, the new one receives the original value as first
argument.
argument
if 'new' is True
.
Alternative usage:
...
...
@@ -448,12 +452,18 @@ class Patch(object):
return
self
return
patch
def
__init__
(
self
,
patched
,
**
patch
):
def
__init__
(
self
,
patched
,
*
args
,
**
patch
):
new
,
=
args
or
(
0
,)
(
name
,
patch
),
=
patch
.
iteritems
()
self
.
_patched
=
patched
self
.
_name
=
name
try
:
wrapped
=
getattr
(
patched
,
name
)
except
AttributeError
:
assert
new
,
(
patched
,
name
)
else
:
assert
not
new
,
(
patched
,
name
)
if
callable
(
patch
):
wrapped
=
getattr
(
patched
,
name
,
None
)
func
=
patch
patch
=
lambda
*
args
,
**
kw
:
func
(
wrapped
,
*
args
,
**
kw
)
if
callable
(
wrapped
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment